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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,687,511,553 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | def check(i):
if i%2 == 0:
return "YES"
else:
return "NO"
i=int(input())
if i>3:
print(check(i))
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
def check(i):
if i%2 == 0:
return "YES"
else:
return "NO"
i=int(input())
if i>3:
print(check(i))
else:
print("NO")
``` | 3.954 |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array. | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82",
"output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0"
},
{
"input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46",
"output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0"
},
{
"input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38",
"output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0"
},
{
"input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37",
"output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37"
},
{
"input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61",
"output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61"
},
{
"input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66",
"output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0"
},
{
"input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82",
"output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0"
},
{
"input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22",
"output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20"
},
{
"input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41",
"output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0"
},
{
"input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935",
"output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0"
},
{
"input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952",
"output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961"
},
{
"input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0",
"output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673"
},
{
"input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0",
"output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182"
},
{
"input": "5\n-1 -2 -3 -4 0",
"output": "1 -1\n2 -4 -3\n2 0 -2"
},
{
"input": "3\n-101 101 0",
"output": "1 -101\n1 101\n1 0"
},
{
"input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000",
"output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000"
},
{
"input": "4\n0 -1 -2 -3",
"output": "1 -1\n2 -3 -2\n1 0"
}
] | 1,687,237,399 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | def divide_array(n, arr):
positive_nums = []
negative_nums = []
zero_nums = []
for num in arr:
if num < 0:
negative_nums.append(num)
elif num > 0:
positive_nums.append(num)
else:
zero_nums.append(num)
if len(negative_nums) % 2 == 0:
set1 = [negative_nums.pop()]
else:
set1 = [negative_nums.pop(0)]
print(len(set1), *set1)
print(len(positive_nums), *positive_nums)
print(len(negative_nums) + len(zero_nums), *(negative_nums + zero_nums))
n = int(input())
arr = list(map(int, input().split()))
divide_array(n, arr)
| Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array.
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
Output Specification:
In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
Demo Input:
['3\n-1 2 0\n', '4\n-1 -2 -3 0\n']
Demo Output:
['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n']
Note:
none | ```python
def divide_array(n, arr):
positive_nums = []
negative_nums = []
zero_nums = []
for num in arr:
if num < 0:
negative_nums.append(num)
elif num > 0:
positive_nums.append(num)
else:
zero_nums.append(num)
if len(negative_nums) % 2 == 0:
set1 = [negative_nums.pop()]
else:
set1 = [negative_nums.pop(0)]
print(len(set1), *set1)
print(len(positive_nums), *positive_nums)
print(len(negative_nums) + len(zero_nums), *(negative_nums + zero_nums))
n = int(input())
arr = list(map(int, input().split()))
divide_array(n, arr)
``` | 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,650,470,537 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 122 | 3,379,200 | N, S = int(input()), 0
for i in range(N * N):
S += int(input())
print("YES" if S == 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, S = int(input()), 0
for i in range(N * N):
S += int(input())
print("YES" if S == 0 else "NO")
``` | -1 |
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,627,046,196 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 6,758,400 | number1 = input()
number2 = input()
result = ""
for x in range(len(number1)):
if number1[x] == number2[x]:
result += "0"
else:
result += "1"
print(result) | 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
number1 = input()
number2 = input()
result = ""
for x in range(len(number1)):
if number1[x] == number2[x]:
result += "0"
else:
result += "1"
print(result)
``` | 3.968161 |
284 | B | Cows and Poker Game | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".
Find the number of cows that can currently show their hands without affecting any betting decisions. | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". | The first line should contain a single integer denoting the number of players that can currently show their hands. | [
"6\nAFFAAA\n",
"3\nAFI\n"
] | [
"4\n",
"1\n"
] | In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | 1,000 | [
{
"input": "6\nAFFAAA",
"output": "4"
},
{
"input": "3\nAFI",
"output": "1"
},
{
"input": "3\nFFF",
"output": "0"
},
{
"input": "3\nFIF",
"output": "1"
},
{
"input": "3\nAAA",
"output": "3"
},
{
"input": "3\nIII",
"output": "0"
},
{
"input": "3\nIIA",
"output": "0"
},
{
"input": "3\nAFF",
"output": "1"
},
{
"input": "5\nFAFFF",
"output": "1"
},
{
"input": "3\nIAA",
"output": "1"
},
{
"input": "3\nIIF",
"output": "0"
},
{
"input": "2\nFA",
"output": "1"
},
{
"input": "2\nFF",
"output": "0"
},
{
"input": "2\nIF",
"output": "1"
},
{
"input": "5\nAAAAI",
"output": "1"
},
{
"input": "5\nIIIIF",
"output": "0"
},
{
"input": "10\nAAAAAAAAAA",
"output": "10"
},
{
"input": "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "100"
},
{
"input": "5\nFAIAF",
"output": "1"
},
{
"input": "5\nAIAIF",
"output": "0"
},
{
"input": "5\nFAAII",
"output": "0"
},
{
"input": "5\nAIFFF",
"output": "1"
},
{
"input": "5\nAFAFA",
"output": "3"
},
{
"input": "2\nFA",
"output": "1"
},
{
"input": "8\nAFFFFIAF",
"output": "1"
},
{
"input": "8\nIAAIFFFI",
"output": "0"
},
{
"input": "5\nIIIII",
"output": "0"
}
] | 1,447,676,543 | 1,342 | Python 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | x = int(input())
s = input()
m = 0
k = 0
for i in range(x):
if s[i] != "F":
if not "I" in s[0:i] + s[i+2:]:
k = s.count('A')
if k > m:
m = k
k = 0
print(m)
| Title: Cows and Poker Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".
Find the number of cows that can currently show their hands without affecting any betting decisions.
Input Specification:
The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED".
Output Specification:
The first line should contain a single integer denoting the number of players that can currently show their hands.
Demo Input:
['6\nAFFAAA\n', '3\nAFI\n']
Demo Output:
['4\n', '1\n']
Note:
In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | ```python
x = int(input())
s = input()
m = 0
k = 0
for i in range(x):
if s[i] != "F":
if not "I" in s[0:i] + s[i+2:]:
k = s.count('A')
if k > m:
m = k
k = 0
print(m)
``` | 0 |
|
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally? | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters. | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "2 1\nc\na\na",
"output": "YES"
},
{
"input": "3 3\nab\nbc\ncd\ncd\ndf\nfg",
"output": "YES"
},
{
"input": "3 3\nc\na\nb\na\nd\ng",
"output": "YES"
},
{
"input": "1 1\naa\naa",
"output": "YES"
},
{
"input": "2 1\na\nb\na",
"output": "YES"
},
{
"input": "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny",
"output": "YES"
},
{
"input": "3 2\na\nb\nc\nd\ne",
"output": "YES"
}
] | 1,612,047,436 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 1,126,400 | pol, en = [int(x) for x in input().split()]
lp = []; le = []
for i in range(pol):
p = input()
lp.append(p)
for j in range(en):
e = input()
le.append(e)
polcount = 0; enemycount = 0
le.sort(); lp.sort()
res = []
while True:
count_pol = 0; count_enemy = 0; temppol = 0; tempenemy = 0
for k in lp:
if k in le and k not in res:
res.append(k)
polcount += 1
temppol = count_pol
count_pol += 1
break
for l in le:
if l in lp and l not in res:
res.append(l)
enemycount += 1
tempenemy = count_enemy
count_enemy += 1
break
if count_pol == temppol or count_enemy == tempenemy:
break
tt = 1
while(tt<(pol+en)+1):
if tt%2 != 0:
for zz in lp:
if zz not in res:
polcount+=1
res.append(zz)
break
else:
for kp in le:
if kp not in res:
enemycount += 1
res.append(kp)
break
tt += 1
if polcount>enemycount:
print("YES")
else:
print("NO")
| Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
Input Specification:
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
Output Specification:
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
Demo Input:
['5 1\npolandball\nis\na\ncool\ncharacter\nnope\n', '2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n', '1 2\na\na\nb\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | ```python
pol, en = [int(x) for x in input().split()]
lp = []; le = []
for i in range(pol):
p = input()
lp.append(p)
for j in range(en):
e = input()
le.append(e)
polcount = 0; enemycount = 0
le.sort(); lp.sort()
res = []
while True:
count_pol = 0; count_enemy = 0; temppol = 0; tempenemy = 0
for k in lp:
if k in le and k not in res:
res.append(k)
polcount += 1
temppol = count_pol
count_pol += 1
break
for l in le:
if l in lp and l not in res:
res.append(l)
enemycount += 1
tempenemy = count_enemy
count_enemy += 1
break
if count_pol == temppol or count_enemy == tempenemy:
break
tt = 1
while(tt<(pol+en)+1):
if tt%2 != 0:
for zz in lp:
if zz not in res:
polcount+=1
res.append(zz)
break
else:
for kp in le:
if kp not in res:
enemycount += 1
res.append(kp)
break
tt += 1
if polcount>enemycount:
print("YES")
else:
print("NO")
``` | 0 |
|
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch. | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integer — the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d",
"output": "3999999999999999994"
},
{
"input": "999999999999999997a",
"output": "3999999999999999988"
},
{
"input": "1c",
"output": "6"
},
{
"input": "1d",
"output": "3"
},
{
"input": "1e",
"output": "2"
},
{
"input": "1a",
"output": "4"
},
{
"input": "2a",
"output": "11"
},
{
"input": "2b",
"output": "12"
},
{
"input": "2e",
"output": "9"
},
{
"input": "2f",
"output": "8"
},
{
"input": "3a",
"output": "4"
},
{
"input": "3b",
"output": "5"
},
{
"input": "3c",
"output": "6"
},
{
"input": "3d",
"output": "3"
},
{
"input": "3e",
"output": "2"
},
{
"input": "3f",
"output": "1"
},
{
"input": "4b",
"output": "12"
},
{
"input": "4c",
"output": "13"
},
{
"input": "4d",
"output": "10"
},
{
"input": "4e",
"output": "9"
},
{
"input": "4f",
"output": "8"
},
{
"input": "999999997a",
"output": "3999999988"
},
{
"input": "999999997b",
"output": "3999999989"
},
{
"input": "999999997c",
"output": "3999999990"
},
{
"input": "999999997d",
"output": "3999999987"
},
{
"input": "999999997e",
"output": "3999999986"
},
{
"input": "999999997f",
"output": "3999999985"
},
{
"input": "999999998a",
"output": "3999999995"
},
{
"input": "999999998b",
"output": "3999999996"
},
{
"input": "999999998c",
"output": "3999999997"
},
{
"input": "999999998d",
"output": "3999999994"
},
{
"input": "999999998e",
"output": "3999999993"
},
{
"input": "999999998f",
"output": "3999999992"
},
{
"input": "999999999a",
"output": "3999999988"
},
{
"input": "999999999b",
"output": "3999999989"
},
{
"input": "999999999c",
"output": "3999999990"
},
{
"input": "999999999d",
"output": "3999999987"
},
{
"input": "999999999e",
"output": "3999999986"
},
{
"input": "999999999f",
"output": "3999999985"
},
{
"input": "1000000000a",
"output": "3999999995"
},
{
"input": "1000000000b",
"output": "3999999996"
},
{
"input": "1000000000c",
"output": "3999999997"
},
{
"input": "1000000000d",
"output": "3999999994"
},
{
"input": "1000000000e",
"output": "3999999993"
},
{
"input": "1000000000f",
"output": "3999999992"
},
{
"input": "100000b",
"output": "399996"
},
{
"input": "100000f",
"output": "399992"
},
{
"input": "100001d",
"output": "400003"
},
{
"input": "100001e",
"output": "400002"
},
{
"input": "100001f",
"output": "400001"
},
{
"input": "100002a",
"output": "400011"
},
{
"input": "100002b",
"output": "400012"
},
{
"input": "100002d",
"output": "400010"
},
{
"input": "1231273a",
"output": "4925092"
},
{
"input": "82784f",
"output": "331128"
},
{
"input": "88312c",
"output": "353245"
},
{
"input": "891237e",
"output": "3564946"
},
{
"input": "999999999999999997b",
"output": "3999999999999999989"
},
{
"input": "999999999999999997c",
"output": "3999999999999999990"
},
{
"input": "999999999999999997d",
"output": "3999999999999999987"
},
{
"input": "999999999999999997e",
"output": "3999999999999999986"
},
{
"input": "999999999999999997f",
"output": "3999999999999999985"
},
{
"input": "999999999999999998a",
"output": "3999999999999999995"
},
{
"input": "999999999999999998b",
"output": "3999999999999999996"
},
{
"input": "999999999999999998c",
"output": "3999999999999999997"
},
{
"input": "999999999999999998d",
"output": "3999999999999999994"
},
{
"input": "999999999999999998e",
"output": "3999999999999999993"
},
{
"input": "999999999999999998f",
"output": "3999999999999999992"
},
{
"input": "999999999999999999a",
"output": "3999999999999999988"
},
{
"input": "999999999999999999b",
"output": "3999999999999999989"
},
{
"input": "999999999999999999c",
"output": "3999999999999999990"
},
{
"input": "999999999999999999d",
"output": "3999999999999999987"
},
{
"input": "1000000000000000000a",
"output": "3999999999999999995"
},
{
"input": "1000000000000000000e",
"output": "3999999999999999993"
},
{
"input": "1000000000000000000f",
"output": "3999999999999999992"
},
{
"input": "1000000000000000000c",
"output": "3999999999999999997"
},
{
"input": "97a",
"output": "388"
},
{
"input": "6f",
"output": "24"
},
{
"input": "7f",
"output": "17"
},
{
"input": "7e",
"output": "18"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "7a",
"output": "20"
},
{
"input": "8f",
"output": "24"
},
{
"input": "999999999999999992a",
"output": "3999999999999999963"
},
{
"input": "999999999999999992b",
"output": "3999999999999999964"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "999999999999999992d",
"output": "3999999999999999962"
},
{
"input": "999999999999999992e",
"output": "3999999999999999961"
},
{
"input": "999999999999999992f",
"output": "3999999999999999960"
},
{
"input": "999999999999999993a",
"output": "3999999999999999972"
},
{
"input": "999999999999999993b",
"output": "3999999999999999973"
},
{
"input": "999999999999999993c",
"output": "3999999999999999974"
},
{
"input": "999999999999999993d",
"output": "3999999999999999971"
},
{
"input": "999999999999999993e",
"output": "3999999999999999970"
},
{
"input": "999999999999999993f",
"output": "3999999999999999969"
},
{
"input": "999999999999999994a",
"output": "3999999999999999979"
},
{
"input": "999999999999999994b",
"output": "3999999999999999980"
},
{
"input": "999999999999999994c",
"output": "3999999999999999981"
},
{
"input": "999999999999999994d",
"output": "3999999999999999978"
},
{
"input": "999999999999999994e",
"output": "3999999999999999977"
},
{
"input": "999999999999999994f",
"output": "3999999999999999976"
},
{
"input": "999999999999999995a",
"output": "3999999999999999972"
},
{
"input": "999999999999999995b",
"output": "3999999999999999973"
},
{
"input": "999999999999999995c",
"output": "3999999999999999974"
},
{
"input": "999999999999999995d",
"output": "3999999999999999971"
},
{
"input": "999999999999999995e",
"output": "3999999999999999970"
},
{
"input": "999999999999999995f",
"output": "3999999999999999969"
},
{
"input": "10a",
"output": "43"
},
{
"input": "11f",
"output": "33"
},
{
"input": "681572647b",
"output": "2726290581"
},
{
"input": "23f",
"output": "81"
},
{
"input": "123a",
"output": "484"
},
{
"input": "999999888888777777a",
"output": "3999999555555111108"
}
] | 1,477,152,718 | 4,018 | Python 3 | RUNTIME_ERROR | PRETESTS | 6 | 61 | 0 | str = input()
sec = 0
count = 1
list = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
raw1 = 1
raw2 = 3
while True:
if raw1 == int(str[0]) or raw2 == int(str[0]):
sec += list[str[1]]
break
if count > 0:
raw1 += 1
raw2 += 1
sec += 7
count -= 1
else:
count = 1
raw1 += 3
raw2 += 3
sec += 9
print(sec) | Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch.
Input Specification:
The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
Output Specification:
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
Demo Input:
['1f\n', '2d\n', '4a\n', '5e\n']
Demo Output:
['1\n', '10\n', '11\n', '18\n']
Note:
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | ```python
str = input()
sec = 0
count = 1
list = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
raw1 = 1
raw2 = 3
while True:
if raw1 == int(str[0]) or raw2 == int(str[0]):
sec += list[str[1]]
break
if count > 0:
raw1 += 1
raw2 += 1
sec += 7
count -= 1
else:
count = 1
raw1 += 3
raw2 += 3
sec += 9
print(sec)
``` | -1 |
|
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10 2 1 1",
"output": "5"
},
{
"input": "1 1000 1 2",
"output": "1"
},
{
"input": "1 1000 3 2",
"output": "2"
},
{
"input": "10 3 1 2",
"output": "7"
},
{
"input": "995 1 2 1",
"output": "995"
},
{
"input": "556 2 16 15",
"output": "4170"
},
{
"input": "477 2 16 14",
"output": "3346"
},
{
"input": "101 110 1 100",
"output": "100"
},
{
"input": "9 3 3 10",
"output": "27"
},
{
"input": "100 8 10 1",
"output": "13"
},
{
"input": "6 4 1 3",
"output": "5"
},
{
"input": "8 5 2 8",
"output": "14"
},
{
"input": "1000 2 1 1000",
"output": "1000"
}
] | 1,691,504,934 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,m,a,b =map(int, input().split())
asum=n*a
msum= n // m
remain= n % m
bsum=msum* b
rsum=remain*a
t = min(asum,bsum+rsum)
print(t)
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides?
Input Specification:
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Output Specification:
Print a single integer — the minimum sum in rubles that Ann will need to spend.
Demo Input:
['6 2 1 2\n', '5 2 2 3\n']
Demo Output:
['6\n', '8\n']
Note:
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | ```python
n,m,a,b =map(int, input().split())
asum=n*a
msum= n // m
remain= n % m
bsum=msum* b
rsum=remain*a
t = min(asum,bsum+rsum)
print(t)
``` | 0 |
|
346 | A | Alice and Bob | PROGRAMMING | 1,600 | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers *x* and *y* from the set, such that the set doesn't contain their absolute difference |*x*<=-<=*y*|. Then this player adds integer |*x*<=-<=*y*| to the set (so, the size of the set increases by one).
If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 500 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
{
"input": "10\n98 63 42 56 14 77 70 35 84 21",
"output": "Bob"
},
{
"input": "2\n1 1000000000",
"output": "Bob"
},
{
"input": "2\n1000000000 999999999",
"output": "Bob"
},
{
"input": "3\n2 4 6",
"output": "Bob"
},
{
"input": "2\n4 6",
"output": "Alice"
},
{
"input": "2\n2 6",
"output": "Alice"
},
{
"input": "2\n6 2",
"output": "Alice"
},
{
"input": "10\n100000000 200000000 300000000 400000000 500000000 600000000 700000000 800000000 900000000 1000000000",
"output": "Bob"
},
{
"input": "2\n1 2",
"output": "Bob"
},
{
"input": "10\n1 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991",
"output": "Alice"
},
{
"input": "3\n6 14 21",
"output": "Bob"
},
{
"input": "3\n4 12 18",
"output": "Bob"
},
{
"input": "4\n2 3 15 30",
"output": "Bob"
},
{
"input": "2\n10 4",
"output": "Alice"
}
] | 1,595,338,591 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 218 | 6,656,000 | from math import gcd
n = int(input())
a = list(map(int, input().split()))
g = a[0]
max = a[0]
for i in a:
if i > max:
max = i
g = gcd(g, i)
ans = (max // g) - n
if ans % 2 == 0:
print("Bob")
else:
print("Alice") | Title: Alice and Bob
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers *x* and *y* from the set, such that the set doesn't contain their absolute difference |*x*<=-<=*y*|. Then this player adds integer |*x*<=-<=*y*| to the set (so, the size of the set increases by one).
If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set.
Output Specification:
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).
Demo Input:
['2\n2 3\n', '2\n5 3\n', '3\n5 6 7\n']
Demo Output:
['Alice\n', 'Alice\n', 'Bob\n']
Note:
Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | ```python
from math import gcd
n = int(input())
a = list(map(int, input().split()))
g = a[0]
max = a[0]
for i in a:
if i > max:
max = i
g = gcd(g, i)
ans = (max // g) - n
if ans % 2 == 0:
print("Bob")
else:
print("Alice")
``` | 3 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,695,093,448 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | n=int(input())
ans=0
while(n>0):
if(n>=5):
ans+=1
n-=5
elif(n>=4):
ans+=1
n-=4
elif(n>=3):
ans+=1
n-=3
elif(n>=2):
ans+=1
n-=2
else:
ans+=1
n-=1
print(ans)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
n=int(input())
ans=0
while(n>0):
if(n>=5):
ans+=1
n-=5
elif(n>=4):
ans+=1
n-=4
elif(n>=3):
ans+=1
n-=3
elif(n>=2):
ans+=1
n-=2
else:
ans+=1
n-=1
print(ans)
``` | 3 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,525,874,031 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 78 | 7,065,600 | x=[int(x) for x in input().split()]
y=list(set(x))
if len(y)==2:
print('Elephant')
elif len(y)==3:
print('Bear')
else:
print('Alien') | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
x=[int(x) for x in input().split()]
y=list(set(x))
if len(y)==2:
print('Elephant')
elif len(y)==3:
print('Bear')
else:
print('Alien')
``` | 0 |
|
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,690,907,754 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | for i in range(int(input())):
n = input()
if len(n) > 11:
print(n[0],len(n)-2, n[-1])
else:
print(n)
| 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
for i in range(int(input())):
n = input()
if len(n) > 11:
print(n[0],len(n)-2, n[-1])
else:
print(n)
``` | 0 |
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360",
"output": "14"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n131",
"output": "1"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "8"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
}
] | 1,656,515,773 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 452 | 307,200 | n=int(input())
box_no=n
box=input()
box=[int(i) for i in box.split()]
dic={}
for i in box:
if i not in dic:
dic[i]=box.count(i)
m=max(dic,key=dic.get)
print(dic[m])
| Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Output Specification:
Print the minimum possible number of visible boxes.
Demo Input:
['3\n1 2 3\n', '4\n4 2 4 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | ```python
n=int(input())
box_no=n
box=input()
box=[int(i) for i in box.split()]
dic={}
for i in box:
if i not in dic:
dic[i]=box.count(i)
m=max(dic,key=dic.get)
print(dic[m])
``` | 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,677,168,455 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | test_cases=int(input())
sumx=0
sumy=0
sumz=0
x=[]
y=[]
z=[]
for i in range(test_cases):
a,b,c=map(int,(input().split()))
x.append(a)
y.append(b)
z.append(c)
for i in range(test_cases):
sumx=sumx+x[i]
sumy=sumy+y[i]
sumz=sumz+z[i]
if((sumx==0)and(sumy==0)and(sumz==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
test_cases=int(input())
sumx=0
sumy=0
sumz=0
x=[]
y=[]
z=[]
for i in range(test_cases):
a,b,c=map(int,(input().split()))
x.append(a)
y.append(b)
z.append(c)
for i in range(test_cases):
sumx=sumx+x[i]
sumy=sumy+y[i]
sumz=sumz+z[i]
if((sumx==0)and(sumy==0)and(sumz==0)):
print("YES")
else:
print("NO")
``` | 3.977 |
895 | B | XK Segments | PROGRAMMING | 1,700 | [
"binary search",
"math",
"sortings",
"two pointers"
] | null | null | While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*.
In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1). | The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print one integer — the answer to the problem. | [
"4 2 1\n1 3 5 7\n",
"4 2 0\n5 3 1 7\n",
"5 3 1\n3 3 3 3 3\n"
] | [
"3\n",
"4\n",
"25\n"
] | In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25. | 1,000 | [
{
"input": "4 2 1\n1 3 5 7",
"output": "3"
},
{
"input": "4 2 0\n5 3 1 7",
"output": "4"
},
{
"input": "5 3 1\n3 3 3 3 3",
"output": "25"
},
{
"input": "5 3 4\n24 13 1 24 24",
"output": "4"
},
{
"input": "4 2 2\n1 3 5 7",
"output": "2"
},
{
"input": "5 1 0\n10 12 14 20 30",
"output": "0"
},
{
"input": "7 3 1\n3 3 6 9 12 15 18",
"output": "9"
},
{
"input": "2 5 0\n3 4",
"output": "3"
},
{
"input": "3 5 0\n4 4 4",
"output": "9"
},
{
"input": "3 6 0\n3 4 5",
"output": "6"
},
{
"input": "10 2 1\n2 2 2 2 2 2 2 1 2 1",
"output": "80"
},
{
"input": "100 2 1\n1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 1 2 2 2 1 1 1 2 2 1 1 2 2 1 1 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 2 1 1 2 2 2 1",
"output": "5200"
},
{
"input": "1 13 1\n13",
"output": "1"
},
{
"input": "2 1 1000000000\n1 1000000000",
"output": "1"
},
{
"input": "2 1000000000 1\n1 1000000000",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "1"
},
{
"input": "5 1000000000 1\n1000000000 1 1 1 1",
"output": "5"
},
{
"input": "2 1000 1000000\n1 1000000000",
"output": "1"
},
{
"input": "6 2 10\n1 1 1 20 20 20",
"output": "9"
},
{
"input": "1 1000000000 1\n1000000000",
"output": "1"
},
{
"input": "4 65536 65536\n1 2 3 4",
"output": "0"
},
{
"input": "1 600000000 1\n500000000",
"output": "0"
},
{
"input": "5 3 2\n2 3 4 5 8",
"output": "2"
}
] | 1,511,715,522 | 3,222 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 5,529,600 | n, x, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a.sort()
def upper_bound( key):
left = -1
right = len(a)
while right > left + 1:
middle = (left + right ) // 2
if a[middle] > key + x * k:
right = middle
else:
left = middle
return right
def lower_bound(key):
left = -1
right = len(a)
while right > left + 1:
middle = (left + right ) // 2
if a[middle] >= key + x * k or (x * k != 0 and a[middle] % (x * k) == 0):
right = middle
else:
left = middle
return right
for i in range(len(a)):
#print(i, lower_bound(a[i]), upper_bound(a[i]))
ans += upper_bound(a[i]) - lower_bound(a[i])
#print(ans)
print(ans)
| Title: XK Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*.
In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1).
Input Specification:
The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Output Specification:
Print one integer — the answer to the problem.
Demo Input:
['4 2 1\n1 3 5 7\n', '4 2 0\n5 3 1 7\n', '5 3 1\n3 3 3 3 3\n']
Demo Output:
['3\n', '4\n', '25\n']
Note:
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25. | ```python
n, x, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a.sort()
def upper_bound( key):
left = -1
right = len(a)
while right > left + 1:
middle = (left + right ) // 2
if a[middle] > key + x * k:
right = middle
else:
left = middle
return right
def lower_bound(key):
left = -1
right = len(a)
while right > left + 1:
middle = (left + right ) // 2
if a[middle] >= key + x * k or (x * k != 0 and a[middle] % (x * k) == 0):
right = middle
else:
left = middle
return right
for i in range(len(a)):
#print(i, lower_bound(a[i]), upper_bound(a[i]))
ans += upper_bound(a[i]) - lower_bound(a[i])
#print(ans)
print(ans)
``` | 0 |
|
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 1,594,999,087 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 6,656,000 | n = int(input())
l = [0] * 101
s = [int(i) for i in input().split()]
for i in s:
l[i] += 1
print(max(l)) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Output Specification:
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Demo Input:
['6\n1 2 4 3 3 2\n', '1\n100\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
n = int(input())
l = [0] * 101
s = [int(i) for i in input().split()]
for i in s:
l[i] += 1
print(max(l))
``` | 3 |
|
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number. | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"output": "130"
},
{
"input": "900000000 16",
"output": "1"
},
{
"input": "909090909 50",
"output": "3"
},
{
"input": "1001 2",
"output": "100"
},
{
"input": "5 2",
"output": "3"
},
{
"input": "2 1",
"output": "1"
}
] | 1,695,043,071 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input("enter number :"))
k = int(input("enter number of subtractions :"))
while k>0:
if n%10 ==0:
n = n/10
k = k-1
else:
n = n-1
k = k-1
print(int(n))
| Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number.
Input Specification:
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Output Specification:
Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number.
Demo Input:
['512 4\n', '1000000000 9\n']
Demo Output:
['50\n', '1\n']
Note:
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | ```python
n = int(input("enter number :"))
k = int(input("enter number of subtractions :"))
while k>0:
if n%10 ==0:
n = n/10
k = k-1
else:
n = n-1
k = k-1
print(int(n))
``` | -1 |
|
713 | C | Sonya and Problem Wihtout a Legend | PROGRAMMING | 2,300 | [
"dp",
"sortings"
] | null | null | Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=3000) — the length of the array.
Next line contains *n* integer *a**i* (1<=≤<=*a**i*<=≤<=109). | Print the minimum number of operation required to make the array strictly increasing. | [
"7\n2 1 5 11 5 9 11\n",
"5\n5 4 3 2 1\n"
] | [
"9\n",
"12\n"
] | In the first sample, the array is going to look as follows:
2 3 5 6 7 9 11
|2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9
And for the second sample:
1 2 3 4 5
|5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12 | 2,000 | [
{
"input": "7\n2 1 5 11 5 9 11",
"output": "9"
},
{
"input": "5\n5 4 3 2 1",
"output": "12"
},
{
"input": "2\n1 1000",
"output": "0"
},
{
"input": "2\n1000 1",
"output": "1000"
},
{
"input": "5\n100 80 60 70 90",
"output": "54"
},
{
"input": "10\n10 16 17 11 1213 1216 1216 1209 3061 3062",
"output": "16"
},
{
"input": "20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158",
"output": "43"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "5\n1 1 1 2 3",
"output": "3"
},
{
"input": "1\n1000",
"output": "0"
},
{
"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",
"output": "12423"
},
{
"input": "75\n392 593 98 533 515 448 220 310 386 79 539 294 208 828 75 534 875 493 94 205 656 105 546 493 60 188 222 108 788 504 809 621 934 455 307 212 630 298 938 62 850 421 839 134 950 256 934 817 209 559 866 67 990 835 534 672 468 768 757 516 959 893 275 315 692 927 321 554 801 805 885 12 67 245 495",
"output": "17691"
},
{
"input": "10\n26 723 970 13 422 968 875 329 234 983",
"output": "2546"
},
{
"input": "20\n245 891 363 6 193 704 420 447 237 947 664 894 512 194 513 616 671 623 686 378",
"output": "3208"
},
{
"input": "5\n850 840 521 42 169",
"output": "1485"
}
] | 1,648,785,854 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 311 | 77,824,000 | import sys
inp = sys.stdin.readline
# Codeforces 713 C
n = int(inp())
a = [int(x) for x in inp().split()]
a = [x - i for i, x in enumerate(a)]
s = sorted(a)
M = [[0 for _ in a] for _ in a]
for i in range(n):
for j in range(n):
if i == 0:
M[i][j] = abs(a[0] - s[j])
elif j == 0:
M[i][j] = M[i-1][0] + abs(a[i] - s[0])
else:
M[i][j] = min(M[i-1][j], M[i][j-1] - abs(a[i] - s[j-1]))+ abs(a[i] - s[j])
print(min(M[-1]))
| Title: Sonya and Problem Wihtout a Legend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=3000) — the length of the array.
Next line contains *n* integer *a**i* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the minimum number of operation required to make the array strictly increasing.
Demo Input:
['7\n2 1 5 11 5 9 11\n', '5\n5 4 3 2 1\n']
Demo Output:
['9\n', '12\n']
Note:
In the first sample, the array is going to look as follows:
2 3 5 6 7 9 11
|2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9
And for the second sample:
1 2 3 4 5
|5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12 | ```python
import sys
inp = sys.stdin.readline
# Codeforces 713 C
n = int(inp())
a = [int(x) for x in inp().split()]
a = [x - i for i, x in enumerate(a)]
s = sorted(a)
M = [[0 for _ in a] for _ in a]
for i in range(n):
for j in range(n):
if i == 0:
M[i][j] = abs(a[0] - s[j])
elif j == 0:
M[i][j] = M[i-1][0] + abs(a[i] - s[0])
else:
M[i][j] = min(M[i-1][j], M[i][j-1] - abs(a[i] - s[j-1]))+ abs(a[i] - s[j])
print(min(M[-1]))
``` | 3 |
|
538 | C | Tourist's Notes | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"greedy",
"implementation",
"math"
] | null | null | A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all *i*'s from 1 to *n*<=-<=1 the inequality |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1 holds.
At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1. | The first line contains two space-separated numbers, *n* and *m* (1<=≤<=*n*<=≤<=108, 1<=≤<=*m*<=≤<=105) — the number of days of the hike and the number of notes left in the journal.
Next *m* lines contain two space-separated integers *d**i* and *h**d**i* (1<=≤<=*d**i*<=≤<=*n*, 0<=≤<=*h**d**i*<=≤<=108) — the number of the day when the *i*-th note was made and height on the *d**i*-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all *i* from 1 to *m*<=-<=1 the following condition holds: *d**i*<=<<=*d**i*<=+<=1. | If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes). | [
"8 2\n2 0\n7 0\n",
"8 3\n2 0\n7 0\n8 3\n"
] | [
"2\n",
"IMPOSSIBLE\n"
] | For the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).
In the second sample the inequality between *h*<sub class="lower-index">7</sub> and *h*<sub class="lower-index">8</sub> does not hold, thus the information is inconsistent. | 1,500 | [
{
"input": "8 2\n2 0\n7 0",
"output": "2"
},
{
"input": "8 3\n2 0\n7 0\n8 3",
"output": "IMPOSSIBLE"
},
{
"input": "10 10\n1 0\n2 0\n3 0\n4 0\n5 1\n6 2\n7 3\n8 2\n9 3\n10 4",
"output": "4"
},
{
"input": "50 10\n1 42\n7 36\n16 40\n21 40\n26 39\n30 41\n32 41\n36 40\n44 37\n50 41",
"output": "42"
},
{
"input": "50 10\n5 17\n7 15\n10 4\n15 11\n18 13\n21 15\n31 5\n34 13\n40 15\n49 16",
"output": "IMPOSSIBLE"
},
{
"input": "100 50\n1 53\n3 51\n4 50\n6 48\n9 45\n12 48\n14 46\n16 48\n17 47\n19 49\n20 48\n22 46\n23 45\n24 44\n26 46\n27 47\n29 49\n32 52\n33 53\n35 55\n37 53\n40 50\n41 51\n43 53\n47 57\n50 60\n51 59\n52 60\n57 65\n59 63\n60 62\n61 61\n62 60\n64 62\n68 66\n70 64\n71 63\n73 65\n77 69\n79 67\n81 65\n83 63\n86 66\n88 68\n89 69\n91 67\n94 64\n95 63\n98 60\n100 58",
"output": "69"
},
{
"input": "10 1\n4 16160172",
"output": "16160178"
},
{
"input": "10000 2\n3270 897970\n8270 899508",
"output": "901239"
},
{
"input": "100000000 1\n9783835 100000000",
"output": "190216165"
},
{
"input": "100000000 1\n1 100000000",
"output": "199999999"
},
{
"input": "100000000 1\n100000000 100000000",
"output": "199999999"
},
{
"input": "100000000 2\n1 100000000\n100000000 100000000",
"output": "149999999"
},
{
"input": "100000000 2\n50000000 100000000\n50000001 100000000",
"output": "149999999"
},
{
"input": "99999999 20\n3 100000000\n14 100000000\n22 100000000\n24 100000000\n31 100000000\n41 100000000\n46 100000000\n84 100000000\n94 100000000\n98 100000000\n99999912 100000000\n99999915 100000000\n99999916 100000000\n99999923 100000000\n99999935 100000000\n99999937 100000000\n99999954 100000000\n99999955 100000000\n99999979 100000000\n99999982 100000000",
"output": "149999907"
},
{
"input": "8 3\n2 0\n7 3\n8 0",
"output": "IMPOSSIBLE"
},
{
"input": "10 1\n5 5",
"output": "10"
},
{
"input": "100 2\n1 100\n2 1",
"output": "IMPOSSIBLE"
},
{
"input": "1 1\n1 100",
"output": "100"
},
{
"input": "1 1\n1 10",
"output": "10"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "9 2\n1 8\n9 11",
"output": "13"
},
{
"input": "9 2\n1 1\n9 3",
"output": "6"
},
{
"input": "10000000 1\n10000000 0",
"output": "9999999"
},
{
"input": "3 2\n1 0\n3 0",
"output": "1"
},
{
"input": "100000000 2\n1 2\n2 1",
"output": "99999999"
},
{
"input": "1 1\n1 5",
"output": "5"
}
] | 1,574,781,150 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 920 | 9,420,800 | n, m = map(int, input().split())
res, pd, ph = 0, 0, 0
for i in range(m):
d, h = map(int, input().split())
if i == 0:
res = h + (d - 1)
else:
delta_d = d - pd
delta_h = abs(h - ph)
if delta_h > delta_d:
print("IMPOSSIBLE")
exit()
res = max(res, max(h, ph) + (delta_d - delta_h) // 2)
if i == m - 1:
res = max(res, h + n - d)
pd, ph = d, h
print(res)
| Title: Tourist's Notes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all *i*'s from 1 to *n*<=-<=1 the inequality |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1 holds.
At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1.
Input Specification:
The first line contains two space-separated numbers, *n* and *m* (1<=≤<=*n*<=≤<=108, 1<=≤<=*m*<=≤<=105) — the number of days of the hike and the number of notes left in the journal.
Next *m* lines contain two space-separated integers *d**i* and *h**d**i* (1<=≤<=*d**i*<=≤<=*n*, 0<=≤<=*h**d**i*<=≤<=108) — the number of the day when the *i*-th note was made and height on the *d**i*-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all *i* from 1 to *m*<=-<=1 the following condition holds: *d**i*<=<<=*d**i*<=+<=1.
Output Specification:
If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes).
Demo Input:
['8 2\n2 0\n7 0\n', '8 3\n2 0\n7 0\n8 3\n']
Demo Output:
['2\n', 'IMPOSSIBLE\n']
Note:
For the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).
In the second sample the inequality between *h*<sub class="lower-index">7</sub> and *h*<sub class="lower-index">8</sub> does not hold, thus the information is inconsistent. | ```python
n, m = map(int, input().split())
res, pd, ph = 0, 0, 0
for i in range(m):
d, h = map(int, input().split())
if i == 0:
res = h + (d - 1)
else:
delta_d = d - pd
delta_h = abs(h - ph)
if delta_h > delta_d:
print("IMPOSSIBLE")
exit()
res = max(res, max(h, ph) + (delta_d - delta_h) // 2)
if i == m - 1:
res = max(res, h + n - d)
pd, ph = d, h
print(res)
``` | 3 |
|
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *j*<=≥<=*i*<=-<=*L**i*.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer — the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0",
"output": "4"
},
{
"input": "6\n3 1 1 0 3 3",
"output": "1"
},
{
"input": "8\n0 0 0 1 0 0 1 2",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "2\n1 3",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "11\n1 0 0 1 1 3 2 0 0 2 3",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
}
] | 1,510,979,526 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 77,926,400 | # http://codeforces.com/problemset/problem/892/B
n = int(input())
l = [int(i) for i in input().split(' ')]
dead = []
for i in range(n-1, -1, -1):
for j in range(i-1, -1, -1):
if j in dead:
continue
if j + l[i] >= i:
dead.append(j)
print(n - len(set(dead))) | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *j*<=≥<=*i*<=-<=*L**i*.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
Output Specification:
Print one integer — the total number of alive people after the bell rings.
Demo Input:
['4\n0 1 0 10\n', '2\n0 0\n', '10\n1 1 3 0 0 0 2 1 0 3\n']
Demo Output:
['1\n', '2\n', '3\n']
Note:
In first sample the last person kills everyone in front of him. | ```python
# http://codeforces.com/problemset/problem/892/B
n = int(input())
l = [int(i) for i in input().split(' ')]
dead = []
for i in range(n-1, -1, -1):
for j in range(i-1, -1, -1):
if j in dead:
continue
if j + l[i] >= i:
dead.append(j)
print(n - len(set(dead)))
``` | 0 |
|
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*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,683,984,736 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=input();b=(n%2*5+4);print b,n-b
| 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<=<<=*x*,<=*y*<=<<=*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
n=input();b=(n%2*5+4);print b,n-b
``` | -1 |
|
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding. | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16",
"output": "50"
},
{
"input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75",
"output": "7"
},
{
"input": "8 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "3 8\n4 3 2",
"output": "2"
},
{
"input": "3 8\n2 4 2",
"output": "2"
},
{
"input": "3 6\n1 3 2",
"output": "2"
},
{
"input": "3 6\n3 2 5",
"output": "2"
},
{
"input": "3 8\n4 2 1",
"output": "2"
},
{
"input": "5 6\n2 3 5 1 2",
"output": "2"
},
{
"input": "2 6\n5 3",
"output": "2"
},
{
"input": "4 12\n6 4 3 1",
"output": "2"
},
{
"input": "3 18\n1 9 6",
"output": "2"
},
{
"input": "3 9\n3 2 1",
"output": "3"
},
{
"input": "3 6\n5 3 2",
"output": "2"
},
{
"input": "2 10\n5 2",
"output": "2"
},
{
"input": "2 18\n6 3",
"output": "3"
},
{
"input": "4 12\n1 2 12 3",
"output": "1"
},
{
"input": "3 7\n3 2 1",
"output": "7"
},
{
"input": "3 6\n3 2 1",
"output": "2"
},
{
"input": "5 10\n5 4 3 2 1",
"output": "2"
},
{
"input": "5 16\n8 4 2 1 7",
"output": "2"
},
{
"input": "6 7\n6 5 4 3 7 1",
"output": "1"
},
{
"input": "2 6\n3 2",
"output": "2"
},
{
"input": "2 4\n4 1",
"output": "1"
},
{
"input": "6 8\n2 4 1 3 5 7",
"output": "2"
},
{
"input": "6 8\n6 5 4 3 2 1",
"output": "2"
},
{
"input": "6 15\n5 2 3 6 4 3",
"output": "3"
},
{
"input": "4 8\n2 4 8 1",
"output": "1"
},
{
"input": "2 5\n5 1",
"output": "1"
},
{
"input": "4 18\n3 1 1 2",
"output": "6"
},
{
"input": "2 1\n2 1",
"output": "1"
},
{
"input": "3 10\n2 10 5",
"output": "1"
},
{
"input": "5 12\n12 4 4 4 3",
"output": "1"
},
{
"input": "3 6\n6 3 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "1"
},
{
"input": "3 18\n1 9 3",
"output": "2"
},
{
"input": "3 8\n7 2 4",
"output": "2"
},
{
"input": "2 100\n99 1",
"output": "100"
},
{
"input": "4 12\n1 3 4 2",
"output": "3"
},
{
"input": "3 6\n2 3 1",
"output": "2"
},
{
"input": "4 6\n3 2 5 12",
"output": "2"
},
{
"input": "4 97\n97 1 50 10",
"output": "1"
},
{
"input": "3 12\n1 12 2",
"output": "1"
},
{
"input": "4 12\n1 4 3 2",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 19\n7 1 1",
"output": "19"
},
{
"input": "5 12\n12 4 3 4 4",
"output": "1"
},
{
"input": "3 8\n8 4 2",
"output": "1"
},
{
"input": "3 3\n3 2 1",
"output": "1"
},
{
"input": "5 6\n3 2 4 2 2",
"output": "2"
},
{
"input": "2 16\n8 4",
"output": "2"
},
{
"input": "3 6\n10 2 3",
"output": "2"
},
{
"input": "5 3\n2 4 5 3 6",
"output": "1"
},
{
"input": "11 99\n1 2 3 6 5 4 7 8 99 33 66",
"output": "1"
},
{
"input": "3 12\n3 12 2",
"output": "1"
},
{
"input": "5 25\n24 5 15 25 23",
"output": "1"
},
{
"input": "2 4\n8 1",
"output": "4"
},
{
"input": "4 100\n2 50 4 1",
"output": "2"
},
{
"input": "3 28\n7 14 1",
"output": "2"
},
{
"input": "4 8\n2 8 4 1",
"output": "1"
},
{
"input": "4 6\n6 1 2 3",
"output": "1"
},
{
"input": "2 12\n4 3",
"output": "3"
},
{
"input": "4 12\n1 2 4 3",
"output": "3"
},
{
"input": "5 12\n2 3 12 6 4",
"output": "1"
},
{
"input": "4 4\n1 2 2 4",
"output": "1"
},
{
"input": "3 6\n2 3 2",
"output": "2"
},
{
"input": "4 21\n21 20 21 2",
"output": "1"
},
{
"input": "3 8\n3 4 2",
"output": "2"
},
{
"input": "1 25\n25",
"output": "1"
},
{
"input": "99 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "1"
},
{
"input": "98 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98",
"output": "1"
},
{
"input": "79 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79",
"output": "1"
},
{
"input": "4 32\n1 1 1 1",
"output": "32"
},
{
"input": "1 100\n1",
"output": "100"
},
{
"input": "2 100\n7 1",
"output": "100"
},
{
"input": "7 24\n1 3 6 4 5 2 7",
"output": "4"
},
{
"input": "6 87\n1 2 8 4 5 7",
"output": "87"
},
{
"input": "1 88\n1",
"output": "88"
},
{
"input": "1 89\n1",
"output": "89"
}
] | 1,585,414,788 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 155 | 0 | # https://vjudge.net/contest/364837#problem/B
n, k = map(lambda x: int(x), input().split(' '))
buckets = list(map(lambda x: int(x), input().split(' ')))
buckets = sorted(buckets, reverse=True)
for b in buckets:
if k % b == 0:
print(int(k/b))
break
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input Specification:
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output Specification:
Print one integer number — the minimum number of hours required to water the garden.
Demo Input:
['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n']
Demo Output:
['2\n', '7\n']
Note:
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | ```python
# https://vjudge.net/contest/364837#problem/B
n, k = map(lambda x: int(x), input().split(' '))
buckets = list(map(lambda x: int(x), input().split(' ')))
buckets = sorted(buckets, reverse=True)
for b in buckets:
if k % b == 0:
print(int(k/b))
break
``` | 3 |
|
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n0 1 1",
"output": "YES"
},
{
"input": "3\n0 1 0",
"output": "NO"
},
{
"input": "2\n0 1",
"output": "YES"
},
{
"input": "2\n1 0",
"output": "YES"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "10\n1 0 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5\n1 1 1 1 0",
"output": "YES"
},
{
"input": "4\n1 0 1 0",
"output": "NO"
},
{
"input": "4\n1 1 0 0",
"output": "NO"
},
{
"input": "10\n0 0 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "94\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",
"output": "NO"
},
{
"input": "64\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",
"output": "NO"
},
{
"input": "34\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",
"output": "NO"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "231\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "10\n1 1 0 1 1 1 0 1 1 1",
"output": "NO"
}
] | 1,500,475,506 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 46 | 4,608,000 | n = int(input())
string = input()
if list(map(int, string.split())).count(0) == 1:
print("YES")
elif n == 1:
print("YES")
else:
print("NO") | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
Output Specification:
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
Demo Input:
['3\n1 0 1\n', '3\n1 0 0\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
string = input()
if list(map(int, string.split())).count(0) == 1:
print("YES")
elif n == 1:
print("YES")
else:
print("NO")
``` | 0 |
|
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 1,678,182,280 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
if n == 1:
print(1)
else:
print(1 if n % 2 == 0 else 2) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
n = int(input())
if n == 1:
print(1)
else:
print(1 if n % 2 == 0 else 2)
``` | 0 |
|
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output": "16"
},
{
"input": "5",
"output": "32"
},
{
"input": "6",
"output": "64"
},
{
"input": "7",
"output": "128"
},
{
"input": "8",
"output": "256"
},
{
"input": "9",
"output": "512"
},
{
"input": "11",
"output": "2048"
},
{
"input": "12",
"output": "4096"
},
{
"input": "13",
"output": "8092"
},
{
"input": "14",
"output": "16184"
},
{
"input": "15",
"output": "32368"
},
{
"input": "16",
"output": "64736"
},
{
"input": "17",
"output": "129472"
},
{
"input": "18",
"output": "258944"
},
{
"input": "19",
"output": "517888"
},
{
"input": "20",
"output": "1035776"
},
{
"input": "21",
"output": "2071552"
},
{
"input": "22",
"output": "4143104"
},
{
"input": "23",
"output": "8286208"
},
{
"input": "24",
"output": "16572416"
},
{
"input": "25",
"output": "33144832"
},
{
"input": "26",
"output": "66289664"
},
{
"input": "27",
"output": "132579328"
},
{
"input": "28",
"output": "265158656"
},
{
"input": "29",
"output": "530317312"
},
{
"input": "30",
"output": "1060634624"
},
{
"input": "31",
"output": "2121269248"
},
{
"input": "32",
"output": "4242538496"
},
{
"input": "33",
"output": "8485076992"
},
{
"input": "34",
"output": "16970153984"
}
] | 1,617,214,442 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 78 | 204,800 | import math
import sys
import collections
import bisect
import time
def get_ints():return map(int, sys.stdin.readline().strip().split())
def get_list():return list(map(int, sys.stdin.readline().strip().split()))
def get_string():return sys.stdin.readline().strip()
for t in range(1):
n=int(input())
arr=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968]
print(arr[n]) | Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
Demo Input:
['3\n', '10\n']
Demo Output:
['8\n', '1024\n']
Note:
none | ```python
import math
import sys
import collections
import bisect
import time
def get_ints():return map(int, sys.stdin.readline().strip().split())
def get_list():return list(map(int, sys.stdin.readline().strip().split()))
def get_string():return sys.stdin.readline().strip()
for t in range(1):
n=int(input())
arr=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968]
print(arr[n])
``` | 3 |
|
67 | A | Partial Teacher | PROGRAMMING | 1,800 | [
"dp",
"graphs",
"greedy",
"implementation"
] | A. Partial Teacher | 1 | 256 | A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one.
It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum. | The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks. | Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | [
"5\nLRLR\n",
"5\n=RRR\n"
] | [
"2 1 2 1 2\n",
"1 1 2 3 4\n"
] | none | 500 | [
{
"input": "5\nLRLR",
"output": "2 1 2 1 2"
},
{
"input": "5\n=RRR",
"output": "1 1 2 3 4"
},
{
"input": "6\nRLRL=",
"output": "1 2 1 2 1 1"
},
{
"input": "3\nR=",
"output": "1 2 2"
},
{
"input": "7\nRR==RR",
"output": "1 2 3 3 3 4 5"
},
{
"input": "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==",
"output": "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2 3 3 4 4 5 6 6 6 1 1 2 2 3 3 4 5 6 6 7 8 8 9 2 1 2 4 3 3 2 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 1 2 3 3 1 2 2 2 3 3 4 4 2 1 2 1 2 1 2 2 3 4 4 5 2 1 2 1 2 2 3 5 4 3 3 3 2 2 1 2 2 3 4 4 5 6 7 1 1 4 3 2 1 2 2 2 1 1 2 3 1 8 7 6 5 4 3 2 1 3 2 2 2 2 1 2 1 2 1 2 1 2 4 3 2 2 1 4 3 2 2 2 2 1 2 1 2 3 3 3"
},
{
"input": "333\nLL=LR=R=RRR=L=LRR=RLRLLLR=LRL=RRLRRRLLRRLL====RL=L====LLRL=RR==L==RLL==L=R=RLRR==LRRL=LRL=RLRLRR=R=LR=LLR===LRL=RRL====R==LRLR===LLLLL=LLLRLRLLLLLL==RLL=RL==LR=RRLRLL=R=R=R=RLRLRLLRRL==L==LRR=L=R=R===RLR=R=L=LR=LRLRR=RRL=L=RRLR=RRL=RRRL=RLRRRLLLRR=RRRLRLLLR==RR=RL===R=RL=RLL====RRRR=LR=LL=RL==RRLR====R=L=R==L=R=R=RLR=RR=R=LRRRRLLL",
"output": "4 3 2 2 1 2 2 3 3 4 5 6 6 2 2 1 2 3 3 4 1 4 3 2 1 2 2 1 2 1 1 2 3 1 2 3 4 2 1 2 3 2 1 1 1 1 1 5 4 4 3 3 3 3 3 2 1 2 1 1 2 3 3 3 1 1 1 4 3 2 2 2 1 1 2 2 3 1 2 3 3 3 1 2 3 2 2 1 2 1 1 2 1 2 1 2 3 3 4 4 1 3 3 2 1 2 2 2 2 1 2 1 1 2 3 1 1 1 1 1 2 2 2 1 2 1 9 9 9 9 8 7 6 5 4 4 3 2 1 2 1 7 6 5 4 3 2 1 1 1 3 2 1 1 3 2 2 2 1 2 2 3 4 1 3 2 1 1 2 2 3 3 4 4 5 1 2 1 3 2 1 2 4 3 3 3 2 2 2 1 2 3 3 1 1 2 2 3 3 3 3 4 1 2 2 3 3 2 2 1 2 2 1 2 1 2 3 3 4 5 2 2 1 1 2 3 1 2 2 3 4 1 1 2 3 4 1 1 2 1 2 3 4 3 2 1 2 3 3 4 5 6 1 4 3 2..."
},
{
"input": "24\nR=R==RL=RL=RLL=LLL=LLRL",
"output": "1 2 2 3 3 3 4 1 1 2 1 1 8 7 6 6 5 4 3 3 2 1 2 1"
},
{
"input": "438\nLR=RLLLRL=R==LLR=RRLRRR==RLRLRLLRRRRRLRL=RRRRLRR==RR=RR=LLRR=L=LLRRRLLR==RL=L=LLR=L=R==LLR=L=RR==LRL=LLL=RRR=R=LRLLRLLLR==LRRLLL=L==LLR=RL=LLLLR=RR=LR=RL==LRLRR=RRRRRLRLRR==RR=LLLRLR====LRRLL==LR==LL=LLRR=LRL=RRRRLR=RLLR=R=LLLRRRRR===R==LRLLRLR=LLL=L=L=R=RLLR=R=RR=RL=LLRRLLRR=LRRRR==LR==L==R=L=L=R===LLL=LL==L=L=LLLLL==RRRR==R=RLL=RLR=RRRR=R=L=RRRLLRRLRRRLLRLLRRRL=LR=R=LRLRL=R=RLRRLRRL==R=RRR=RLLR=RR=LL=RLR=R==R===RRLR=LLLR=L===LR=L=R",
"output": "2 1 2 2 4 3 2 1 2 1 1 3 3 3 2 1 2 2 3 4 1 2 3 4 4 4 5 1 2 1 3 2 1 2 3 4 5 6 1 2 1 1 2 3 4 5 1 2 3 3 3 4 5 5 6 7 7 2 1 2 4 4 3 3 2 1 2 3 4 2 1 2 2 2 5 4 4 3 3 2 1 2 2 1 1 3 3 3 2 1 2 2 1 1 2 3 3 3 1 5 4 4 3 2 1 1 2 3 4 4 5 5 1 3 2 1 4 3 2 1 2 2 2 1 2 7 6 5 4 4 3 3 3 2 1 2 2 6 5 5 4 3 2 1 2 2 3 4 4 1 2 2 3 2 2 2 1 2 1 2 3 3 4 5 6 7 8 1 2 1 2 3 3 3 4 5 5 3 2 1 2 1 2 2 2 2 2 1 2 4 3 2 2 2 1 5 5 5 4 3 3 2 1 2 3 3 1 2 1 1 2 3 4 5 1 2 2 3 2 1 2 2 4 4 3 2 1 2 3 4 5 6 6 6 6 7 7 7 1 3 2 1 2 1 6 6 5 4 3 3 2 2 1 1 2 2..."
},
{
"input": "453\nR==LL==RRLLRRLR=L=LRLL=LRRR=R====L=RL======RR==RRRR=LRR=LLLRR=LLLLL===LL=LLL=LR=RLRL===L==R=LRL=L=R==RRLLR=L==LRR=RRLRLLRR=LL==RLRLLRRRL=RRL=R====L=RLRR=RR=RRRL=R=RL=LLR=LR=L=RR=RR====LRRLRRLLR==R==L==RRLLRLR=RLLLLR==L=L=L=RR==L=LRRRL=R==RRL=LRR=RRRRRL===RLRLR=RLRLRLRLRR=RL=LL=RLLRR=LL=RLL=L=LRLLLLLR==RRL=R=L===LRLLL=RRRLR=LR====RR=L===LLLL=R=LLLRRRLL=LL==RLRL=LRLRL=RR=RLR==LLR=LR=RLLRLRRLL==L=LL==L==RLRLRLL=L=RLLR==LLRRLRRL==L=R=RLLRLLLL====L=====",
"output": "1 3 3 3 2 1 1 1 2 3 2 1 2 3 1 3 3 2 2 1 4 3 2 2 1 2 3 4 4 5 5 5 5 5 1 1 2 1 1 1 1 1 1 1 2 3 3 3 4 5 6 7 7 1 2 4 4 3 2 1 2 12 12 11 10 9 8 7 7 7 7 6 5 5 4 3 2 2 1 2 2 3 1 3 2 2 2 2 1 1 1 2 2 1 3 2 2 1 1 2 2 2 3 4 2 1 3 3 2 2 2 1 2 3 3 4 5 1 3 2 1 2 3 3 2 1 1 1 2 1 3 2 1 2 3 4 1 1 2 3 1 1 2 2 2 2 2 1 1 2 1 2 3 3 4 5 5 6 7 8 1 1 2 2 4 3 3 2 1 2 2 1 2 2 1 1 2 3 3 4 5 5 5 5 5 1 2 3 1 2 3 2 1 2 2 2 3 3 3 1 1 1 2 3 2 1 2 1 2 2 5 4 3 2 1 4 4 4 3 3 2 2 1 1 2 3 3 3 2 2 1 2 3 4 1 1 2 2 2 3 4 2 2 1 2 3 3 4 5 6 7 8 1 1..."
},
{
"input": "100\n=L=L=L=R=LR=RRRLRL=LRL=RRLLLLRL=R==R=LLLRR===RR=LR==LRLR===RRLRLLRLLR=LRLRR=L=LRRLLLRR==LLRLLLL==RL",
"output": "4 4 3 3 2 2 1 1 2 2 1 2 2 3 4 5 1 3 2 2 1 2 1 1 2 5 4 3 2 1 2 1 1 2 2 2 4 4 3 2 1 2 3 3 3 3 4 5 5 1 2 2 2 1 2 1 2 2 2 2 3 4 1 3 2 1 3 2 1 2 2 1 2 1 2 3 3 2 2 1 2 4 3 2 1 2 3 3 3 2 1 5 4 3 2 1 1 1 2 1"
},
{
"input": "484\nLLRRRL==RRLRRLR=LRR=RL=LLLRL===RLRRRLRR=RRRL=LLLLRL==RL==R==LLLRL=RLLRLRLLLLLLLRRLL=LLR=LLR==RLL==LLLR=RL==LL=LRRL=LLRRRLR====R=R=LRRRLLL==RLRRLR=LL==LLRLR===RR=LR==RL==L==R====LRL=LR=R=R=R=LL=L=RLR=RL==R==LRLRL==L==LL=LR=L=RRRR=R==RRLRRRLR==R=LL===R===RLRRR===LRRLLRRRRR=L==LLRRRRLRRRLL===L==LR==LR==RRLRRLRLLLL=RRL=L=LLLRLRRLLL=LRRRRLLLR=L=LL=LRLL=R==L=LRR=R=LLLRR=LRRRLR=R=RLLRR=LRL===LL==LR===L=L=L=RLL=LRRL=LL==RL==RRL====RR=L=R==L==RRL=LLRLR=RLLLL==R==RRL=====LR=RRR=LRLRRR=RLR",
"output": "3 2 1 2 3 4 1 1 1 2 3 1 2 3 1 2 2 1 2 3 3 5 4 4 3 2 1 2 1 1 1 1 2 1 2 3 4 1 2 3 3 4 5 6 5 5 4 3 2 1 2 1 1 1 2 1 1 1 4 4 4 3 2 1 2 1 1 3 2 1 2 1 8 7 6 5 4 3 2 1 2 5 4 3 3 2 1 3 3 2 1 2 2 2 6 5 4 4 4 3 2 1 2 2 5 4 4 4 3 2 2 1 2 4 3 3 2 1 2 3 4 1 2 2 2 2 2 3 3 4 4 1 2 3 4 3 2 1 1 1 2 1 2 3 1 5 5 4 3 3 3 2 1 2 1 2 2 2 2 3 4 4 1 2 2 2 3 2 2 2 1 1 1 2 2 2 2 2 1 3 2 2 1 2 2 3 3 4 4 5 5 3 2 2 1 1 2 1 2 2 3 1 1 1 2 2 2 1 2 1 6 5 5 5 4 4 4 3 2 2 1 2 2 1 1 2 3 4 5 5 6 6 6 7 8 1 2 3 4 1 2 2 2 3 3 2 1 1 1 1 2 2 2 2 3 1..."
},
{
"input": "338\n==R===L=RLRLR===RR=RRL==R=R=RLRLLRLRRRLR=LR=RR=RLLRR=RRRLLRLL=RRRRRLRLLLL=RLLRLLLRL===RRR=RRLLR=LLLL===RLL==LRLLLLRLLLLR=====RLRLRLRL=L==RRLL=RLL===LL=R=RRL=LL=L==RRLLR=LLRLL=LL=LL==RRLR=L=RLLL=LRLLLRRLR=RL=RR=R=L==RLRLL=LRRLLLLLL=RRL==RLL==R===LR===LRLRLR==LR=RR==RR=RRRRRLRRRLRLLRRRLL=LR=RRR=RL=R=LRRLR==RRR=LLL===RR=RL==RRLLL=RL=L=RLL",
"output": "1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 2 2 3 4 4 5 6 1 1 1 2 2 3 3 4 1 3 2 1 2 1 2 3 4 1 2 2 1 2 2 3 4 4 5 2 1 2 3 3 4 5 6 2 1 3 2 1 1 2 3 4 5 6 1 5 4 3 2 1 1 3 2 1 4 3 2 1 2 1 1 1 1 2 3 4 4 5 6 2 1 5 5 4 3 2 1 1 1 1 4 3 2 2 2 1 5 4 3 2 1 5 4 3 2 1 2 2 2 2 2 2 3 1 2 1 2 1 3 2 2 1 1 1 2 3 2 1 1 5 4 3 3 3 3 2 1 1 2 2 3 5 4 4 3 2 2 1 1 1 2 3 2 1 3 3 2 1 7 6 5 5 4 3 3 2 1 1 1 2 3 1 2 2 1 1 5 4 3 2 2 1 4 3 2 1 2 3 1 2 2 3 1 1 2 3 3 4 4 1 1 1 2 1 4 3 2 2 1 2 7 6 5 4 3 2 1 1 2 3 1 1 1 3 2 1 1 1 2 2 2 2 1 2 2 2 2 1 2 1 2 1..."
},
{
"input": "198\nLLRRR=RRRRLRRLRR=R===R=RL==R=RLLLR=R=L=LR=R====RRL=RRR=LL=R=RR=RRRLRRLRRR==L=LRLLL====LR=RL==L===LRR=L=L==R==R==L=LLL===R=LLL=R=L=LLLLRLL=RL=LRRLR=RL==RR=R==RLR==R=R==RLRL=LL=RRR=R===LLLRRRRL=RLRLL",
"output": "3 2 1 2 3 4 4 5 6 7 8 1 2 3 1 2 3 3 4 4 4 4 5 5 6 1 1 1 2 2 4 3 2 1 2 2 3 3 2 2 1 2 2 3 3 3 3 3 4 5 1 1 2 3 4 4 2 1 1 2 2 3 4 4 5 6 7 1 2 3 1 2 3 4 4 4 2 2 1 5 4 3 2 2 2 2 2 1 2 2 4 3 3 3 2 2 2 2 1 2 3 3 2 2 1 1 1 2 2 2 5 5 5 4 4 3 2 1 1 1 1 4 4 3 2 1 1 6 6 5 5 4 3 2 1 3 2 1 1 3 2 2 1 2 3 1 2 2 3 1 1 1 2 3 3 4 4 4 5 1 2 2 2 3 3 4 4 4 5 1 4 3 3 2 1 1 2 3 4 4 5 5 5 5 3 2 1 2 3 4 5 1 1 2 1 3 2 1"
},
{
"input": "426\nR==LRRRL=R==LLRRRLRLLLR=====R=RRRLLR==LL=L=RR=L=L==LRRR=LL=RR=LRRRLRLLR=R==RL=RRL===RRRL=RLRRRRRLRLLR=LR==LL=R=RRRLRLLLRL=L=RL=R==L==RRLLRRR=RRR==RL=====R=R==RLR=R==L==RL=RRR=RLL=L=LL=RLLR===R=RL==LR=LRLLLR==L==LR=RLLLRRRRL=RRRL=RL=LR=====R=RR=L=RL==L=LLRL=LL=L==LR=RLLRR=RLRLR=LRLLRR===L===RLL=RR==RR=R====RRLR=L=RLRLRLLRLLL=R=R=LLLRRRLR=L==L=R==LLR=L=L==RRLR=LR=R=LR=RR=R=LLRL=L=R=LLLLLR==L=LR=R=L=LL==LRR=L===RL==LL==R==RL",
"output": "1 2 2 2 1 2 3 4 1 1 3 3 3 2 1 2 3 4 1 4 3 2 1 2 2 2 2 2 2 3 3 4 5 6 2 1 4 4 4 3 2 2 1 1 2 4 4 3 3 2 2 2 1 2 3 4 4 2 1 1 2 3 3 1 2 3 4 1 3 2 1 2 2 3 3 3 4 1 1 2 3 1 1 1 1 2 3 4 1 1 2 1 2 3 4 5 6 1 3 2 1 2 2 1 3 3 3 2 1 1 2 2 3 4 5 1 4 3 2 1 3 2 2 1 1 2 1 1 2 2 2 1 1 1 2 3 2 1 2 3 4 4 5 6 7 7 7 8 1 1 1 1 1 1 2 2 3 3 3 4 1 2 2 3 3 3 1 1 1 2 1 1 2 3 4 4 6 5 4 4 3 3 2 1 1 3 2 1 2 2 2 2 3 3 4 2 2 2 1 2 2 1 4 3 2 1 3 3 3 2 2 2 1 2 2 4 3 2 1 2 3 4 5 1 1 2 3 4 1 1 3 2 2 1 2 2 2 2 2 2 3 3 4 5 5 1 1 5 4 4 4 3 3 2 1 6..."
},
{
"input": "10\nRL=R=RLR=",
"output": "1 2 1 1 2 2 3 1 2 2"
},
{
"input": "2\nL",
"output": "2 1"
},
{
"input": "100\nR=R=RRR=R=RR=RRLL=RLRLLLLLR==L=======L=LLR==RL=R=LRLLLR==LLLL=RRRL=LRL=LR=====L=LLLRRL=LLR===RLR=RR",
"output": "1 2 2 3 3 4 5 6 6 7 7 8 9 9 10 11 2 1 1 2 1 6 5 4 3 2 1 5 5 5 4 4 4 4 4 4 4 4 3 3 2 1 2 2 2 3 1 1 2 2 1 4 3 2 1 5 5 5 4 3 2 1 1 2 3 4 2 2 1 3 2 2 1 5 5 5 5 5 5 4 4 3 2 1 2 4 3 3 2 1 2 2 2 2 3 1 2 2 3 4"
},
{
"input": "23\nL=LLLLRL=RR=RLLLL=RR==",
"output": "6 5 5 4 3 2 1 2 1 1 2 3 3 5 4 3 2 1 1 2 3 3 3"
},
{
"input": "432\n=R=RRL=LLR=LLRLLRL=RL==R===L===LR=RR=LL==RLRLRRL=LRL=RLLRRLLL==RLLR=LLLRL=RLRRLLRRL=RLRRL=LL=RR=RL==LL===R==RR=LLL=RRR===R=RLLLR====R==RL=LRL=LLRLRLLRL=LLR==R==LLLL===R=R=LR=L=LRR=LR==LLL=L=LR=R=RLR=L=R==L=RLLLRR=R===R==L==R===L=RLLRLLLLLLL=LRRL=LLLL=RR==R===RR=LLLLRLRL==R====LR==LRL=L=R=R=L====LRLRL=RRR=RRRL====R=LRLRL===LRLLLR==R==LL=R==L==L=LRRRL==LL=R=L=LL=RRRLLRLRL==LLR===RRR=RRLRRR=R=RL===L=RRRR=R=RL===R==L===LLR=LLRLLLRL",
"output": "1 1 2 2 3 4 3 3 2 1 3 3 2 1 3 2 1 2 1 1 2 1 1 1 3 3 3 3 2 2 2 2 1 2 2 3 4 4 2 1 1 1 2 1 2 1 2 3 2 2 1 2 1 1 3 2 1 2 4 3 2 1 1 1 3 2 1 4 4 3 2 1 2 1 1 2 1 2 3 2 1 2 3 1 1 2 1 2 4 3 3 2 1 1 2 3 3 4 3 3 3 2 1 1 1 1 2 2 2 3 4 4 3 2 1 1 2 3 4 4 4 4 5 5 6 3 2 1 2 2 2 2 2 3 3 3 4 2 2 1 4 3 3 2 1 2 1 3 2 1 4 3 3 2 1 2 2 2 5 5 5 4 3 2 1 1 1 1 2 2 3 3 1 3 3 2 2 1 2 3 3 1 6 6 6 5 4 3 3 2 2 1 2 2 3 3 4 1 2 2 1 1 2 2 2 1 1 4 3 2 1 2 3 3 4 4 4 4 5 5 5 1 1 1 2 2 2 2 1 1 3 2 1 9 8 7 6 5 4 3 2 2 1 2 6 5 5 4 3 2 1 1 2 3 3 3..."
},
{
"input": "4\nRRL",
"output": "1 2 3 1"
},
{
"input": "17\n=RRR=L==LLLLRRRL",
"output": "1 1 2 3 6 6 5 5 5 4 3 2 1 2 3 4 1"
},
{
"input": "20\nRRLLLLLRRRRRRRRLRLR",
"output": "1 2 6 5 4 3 2 1 2 3 4 5 6 7 8 9 1 2 1 2"
},
{
"input": "9\nR===RRLL",
"output": "1 2 2 2 2 3 4 2 1"
},
{
"input": "15\n=RRR=LLLLLRRRL",
"output": "1 1 2 3 6 6 5 4 3 2 1 2 3 4 1"
}
] | 1,590,933,765 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 280 | 1,740,800 | n = int(input())
a = list(input())
ans = []
num = 0
flag = False
if a[0] == 'L':
flag = True
for i in range(n-1):
if a[i] == 'L':
flag = True
if flag:
if a[i] == 'L' or a[i] == '=':
num += 1
else:
flag = False
if num != 0:
ans.append([i-num, num])
num = 0
if flag:
if num != 0:
ans.append([n-1-num, num])
answer = [1 for i in range(n)]
for i in ans:
y = 0
if i[0]+i[1] < n-1:
y = 1
x = i[1] + y
for j in range(i[0], i[0]+i[1]):
answer[j] = x
x -= 1
j = 1
for i in a:
if i == 'R':
answer[j] = answer[j-1] + 1
if i == '=':
answer[j] = answer[j-1]
#if i == 'L':
# answer[j] = answer[j-1] - 1
j += 1
print(*answer)
'''
5
LRLR
1 2 1 2 1 1
''' | Title: Partial Teacher
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one.
It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum.
Input Specification:
The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks.
Output Specification:
Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
Demo Input:
['5\nLRLR\n', '5\n=RRR\n']
Demo Output:
['2 1 2 1 2\n', '1 1 2 3 4\n']
Note:
none | ```python
n = int(input())
a = list(input())
ans = []
num = 0
flag = False
if a[0] == 'L':
flag = True
for i in range(n-1):
if a[i] == 'L':
flag = True
if flag:
if a[i] == 'L' or a[i] == '=':
num += 1
else:
flag = False
if num != 0:
ans.append([i-num, num])
num = 0
if flag:
if num != 0:
ans.append([n-1-num, num])
answer = [1 for i in range(n)]
for i in ans:
y = 0
if i[0]+i[1] < n-1:
y = 1
x = i[1] + y
for j in range(i[0], i[0]+i[1]):
answer[j] = x
x -= 1
j = 1
for i in a:
if i == 'R':
answer[j] = answer[j-1] + 1
if i == '=':
answer[j] = answer[j-1]
#if i == 'L':
# answer[j] = answer[j-1] - 1
j += 1
print(*answer)
'''
5
LRLR
1 2 1 2 1 1
'''
``` | 0 |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "Still Rozdil"
},
{
"input": "4\n1000000000 100000000 1000000 1000000",
"output": "Still Rozdil"
},
{
"input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6",
"output": "Still Rozdil"
},
{
"input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7",
"output": "8"
},
{
"input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11",
"output": "Still Rozdil"
},
{
"input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "32"
},
{
"input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63",
"output": "19"
},
{
"input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622",
"output": "68"
},
{
"input": "5\n5 5 2 3 1",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "3\n7 7 4",
"output": "3"
},
{
"input": "3\n2 2 1",
"output": "3"
},
{
"input": "3\n4 4 3",
"output": "3"
},
{
"input": "2\n10000001 10000002",
"output": "1"
},
{
"input": "4\n3 3 2 1",
"output": "4"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "2\n1000000000 100000000",
"output": "2"
},
{
"input": "1\n99999999",
"output": "1"
},
{
"input": "3\n5 5 3",
"output": "3"
},
{
"input": "3\n7 7 5",
"output": "3"
},
{
"input": "3\n3 3 1",
"output": "3"
},
{
"input": "4\n10 10 10 1",
"output": "4"
}
] | 1,684,957,308 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 372 | 11,366,400 | def main():
num_towns = int(input())
time_per_town = input().split()
minimum = int(time_per_town[0])
for i in range(len(time_per_town)):
time_per_town[i] = int(time_per_town[i])
if time_per_town[i] < minimum:
minimum = time_per_town[i]
count = 0
index = 0
for i in range(len(time_per_town)):
if time_per_town[i] == minimum:
count += 1
index = i
if count == 1:
print(index + 1)
else:
print("Still Rozdil")
main()
| Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Output Specification:
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
Demo Input:
['2\n7 4\n', '7\n7 4 47 100 4 9 12\n']
Demo Output:
['2\n', 'Still Rozdil\n']
Note:
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | ```python
def main():
num_towns = int(input())
time_per_town = input().split()
minimum = int(time_per_town[0])
for i in range(len(time_per_town)):
time_per_town[i] = int(time_per_town[i])
if time_per_town[i] < minimum:
minimum = time_per_town[i]
count = 0
index = 0
for i in range(len(time_per_town)):
if time_per_town[i] == minimum:
count += 1
index = i
if count == 1:
print(index + 1)
else:
print("Still Rozdil")
main()
``` | 3 |
|
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 998320124 820674098",
"output": "No"
},
{
"input": "948253616 -83299062 1031552680",
"output": "Yes"
},
{
"input": "711980199 216568284 928548487",
"output": "Yes"
},
{
"input": "-453961301 271150176 725111473",
"output": "No"
},
{
"input": "0 0 2000000000",
"output": "Yes"
},
{
"input": "0 0 1999999999",
"output": "No"
},
{
"input": "1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 1000000000",
"output": "No"
},
{
"input": "-1 -1 3",
"output": "No"
},
{
"input": "919785634 216774719 129321944",
"output": "No"
},
{
"input": "-467780354 -721273539 1369030008",
"output": "No"
},
{
"input": "-232833910 -880680184 1774549792",
"output": "Yes"
},
{
"input": "45535578 402686155 1011249824",
"output": "No"
},
{
"input": "-203250176 -30379840 233630015",
"output": "No"
},
{
"input": "-814516648 -75830576 890347222",
"output": "No"
},
{
"input": "869184175 -511854751 1381038923",
"output": "No"
},
{
"input": "552884998 -262338193 815223187",
"output": "No"
},
{
"input": "-133874494 857573117 991447611",
"output": "Yes"
},
{
"input": "169406792 786701289 956108082",
"output": "No"
},
{
"input": "30237137 -989203246 1019440385",
"output": "Yes"
},
{
"input": "576608216 -617624133 1194232352",
"output": "No"
},
{
"input": "-662360368 97618995 759979367",
"output": "Yes"
},
{
"input": "-115989290 321714461 437703756",
"output": "No"
},
{
"input": "-1 -3 2",
"output": "No"
},
{
"input": "-2 -2 2",
"output": "No"
},
{
"input": "0 0 1",
"output": "No"
},
{
"input": "0 -1 7",
"output": "Yes"
},
{
"input": "1 2 7",
"output": "Yes"
},
{
"input": "0 5 6",
"output": "No"
},
{
"input": "0 -4 2",
"output": "No"
},
{
"input": "-5 5 2",
"output": "No"
},
{
"input": "-5 -2 7",
"output": "Yes"
},
{
"input": "5 -5 2",
"output": "No"
}
] | 1,589,891,264 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | x,y,s=[int(i) for i in input().split()]
k=abs(x)+abs(y)
if k<=s:
s-=k
if s%2==0:print('Yes')
else:print('No')
else:print('No')
| Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
Input Specification:
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
Output Specification:
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes".
Demo Input:
['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n']
Demo Output:
['No\n', 'Yes\n', 'No\n', 'Yes\n']
Note:
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
x,y,s=[int(i) for i in input().split()]
k=abs(x)+abs(y)
if k<=s:
s-=k
if s%2==0:print('Yes')
else:print('No')
else:print('No')
``` | 3 |
|
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": "1 7"
},
{
"input": "2 2\nabc\nAbc\nabc",
"output": "1 2"
},
{
"input": "2 1\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 2\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 1\nab\nabc\nabc",
"output": "7 7"
},
{
"input": "2 2\nab\nabc\nabc",
"output": "2 2"
},
{
"input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no",
"output": "1 1"
},
{
"input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa",
"output": "25 25"
},
{
"input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9",
"output": "3 11"
},
{
"input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB",
"output": "44 50"
},
{
"input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL",
"output": "36 65"
},
{
"input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr",
"output": "1 65"
},
{
"input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288",
"output": "6 25"
},
{
"input": "3 1\na\nb\naa\naa",
"output": "13 13"
},
{
"input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc",
"output": "9 11"
},
{
"input": "4 2\n1\n2\n11\n22\n22",
"output": "8 9"
},
{
"input": "2 1\n1\n12\n12",
"output": "7 7"
},
{
"input": "3 1\nab\nabc\nabd\nabc",
"output": "7 13"
},
{
"input": "2 1\na\nab\nab",
"output": "7 7"
},
{
"input": "5 2\na\nb\nc\nab\naa\naa",
"output": "9 15"
},
{
"input": "6 1\n1\n2\n11\n22\n111\n2222\n22",
"output": "13 19"
},
{
"input": "3 1\n1\n2\n11\n11",
"output": "13 13"
},
{
"input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac",
"output": "12 20"
},
{
"input": "4 2\na\nb\nc\nd\na",
"output": "1 9"
},
{
"input": "4 1\n1\n2\n3\n4\n4",
"output": "1 19"
},
{
"input": "5 1\na\nb\nc\nd\nef\nef",
"output": "25 25"
},
{
"input": "6 4\n1\n2\n22\n33\n44\n555\n555",
"output": "11 11"
},
{
"input": "5 2\na\nb\nc\nd\nab\nab",
"output": "15 15"
},
{
"input": "6 2\n1\n2\n3\n4\n5\n23\n23",
"output": "16 16"
},
{
"input": "4 2\na\nb\naa\nbb\naa",
"output": "8 9"
},
{
"input": "5 4\na\nbb\ncc\ndd\nee\nbb",
"output": "2 10"
},
{
"input": "4 1\na\nb\nc\nab\nab",
"output": "19 19"
},
{
"input": "7 100\na\nb\nc\nd\ne\ng\nab\nab",
"output": "7 7"
},
{
"input": "6 1\na\nb\nc\nd\ne\naa\naa",
"output": "31 31"
},
{
"input": "4 1\na\nas\nasd\nasde\nasde",
"output": "19 19"
},
{
"input": "5 2\n1\n2\n3\n11\n22\n22",
"output": "9 15"
},
{
"input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii",
"output": "15 30"
},
{
"input": "3 1\na\nab\nbc\nab",
"output": "7 13"
},
{
"input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc",
"output": "4 11"
}
] | 1,599,105,889 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 409,600 | from collections import Counter
n,k=map(int,input().split())
arr=[]
for _ in range(n):
s=input()
arr.append(s)
passs=input()
hehe=set(arr)
count=[0 for i in range(0,101)]
for i in hehe:
count[len(i)]+=1
j=0
time=0
while j<len(passs):
if count[j]>0:
time+=(count[j]//k)*5+count[j]
j+=1
mini=time+1
abss=count[j]/k
if abss==1:
abss=0
else:
abss=int(abss)
maxx=time+abss*5+count[j]
print(mini,maxx) | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
Output Specification:
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
Demo Input:
['5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n', '4 100\n11\n22\n1\n2\n22\n']
Demo Output:
['1 15\n', '3 4\n']
Note:
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | ```python
from collections import Counter
n,k=map(int,input().split())
arr=[]
for _ in range(n):
s=input()
arr.append(s)
passs=input()
hehe=set(arr)
count=[0 for i in range(0,101)]
for i in hehe:
count[len(i)]+=1
j=0
time=0
while j<len(passs):
if count[j]>0:
time+=(count[j]//k)*5+count[j]
j+=1
mini=time+1
abss=count[j]/k
if abss==1:
abss=0
else:
abss=int(abss)
maxx=time+abss*5+count[j]
print(mini,maxx)
``` | 0 |
|
552 | D | Vanya and Triangles | PROGRAMMING | 1,900 | [
"brute force",
"combinatorics",
"data structures",
"geometry",
"math",
"sortings"
] | null | null | Vanya got bored and he painted *n* distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of the points painted on the plane.
Next *n* lines contain two integers each *x**i*,<=*y**i* (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100) — the coordinates of the *i*-th point. It is guaranteed that no two given points coincide. | In the first line print an integer — the number of triangles with the non-zero area among the painted points. | [
"4\n0 0\n1 1\n2 0\n2 2\n",
"3\n0 0\n1 1\n2 0\n",
"1\n1 1\n"
] | [
"3\n",
"1\n",
"0\n"
] | Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | 2,000 | [
{
"input": "4\n0 0\n1 1\n2 0\n2 2",
"output": "3"
},
{
"input": "3\n0 0\n1 1\n2 0",
"output": "1"
},
{
"input": "1\n1 1",
"output": "0"
},
{
"input": "5\n0 0\n1 1\n2 2\n3 3\n4 4",
"output": "0"
},
{
"input": "5\n0 0\n1 1\n2 3\n3 6\n4 10",
"output": "10"
},
{
"input": "4\n-100 -100\n-100 100\n100 -100\n100 100",
"output": "4"
},
{
"input": "5\n-100 -100\n-100 100\n100 -100\n100 100\n0 0",
"output": "8"
},
{
"input": "4\n1 -100\n2 -100\n100 -99\n99 -99",
"output": "4"
},
{
"input": "25\n26 -54\n16 56\n-42 -51\n92 -58\n100 52\n57 -98\n-84 -28\n-71 12\n21 -82\n-3 -30\n72 94\n-66 96\n-50 -41\n-77 -41\n-42 -55\n-13 12\n0 -99\n-50 -5\n65 -48\n-96 -80\n73 -92\n72 59\n53 -66\n-67 -75\n2 56",
"output": "2300"
},
{
"input": "5\n-62 -69\n3 -48\n54 54\n8 94\n83 94",
"output": "10"
},
{
"input": "33\n0 81\n20 -16\n-71 38\n-45 28\n-8 -40\n34 -49\n43 -10\n-40 19\n14 -50\n-95 8\n-21 85\n64 98\n-97 -82\n19 -83\n39 -99\n43 71\n67 43\n-54 57\n-7 24\n83 -76\n54 -88\n-43 -9\n-75 24\n74 32\n-68 -1\n71 84\n88 80\n52 67\n-64 21\n-85 97\n33 13\n41 -28\n0 74",
"output": "5456"
},
{
"input": "61\n37 -96\n36 -85\n30 -53\n-98 -40\n2 3\n-88 -69\n88 -26\n78 -69\n48 -3\n-41 66\n-93 -58\n-51 59\n21 -2\n65 29\n-3 35\n-98 46\n42 38\n0 -99\n46 84\n39 -48\n-15 81\n-15 51\n-77 74\n81 -58\n26 -35\n-14 20\n73 74\n-45 83\n90 22\n-8 53\n1 -52\n20 58\n39 -22\n60 -10\n52 22\n-46 6\n8 8\n14 9\n38 -45\n82 13\n43 4\n-25 21\n50 -16\n31 -12\n76 -13\n-82 -2\n-5 -56\n87 -31\n9 -36\n-100 92\n-10 39\n-16 2\n62 -39\n-36 60\n14 21\n-62 40\n98 43\n-54 66\n-34 46\n-47 -65\n21 44",
"output": "35985"
},
{
"input": "9\n-41 -22\n95 53\n81 -61\n22 -74\n-79 38\n-56 -32\n100 -32\n-37 -94\n-59 -9",
"output": "84"
},
{
"input": "33\n21 -99\n11 85\n80 -77\n-31 59\n32 6\n24 -52\n-32 -47\n57 18\n76 -36\n96 -38\n-59 -12\n-98 -32\n-52 32\n-73 -87\n-51 -40\n34 -55\n69 46\n-88 -67\n-68 65\n60 -11\n-45 -41\n91 -21\n45 21\n-75 49\n58 65\n-20 81\n-24 29\n66 -71\n-25 50\n96 74\n-43 -47\n34 -86\n81 14",
"output": "5455"
},
{
"input": "61\n83 52\n28 91\n-45 -68\n-84 -8\n-59 -28\n-98 -72\n38 -38\n-51 -96\n-66 11\n-76 45\n95 45\n-89 5\n-60 -66\n73 26\n9 94\n-5 -80\n44 41\n66 -22\n61 26\n-58 -84\n62 -73\n18 63\n44 71\n32 -41\n-50 -69\n-30 17\n61 47\n45 70\n-97 76\n-27 31\n2 -12\n-87 -75\n-80 -82\n-47 50\n45 -23\n71 54\n79 -7\n35 22\n19 -53\n-65 -72\n-69 68\n-53 48\n-73 -15\n29 38\n-49 -47\n12 -30\n-21 -59\n-28 -11\n-73 -60\n99 74\n32 30\n-9 -7\n-82 95\n58 -32\n39 64\n-42 9\n-21 -76\n39 33\n-63 59\n-66 41\n-54 -69",
"output": "35985"
},
{
"input": "62\n-53 -58\n29 89\n-92 15\n-91 -19\n96 23\n-1 -57\n-83 11\n56 -95\n-39 -47\n-75 77\n52 -95\n-13 -12\n-51 80\n32 -78\n94 94\n-51 81\n53 -28\n-83 -78\n76 -25\n91 -60\n-40 -27\n55 86\n-26 1\n-41 89\n61 -23\n81 31\n-21 82\n-12 47\n20 36\n-95 54\n-81 73\n-19 -83\n52 51\n-60 68\n-58 35\n60 -38\n-98 32\n-10 60\n88 -5\n78 -57\n-12 -43\n-83 36\n51 -63\n-89 -5\n-62 -42\n-29 78\n73 62\n-88 -55\n34 38\n88 -26\n-26 -89\n40 -26\n46 63\n74 -66\n-61 -61\n82 -53\n-75 -62\n-99 -52\n-15 30\n38 -52\n-83 -75\n-31 -38",
"output": "37814"
},
{
"input": "2\n0 0\n1 1",
"output": "0"
},
{
"input": "50\n0 -26\n0 -64\n0 63\n0 -38\n0 47\n0 31\n0 -72\n0 60\n0 -15\n0 -36\n0 50\n0 -77\n0 -89\n0 5\n0 83\n0 -52\n0 -21\n0 39\n0 51\n0 -11\n0 -69\n0 57\n0 -58\n0 64\n0 85\n0 -61\n0 0\n0 69\n0 -83\n0 24\n0 -91\n0 -33\n0 -79\n0 -39\n0 -98\n0 45\n0 4\n0 -8\n0 96\n0 35\n0 9\n0 53\n0 90\n0 15\n0 -19\n0 -48\n0 -56\n0 38\n0 92\n0 76",
"output": "0"
},
{
"input": "20\n12 16\n19 13\n19 15\n20 3\n5 20\n8 3\n9 18\n2 15\n2 3\n16 8\n14 18\n16 20\n13 17\n0 15\n10 12\n10 6\n18 8\n6 1\n6 2\n0 6",
"output": "1130"
},
{
"input": "5\n0 0\n1 1\n2 4\n3 8\n4 16",
"output": "10"
},
{
"input": "3\n-100 -100\n0 0\n100 100",
"output": "0"
},
{
"input": "20\n-2 1\n5 1\n1 -1\n1 4\n-5 -5\n3 1\n-5 -3\n-2 3\n-3 4\n5 -4\n-4 5\n3 3\n1 0\n-4 -4\n3 0\n4 -1\n-3 0\n-2 2\n-2 -5\n-5 -4",
"output": "1109"
},
{
"input": "3\n1 1\n3 3\n2 2",
"output": "0"
},
{
"input": "10\n-52 25\n55 76\n97 88\n92 3\n-98 77\n45 90\n6 85\n-68 -38\n-74 -55\n-48 60",
"output": "120"
},
{
"input": "10\n-1 32\n0 88\n-1 69\n0 62\n-1 52\n0 16\n0 19\n-1 58\n0 38\n0 67",
"output": "96"
},
{
"input": "20\n-100 -100\n-99 -99\n-98 -96\n-97 -91\n-96 -84\n-95 -75\n-94 -64\n-93 -51\n-92 -36\n-91 -19\n100 100\n99 99\n98 96\n97 91\n96 84\n95 75\n94 64\n93 51\n92 36\n91 19",
"output": "1136"
}
] | 1,660,427,069 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 4,000 | 60,211,200 | import math
import random
n = int(input())
def equa(a, b):
if a[0] == b[0]:
return math.inf, a[0]
return (math.floor(1000000000*(b[1] - a[1]) / (b[0] - a[0])))/1000000000, math.floor(1000000000*(a[1] - a[0] * ((b[1] - a[1]) / (b[0] - a[0]))))
pontos = [[int(x) for x in input().split()] for _ in range(n)]
#print(pontos)
def main(n, pontos):
pares = dict()
for pri in range(n):
for seg in range(pri+1, n):
if equa(pontos[pri], pontos[seg]) in pares.keys():
pares[equa(pontos[pri], pontos[seg])] += 1
else:
pares[equa(pontos[pri], pontos[seg])] = 1
ans = n*(n-1)*(n-2)/6
#print('possibilis', ans)
for resposta in pares.keys():
# print(f'pre: {resposta},{pares[resposta]}')
resposta = (-1 + math.sqrt(1 + 8 * pares[resposta]))/2 + 1
# print(resposta, '!')
if resposta >= 3:
#print(f'eita! {resposta}! removi {resposta*(resposta-1)*(resposta-2)/6}')
ans -= resposta*(resposta-1)*(resposta-2)/6
return(int(ans))
def slow(n, pontos):
ans = 0
for prim in range(n):
for seg in range(prim + 1, n):
for terc in range(seg + 1, n):
if equa(pontos[prim], pontos[seg]) != equa(pontos[terc], pontos[seg]):
ans += 1
return ans
#for kk in range(10000):
# if kk%100:
# print('estamos', kk)
# n = random.randint(1, 5)
# pontos = list(set([(random.randint(-5, 5), random.randint(-5, 5)) for _ in range(n)]))
# n = len(pontos)
# if slow(n, pontos) != main(n, pontos):
# print('ERRO')
# print(n)
# print(pontos)
# print(slow(n, pontos), main(n, pontos))
# break
print(main(n, pontos))
| Title: Vanya and Triangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got bored and he painted *n* distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of the points painted on the plane.
Next *n* lines contain two integers each *x**i*,<=*y**i* (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100) — the coordinates of the *i*-th point. It is guaranteed that no two given points coincide.
Output Specification:
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Demo Input:
['4\n0 0\n1 1\n2 0\n2 2\n', '3\n0 0\n1 1\n2 0\n', '1\n1 1\n']
Demo Output:
['3\n', '1\n', '0\n']
Note:
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | ```python
import math
import random
n = int(input())
def equa(a, b):
if a[0] == b[0]:
return math.inf, a[0]
return (math.floor(1000000000*(b[1] - a[1]) / (b[0] - a[0])))/1000000000, math.floor(1000000000*(a[1] - a[0] * ((b[1] - a[1]) / (b[0] - a[0]))))
pontos = [[int(x) for x in input().split()] for _ in range(n)]
#print(pontos)
def main(n, pontos):
pares = dict()
for pri in range(n):
for seg in range(pri+1, n):
if equa(pontos[pri], pontos[seg]) in pares.keys():
pares[equa(pontos[pri], pontos[seg])] += 1
else:
pares[equa(pontos[pri], pontos[seg])] = 1
ans = n*(n-1)*(n-2)/6
#print('possibilis', ans)
for resposta in pares.keys():
# print(f'pre: {resposta},{pares[resposta]}')
resposta = (-1 + math.sqrt(1 + 8 * pares[resposta]))/2 + 1
# print(resposta, '!')
if resposta >= 3:
#print(f'eita! {resposta}! removi {resposta*(resposta-1)*(resposta-2)/6}')
ans -= resposta*(resposta-1)*(resposta-2)/6
return(int(ans))
def slow(n, pontos):
ans = 0
for prim in range(n):
for seg in range(prim + 1, n):
for terc in range(seg + 1, n):
if equa(pontos[prim], pontos[seg]) != equa(pontos[terc], pontos[seg]):
ans += 1
return ans
#for kk in range(10000):
# if kk%100:
# print('estamos', kk)
# n = random.randint(1, 5)
# pontos = list(set([(random.randint(-5, 5), random.randint(-5, 5)) for _ in range(n)]))
# n = len(pontos)
# if slow(n, pontos) != main(n, pontos):
# print('ERRO')
# print(n)
# print(pontos)
# print(slow(n, pontos), main(n, pontos))
# break
print(main(n, pontos))
``` | 0 |
|
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
"output": "90"
},
{
"input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88",
"output": "90"
},
{
"input": "90\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n1",
"output": "16"
},
{
"input": "5\n15 30 45 60 75",
"output": "90"
},
{
"input": "6\n14 29 43 59 70 74",
"output": "58"
},
{
"input": "1\n15",
"output": "30"
},
{
"input": "1\n16",
"output": "15"
},
{
"input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89",
"output": "90"
},
{
"input": "76\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n90",
"output": "15"
},
{
"input": "6\n13 17 32 47 60 66",
"output": "81"
},
{
"input": "84\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84",
"output": "90"
},
{
"input": "9\n6 20 27 28 40 53 59 70 85",
"output": "90"
},
{
"input": "12\n14 22 27 31 35 44 62 69 74 79 88 89",
"output": "59"
},
{
"input": "5\n15 30 45 60 74",
"output": "89"
},
{
"input": "72\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89",
"output": "54"
},
{
"input": "8\n1 16 30 31 32 33 34 50",
"output": "49"
},
{
"input": "12\n1 3 6 10 15 21 28 36 45 55 66 78",
"output": "90"
},
{
"input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90",
"output": "80"
},
{
"input": "8\n5 17 20 35 42 53 67 76",
"output": "90"
},
{
"input": "9\n15 28 39 48 55 60 63 64 74",
"output": "89"
},
{
"input": "10\n15 28 39 48 55 60 63 64 74 82",
"output": "90"
},
{
"input": "2\n1 18",
"output": "16"
},
{
"input": "9\n10 20 30 40 50 60 70 80 84",
"output": "90"
},
{
"input": "2\n16 50",
"output": "15"
},
{
"input": "6\n15 30 45 60 75 84",
"output": "90"
},
{
"input": "8\n15 20 30 40 50 60 73 83",
"output": "90"
},
{
"input": "8\n10 20 30 40 50 60 70 80",
"output": "90"
},
{
"input": "3\n1 20 90",
"output": "16"
},
{
"input": "6\n15 30 45 60 74 89",
"output": "90"
}
] | 1,622,861,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | number_interesting = int(input())
current_num = 0
time_watch = 0
arr = list(map(int, input().split()))
for i in range(number_interesting):
current_num = arr[i] - current_num
if current_num > 15:
time_watch = time_watch + 15
break
else:
time_watch = time_watch + current_num
print(time_watch)
| Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order.
Output Specification:
Print the number of minutes Limak will watch the game.
Demo Input:
['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n']
Demo Output:
['35\n', '15\n', '90\n']
Note:
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | ```python
number_interesting = int(input())
current_num = 0
time_watch = 0
arr = list(map(int, input().split()))
for i in range(number_interesting):
current_num = arr[i] - current_num
if current_num > 15:
time_watch = time_watch + 15
break
else:
time_watch = time_watch + current_num
print(time_watch)
``` | 0 |
|
198 | B | Jumping on Walls | PROGRAMMING | 1,400 | [
"shortest paths"
] | null | null | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up; - climb one area down; - jump to the opposite wall. That gets the ninja to the area that is exactly *k* meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area *x* of one wall, then after the jump he is located at area *x*<=+<=*k* of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than *n*, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous. | Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). | [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n"
] | [
"YES\n",
"NO\n"
] | In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | 1,000 | [
{
"input": "7 3\n---X--X\n-X--XX-",
"output": "YES"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "10 1\n-X-X-X-X-X\nX-X-X-X-X-",
"output": "YES"
},
{
"input": "5 4\n-X---\n----X",
"output": "NO"
},
{
"input": "6 2\n--X--X\nXX-X-X",
"output": "YES"
},
{
"input": "50 4\n-X-X-X--X--X--X-XX-----XX--X--------------XXX-X-X-\n--XX---XXXXXXX----XX--X--XXX--XXXX-XX--X--X--X----",
"output": "YES"
},
{
"input": "1 1\n-\nX",
"output": "YES"
},
{
"input": "2 1\n-X\nX-",
"output": "YES"
},
{
"input": "2 1\n-X\n-X",
"output": "NO"
},
{
"input": "1 20\n-\n-",
"output": "YES"
},
{
"input": "1 100000\n-\n-",
"output": "YES"
},
{
"input": "5 2\n-----\nXXXXX",
"output": "YES"
},
{
"input": "5 1\n----X\n----X",
"output": "NO"
},
{
"input": "12 4\n----X---X--X\n-----X-----X",
"output": "YES"
},
{
"input": "12 2\n-X-X-X-X-X-X\nX---XXX--X-X",
"output": "NO"
},
{
"input": "10 8\n-XXXXXXXXX\nXXXXXXXXX-",
"output": "NO"
},
{
"input": "100 10\n-X------XXX--XXX-XXXXXX---XXX---X-XX--XXX----------XX-X-XXXX-X-X-XX-X-X--XXXXX---X--X--XXX-X--XXXXXX\n---X-XXXXXXX--X-XXX--X-XX--XX----XX-X----X-X-XX-X--X-XXXXXXX-XX-X---X--XX-X-XX--XXXXXXX-X--XX--X-XXX",
"output": "NO"
},
{
"input": "12 3\n--XX--XX-XXX\n----X---XXX-",
"output": "NO"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--",
"output": "YES"
},
{
"input": "13 2\n---X---X--X-X\n--X---X-X--X-",
"output": "YES"
},
{
"input": "5 2\n---XX\n---X-",
"output": "YES"
},
{
"input": "101 1\n----------------------------------------------------------------------------------------------------X\n----------------------------------------------------------------------------------------------------X",
"output": "NO"
}
] | 1,684,262,367 | 2,147,483,647 | Python 3 | IDLENESS_LIMIT_EXCEEDED | TESTS | 0 | 0 | 0 | from queue import Queue
import sys
input = sys.stdin.readline
amn = 10**5+5
mp = [[0] * amn for _ in range(5)]
hm = [[0] * amn for _ in range(5)]
valid = False
idx = [[False] * amn for _ in range(5)]
class pii:
def __init__(self, f, s, hh):
self.first = f
self.second = s
self.h = hh
def bfs():
global valid
global idx
idx[0][1] = True
q = Queue()
q.put(pii(0, 1, 0))
while not q.empty():
x, y, h = q.get().first, q.get().second, q.get().h
if y + k > n:
valid = True
return
if y <= h:
continue
if not idx[x][y+1] and mp[x][y+1]:
idx[x][y+1] = True
q.put(pii(x, y+1, h+1))
if not idx[x][y-1] and mp[x][y-1]:
idx[x][y-1] = True
q.put(pii(x, y-1, h+1))
if not idx[x^1][y+k] and mp[x^1][y+k]:
idx[x^1][y+k] = True
q.put(pii(x^1, y+k, h+1))
if __name__ == "__main__":
n, k = map(int, input().split())
for i in range(2):
s = input().strip()
for j in range(1, n+1):
if s[j-1] == '-':
mp[i][j] = 1
else:
mp[i][j] = 0
valid = False
bfs()
if valid:
print("YES")
else:
print("NO")
| Title: Jumping on Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up; - climb one area down; - jump to the opposite wall. That gets the ninja to the area that is exactly *k* meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area *x* of one wall, then after the jump he is located at area *x*<=+<=*k* of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than *n*, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output Specification:
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Demo Input:
['7 3\n---X--X\n-X--XX-\n', '6 2\n--X-X-\nX--XX-\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | ```python
from queue import Queue
import sys
input = sys.stdin.readline
amn = 10**5+5
mp = [[0] * amn for _ in range(5)]
hm = [[0] * amn for _ in range(5)]
valid = False
idx = [[False] * amn for _ in range(5)]
class pii:
def __init__(self, f, s, hh):
self.first = f
self.second = s
self.h = hh
def bfs():
global valid
global idx
idx[0][1] = True
q = Queue()
q.put(pii(0, 1, 0))
while not q.empty():
x, y, h = q.get().first, q.get().second, q.get().h
if y + k > n:
valid = True
return
if y <= h:
continue
if not idx[x][y+1] and mp[x][y+1]:
idx[x][y+1] = True
q.put(pii(x, y+1, h+1))
if not idx[x][y-1] and mp[x][y-1]:
idx[x][y-1] = True
q.put(pii(x, y-1, h+1))
if not idx[x^1][y+k] and mp[x^1][y+k]:
idx[x^1][y+k] = True
q.put(pii(x^1, y+k, h+1))
if __name__ == "__main__":
n, k = map(int, input().split())
for i in range(2):
s = input().strip()
for j in range(1, n+1):
if s[j-1] == '-':
mp[i][j] = 1
else:
mp[i][j] = 0
valid = False
bfs()
if valid:
print("YES")
else:
print("NO")
``` | -1 |
|
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally. | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6",
"output": "100"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611",
"output": "127184126241438168"
},
{
"input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974",
"output": "922371547895579571"
},
{
"input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410",
"output": "663200522440413120"
},
{
"input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682",
"output": "883931400924882950"
},
{
"input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106",
"output": "910849554065102112"
},
{
"input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544",
"output": "504117593849498724"
},
{
"input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617",
"output": "534123411186652380"
},
{
"input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478",
"output": "848714444125692276"
},
{
"input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867",
"output": "866064226130454915"
},
{
"input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081",
"output": "501307028237810934"
},
{
"input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625",
"output": "822104826327386019"
},
{
"input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542",
"output": "941783658451562540"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604",
"output": "-1288212069119760"
},
{
"input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017",
"output": "-18990884587723"
},
{
"input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528",
"output": "-1464096896176096"
},
{
"input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396",
"output": "-120782803247464704"
},
{
"input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983",
"output": "-640647347631440"
},
{
"input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-1000000000000000000"
}
] | 1,519,230,601 | 2,101 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 77 | 19,968,000 | n, m = (int(x) for x in input().split())
a1 = [int(x) for x in input().split()]
a2 = [int(x) for x in input().split()]
print(max([max(a2) * sorted(a1, key=lambda x: -x)[1], min(a2) * min(a1), min(a2) * max(sorted(a1, key=lambda x: -x)[1:])]))
| Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input Specification:
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
Output Specification:
Print a single integer — the brightness of the chosen pair.
Demo Input:
['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n']
Demo Output:
['252\n', '2\n']
Note:
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | ```python
n, m = (int(x) for x in input().split())
a1 = [int(x) for x in input().split()]
a2 = [int(x) for x in input().split()]
print(max([max(a2) * sorted(a1, key=lambda x: -x)[1], min(a2) * min(a1), min(a2) * max(sorted(a1, key=lambda x: -x)[1:])]))
``` | 0 |
|
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,592,424,424 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 140 | 0 | n=int(input())
a=len(str(n))
print(a*(n+1)-int('1'*a)) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
n=int(input())
a=len(str(n))
print(a*(n+1)-int('1'*a))
``` | 3 |
|
424 | B | Megacity | PROGRAMMING | 1,200 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with *n* other locations, the *i*-th one has coordinates (*x**i*, *y**i*) with the population of *k**i* people. You can widen the city boundaries to a circle of radius *r*. In such case all locations inside the circle and on its border are included into the city.
Your goal is to write a program that will determine the minimum radius *r*, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity. | The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the number *k**i* of people in it (1<=≤<=*k**i*<=<<=106). Each coordinate is an integer and doesn't exceed 104 in its absolute value.
It is guaranteed that no two locations are at the same point and no location is at point (0; 0). | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don't exceed 10<=-<=6. | [
"4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n",
"4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n",
"2 1\n1 1 999997\n2 2 1\n"
] | [
"2.8284271\n",
"1.4142136\n",
"-1"
] | none | 1,000 | [
{
"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1",
"output": "2.8284271"
},
{
"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1",
"output": "1.4142136"
},
{
"input": "2 1\n1 1 999997\n2 2 1",
"output": "-1"
},
{
"input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10",
"output": "4.2426407"
},
{
"input": "15 95473\n-9 6 199715\n0 -8 110607\n0 2 6621\n-3 -2 59894\n-10 -8 175440\n-2 0 25814\n10 -4 68131\n7 1 9971\n6 7 821\n6 5 20208\n6 2 68468\n0 7 37427\n1 -3 13337\n-10 7 113041\n-6 -2 44028",
"output": "12.8062485"
},
{
"input": "20 93350\n13 -28 486\n26 -26 48487\n5 -23 143368\n-23 -25 10371\n-2 -7 75193\n0 -8 3\n-6 -11 5015\n-19 -18 315278\n28 -15 45801\n21 8 4590\n-4 -28 12926\n-16 17 9405\n-28 -23 222092\n1 -10 1857\n14 -28 35170\n-4 -22 22036\n-2 -10 1260\n-1 12 375745\n-19 -24 38845\n10 -25 9256",
"output": "26.1725047"
},
{
"input": "30 505231\n-18 16 88130\n-10 16 15693\n16 -32 660\n-27 17 19042\n30 -37 6680\n36 19 299674\n-45 21 3300\n11 27 76\n-49 -34 28649\n-1 11 31401\n25 42 20858\n-40 6 455660\n-29 43 105001\n-38 10 6042\n19 -45 65551\n20 -9 148533\n-5 -24 393442\n-43 2 8577\n-39 18 97059\n12 28 39189\n35 23 28178\n40 -34 51687\n23 41 219028\n21 -44 927\n47 8 13206\n33 41 97342\n10 18 24895\n0 12 288\n0 -44 1065\n-25 43 44231",
"output": "24.5153013"
},
{
"input": "2 500000\n936 1000 500000\n961 976 500000",
"output": "1369.7065379"
},
{
"input": "10 764008\n959 32 23049\n-513 797 38979\n-603 -838 24916\n598 -430 25414\n-280 -624 18714\n330 891 21296\n-347 -68 27466\n650 -842 30125\n-314 889 35394\n275 969 5711",
"output": "1063.7029661"
},
{
"input": "30 295830\n1 -4 24773\n4 3 26175\n-2 -3 14789\n2 -1 46618\n-2 -2 52997\n-3 0 517\n-2 0 18173\n-4 -3 54465\n2 4 63579\n4 -4 41821\n2 2 11018\n0 4 42856\n0 -1 51885\n-3 4 57137\n3 0 4688\n0 2 60137\n-4 4 33484\n-1 3 66196\n3 -1 53634\n0 -2 41630\n-2 1 54606\n2 -2 2978\n2 -3 23733\n1 -2 35248\n-3 -3 15124\n-2 -4 26518\n4 0 28151\n4 -1 18348\n3 3 16914\n-4 2 26013",
"output": "4.4721360"
},
{
"input": "10 511500\n-5129 -3858 76954\n1296 1130 36126\n1219 6732 102003\n-8026 -178 4150\n-3261 1342 105429\n7965 -3013 62561\n5607 8963 53539\n-9044 -3999 16509\n1406 4103 115667\n-3716 2522 110626",
"output": "6841.4753526"
},
{
"input": "20 39342\n2 0 36476\n-3 1 136925\n1 3 31234\n0 -3 23785\n-1 3 77700\n-3 -1 50490\n-1 -3 13965\n-3 2 121093\n3 0 118933\n-3 0 125552\n-3 3 54779\n-2 0 96250\n1 2 142643\n2 2 23848\n0 2 29845\n0 -2 80462\n-1 1 91852\n-1 2 26526\n0 -1 136272\n1 1 108999",
"output": "3.0000000"
},
{
"input": "2 1\n1 0 1\n0 1 999999",
"output": "1.0000000"
},
{
"input": "2 999997\n1 1 1\n1 2 1",
"output": "-1"
}
] | 1,687,469,092 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 29 | 93 | 102,400 | import math
def prsum(r):
p = [0]
for t in range(len(r)):
p.append(int(r[t])+p[-1])
return(p)
def sufsum(a):
pr = [0]
for t in range(1,len(a)+1):
pr.append(int(a[-t])+pr[-1])
return(pr)
def bl(x):
L = 0
R = x+1
while R-L > 1:
m = (L + R)//2
if m**3 <= x:
L = m
else:
R = m
return L
def bll(a,b):
L = 0
R = len(a)+1
while R-L>1:
M = (R+L)//2
if a[M]<b:
L = M
else:
R = M
return(L)
n, m = map(int, input().split())
a = []
g = []
for _ in range(n):
k = []
r = []
b, c, d = map(int, input().split())
g.append(math.sqrt(b**2+c**2))
a.append(math.sqrt(b**2+c**2))
a.append(d)
g = sorted(g)
for elem in g:
for i in range(a.count(elem)):
k.append(a[a.index(elem)+1])
a.pop(a.index(elem))
k = sorted(k)
for el in k:
r.append(el)
k = []
r = prsum(r)
if r[-1]<10**6-m:
print(-1)
else:
print(g[bll(r,10**6-m)]) | Title: Megacity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with *n* other locations, the *i*-th one has coordinates (*x**i*, *y**i*) with the population of *k**i* people. You can widen the city boundaries to a circle of radius *r*. In such case all locations inside the circle and on its border are included into the city.
Your goal is to write a program that will determine the minimum radius *r*, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity.
Input Specification:
The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the number *k**i* of people in it (1<=≤<=*k**i*<=<<=106). Each coordinate is an integer and doesn't exceed 104 in its absolute value.
It is guaranteed that no two locations are at the same point and no location is at point (0; 0).
Output Specification:
In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don't exceed 10<=-<=6.
Demo Input:
['4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n', '4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n', '2 1\n1 1 999997\n2 2 1\n']
Demo Output:
['2.8284271\n', '1.4142136\n', '-1']
Note:
none | ```python
import math
def prsum(r):
p = [0]
for t in range(len(r)):
p.append(int(r[t])+p[-1])
return(p)
def sufsum(a):
pr = [0]
for t in range(1,len(a)+1):
pr.append(int(a[-t])+pr[-1])
return(pr)
def bl(x):
L = 0
R = x+1
while R-L > 1:
m = (L + R)//2
if m**3 <= x:
L = m
else:
R = m
return L
def bll(a,b):
L = 0
R = len(a)+1
while R-L>1:
M = (R+L)//2
if a[M]<b:
L = M
else:
R = M
return(L)
n, m = map(int, input().split())
a = []
g = []
for _ in range(n):
k = []
r = []
b, c, d = map(int, input().split())
g.append(math.sqrt(b**2+c**2))
a.append(math.sqrt(b**2+c**2))
a.append(d)
g = sorted(g)
for elem in g:
for i in range(a.count(elem)):
k.append(a[a.index(elem)+1])
a.pop(a.index(elem))
k = sorted(k)
for el in k:
r.append(el)
k = []
r = prsum(r)
if r[-1]<10**6-m:
print(-1)
else:
print(g[bll(r,10**6-m)])
``` | 0 |
|
292 | D | Connected Components | PROGRAMMING | 1,900 | [
"data structures",
"dfs and similar",
"dp",
"dsu"
] | null | null | We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of *n* computers and *m* cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with *n* nodes and *m* edges. Let's index the computers with integers from 1 to *n*, let's index the cables with integers from 1 to *m*.
Polycarpus was given an important task — check the reliability of his company's network. For that Polycarpus decided to carry out a series of *k* experiments on the computer network, where the *i*-th experiment goes as follows:
1. Temporarily disconnect the cables with indexes from *l**i* to *r**i*, inclusive (the other cables remain connected). 1. Count the number of connected components in the graph that is defining the computer network at that moment. 1. Re-connect the disconnected cables with indexes from *l**i* to *r**i* (that is, restore the initial network).
Help Polycarpus carry out all experiments and for each print the number of connected components in the graph that defines the computer network through the given experiment. Isolated vertex should be counted as single component. | The first line contains two space-separated integers *n*, *m* (2<=≤<=*n*<=≤<=500; 1<=≤<=*m*<=≤<=104) — the number of computers and the number of cables, correspondingly.
The following *m* lines contain the cables' description. The *i*-th line contains space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*) — the numbers of the computers that are connected by the *i*-th cable. Note that a pair of computers can be connected by multiple cables.
The next line contains integer *k* (1<=≤<=*k*<=≤<=2·104) — the number of experiments. Next *k* lines contain the experiments' descriptions. The *i*-th line contains space-separated integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — the numbers of the cables that Polycarpus disconnects during the *i*-th experiment. | Print *k* numbers, the *i*-th number represents the number of connected components of the graph that defines the computer network during the *i*-th experiment. | [
"6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3\n"
] | [
"4\n5\n6\n3\n4\n2\n"
] | none | 2,000 | [
{
"input": "6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3",
"output": "4\n5\n6\n3\n4\n2"
},
{
"input": "2 1\n2 1\n2\n1 1\n1 1",
"output": "2\n2"
},
{
"input": "3 2\n3 2\n3 1\n4\n1 1\n1 2\n2 2\n2 2",
"output": "2\n3\n2\n2"
},
{
"input": "3 3\n2 3\n3 1\n2 1\n5\n2 3\n3 3\n2 2\n2 2\n2 2",
"output": "2\n1\n1\n1\n1"
},
{
"input": "4 5\n1 4\n2 1\n4 3\n2 1\n3 4\n5\n4 5\n2 4\n4 4\n1 3\n4 4",
"output": "1\n2\n1\n2\n1"
},
{
"input": "5 4\n3 2\n5 2\n5 3\n2 3\n8\n4 4\n1 1\n3 4\n1 1\n3 3\n3 4\n3 4\n4 4",
"output": "3\n3\n3\n3\n3\n3\n3\n3"
},
{
"input": "8 10\n8 6\n8 7\n8 3\n3 7\n4 8\n1 6\n5 1\n8 7\n6 8\n1 6\n13\n1 10\n2 6\n3 3\n5 5\n2 2\n1 3\n10 10\n7 7\n2 4\n3 6\n2 7\n9 9\n3 6",
"output": "8\n4\n2\n3\n2\n2\n2\n3\n3\n4\n5\n2\n4"
},
{
"input": "10 10\n7 5\n5 9\n10 9\n8 7\n5 10\n4 2\n8 2\n9 1\n2 8\n10 7\n10\n10 10\n7 9\n2 6\n1 5\n4 7\n9 9\n7 7\n2 6\n6 9\n10 10",
"output": "3\n5\n6\n6\n5\n3\n3\n6\n6\n3"
},
{
"input": "7 14\n7 1\n1 5\n6 4\n7 6\n2 4\n2 4\n7 2\n3 1\n7 6\n6 7\n5 3\n5 4\n1 3\n6 2\n40\n2 3\n14 14\n13 14\n13 13\n7 9\n1 13\n12 14\n14 14\n12 12\n6 10\n6 14\n8 8\n14 14\n9 10\n8 9\n8 11\n9 9\n2 3\n1 11\n13 14\n4 11\n2 9\n1 10\n6 11\n3 3\n4 12\n5 11\n8 8\n7 14\n13 13\n14 14\n14 14\n8 12\n14 14\n8 8\n7 7\n2 11\n10 12\n4 5\n9 10",
"output": "1\n1\n1\n1\n1\n6\n1\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n4\n1\n1\n1\n3\n1\n1\n2\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n3\n1\n1\n1"
}
] | 1,689,286,590 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689286590.325384")# 1689286590.325404 | Title: Connected Components
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of *n* computers and *m* cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with *n* nodes and *m* edges. Let's index the computers with integers from 1 to *n*, let's index the cables with integers from 1 to *m*.
Polycarpus was given an important task — check the reliability of his company's network. For that Polycarpus decided to carry out a series of *k* experiments on the computer network, where the *i*-th experiment goes as follows:
1. Temporarily disconnect the cables with indexes from *l**i* to *r**i*, inclusive (the other cables remain connected). 1. Count the number of connected components in the graph that is defining the computer network at that moment. 1. Re-connect the disconnected cables with indexes from *l**i* to *r**i* (that is, restore the initial network).
Help Polycarpus carry out all experiments and for each print the number of connected components in the graph that defines the computer network through the given experiment. Isolated vertex should be counted as single component.
Input Specification:
The first line contains two space-separated integers *n*, *m* (2<=≤<=*n*<=≤<=500; 1<=≤<=*m*<=≤<=104) — the number of computers and the number of cables, correspondingly.
The following *m* lines contain the cables' description. The *i*-th line contains space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*) — the numbers of the computers that are connected by the *i*-th cable. Note that a pair of computers can be connected by multiple cables.
The next line contains integer *k* (1<=≤<=*k*<=≤<=2·104) — the number of experiments. Next *k* lines contain the experiments' descriptions. The *i*-th line contains space-separated integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — the numbers of the cables that Polycarpus disconnects during the *i*-th experiment.
Output Specification:
Print *k* numbers, the *i*-th number represents the number of connected components of the graph that defines the computer network during the *i*-th experiment.
Demo Input:
['6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3\n']
Demo Output:
['4\n5\n6\n3\n4\n2\n']
Note:
none | ```python
print("_RANDOM_GUESS_1689286590.325384")# 1689286590.325404
``` | 0 |
|
409 | C | Magnum Opus | PROGRAMMING | 1,700 | [
"*special"
] | null | null | Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via.
Fac et spera,
Vale,
Nicolas Flamel | The first line of input contains several space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100). | Print a single integer. | [
"2 4 6 8 10\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "2 4 6 8 10",
"output": "1"
},
{
"input": "50 27 17 31 89",
"output": "4"
},
{
"input": "50 87 29 81 21",
"output": "5"
},
{
"input": "74 21 36 68 80",
"output": "9"
},
{
"input": "75 82 48 95 12",
"output": "3"
},
{
"input": "41 85 14 43 23",
"output": "5"
},
{
"input": "94 28 3 29 9",
"output": "1"
},
{
"input": "94 21 36 89 20",
"output": "5"
},
{
"input": "60 92 82 71 53",
"output": "10"
},
{
"input": "46 68 3 0 51",
"output": "0"
},
{
"input": "12 39 3 50 84",
"output": "1"
},
{
"input": "12 31 47 31 84",
"output": "4"
},
{
"input": "79 2 93 92 16",
"output": "2"
},
{
"input": "65 46 3 77 81",
"output": "1"
},
{
"input": "31 38 47 26 13",
"output": "3"
},
{
"input": "42 9 59 19 24",
"output": "2"
},
{
"input": "51 19 70 5 78",
"output": "0"
},
{
"input": "51 56 14 99 21",
"output": "5"
},
{
"input": "28 49 58 47 54",
"output": "6"
},
{
"input": "3 26 69 33 18",
"output": "3"
},
{
"input": "14 63 14 25 18",
"output": "3"
},
{
"input": "81 67 58 8 51",
"output": "1"
},
{
"input": "81 26 69 0 84",
"output": "0"
},
{
"input": "32 36 80 54 48",
"output": "7"
},
{
"input": "0 74 25 35 48",
"output": "0"
},
{
"input": "67 66 69 96 92",
"output": "13"
},
{
"input": "52 43 80 14 79",
"output": "2"
},
{
"input": "18 13 91 64 22",
"output": "5"
},
{
"input": "19 84 69 57 55",
"output": "8"
},
{
"input": "71 61 47 9 19",
"output": "1"
},
{
"input": "0 0 0 0 0",
"output": "0"
},
{
"input": "1 1 2 7 4",
"output": "1"
},
{
"input": "1 0 2 7 4",
"output": "0"
},
{
"input": "1 1 2 6 4",
"output": "0"
},
{
"input": "1 1 1 7 4",
"output": "0"
},
{
"input": "1 2 2 7 4",
"output": "1"
},
{
"input": "1 1 3 7 4",
"output": "1"
},
{
"input": "2 2 3 14 8",
"output": "1"
},
{
"input": "100 100 100 100 100",
"output": "14"
}
] | 1,666,265,897 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a=list(map(int,input().split()))
print(1)
| Title: Magnum Opus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via.
Fac et spera,
Vale,
Nicolas Flamel
Input Specification:
The first line of input contains several space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print a single integer.
Demo Input:
['2 4 6 8 10\n']
Demo Output:
['1\n']
Note:
none | ```python
a=list(map(int,input().split()))
print(1)
``` | 0 |
|
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output": "No"
},
{
"input": "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC",
"output": "No"
},
{
"input": "1\nC",
"output": "No"
},
{
"input": "1\n?",
"output": "Yes"
},
{
"input": "2\nMY",
"output": "No"
},
{
"input": "2\n?M",
"output": "Yes"
},
{
"input": "2\nY?",
"output": "Yes"
},
{
"input": "2\n??",
"output": "Yes"
},
{
"input": "3\n??C",
"output": "Yes"
},
{
"input": "3\nM??",
"output": "Yes"
},
{
"input": "3\nYCM",
"output": "No"
},
{
"input": "3\n?C?",
"output": "Yes"
},
{
"input": "3\nMC?",
"output": "Yes"
},
{
"input": "4\nCYCM",
"output": "No"
},
{
"input": "4\nM?CM",
"output": "No"
},
{
"input": "4\n??YM",
"output": "Yes"
},
{
"input": "4\nC???",
"output": "Yes"
},
{
"input": "10\nMCYM?MYM?C",
"output": "Yes"
},
{
"input": "50\nCMCMCYM?MY?C?MC??YM?CY?YM??M?MCMCYCYMCYCMCM?MCM?MC",
"output": "Yes"
},
{
"input": "97\nMCM?YCMYM?YMY?MY?MYCY?CMCMCYC?YMY?MYCMC?M?YCMC?YM?C?MCMCMYMCMY?MCM?YC?YMYMY?MYCYCM?YC?YCY?MYMYMYC",
"output": "No"
},
{
"input": "100\nC?M?M?M?YM??YMYC?MCYMYM??Y??YC?CYC???YM?YM??MYMY?CYCYMYC?YC?C?CYCMY??CMC?YMCMYCYCYMYM?CYM?M?MCMCMY?Y",
"output": "Yes"
},
{
"input": "100\n?YYYYYYYYYYYYYYYYYYYYYYYYYYYYY??YYY?YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?",
"output": "No"
},
{
"input": "100\n????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "Yes"
},
{
"input": "100\nY?CYMYMYMYCYMY?CMCYMYMC?MYCY?CMCYCYMCM?YCMCYMYCYCY?MYMYCYCYCM?CYMYMY?CY?MYCYCY?M?YMYCY?CMCMCY?CY?M?C",
"output": "No"
},
{
"input": "4\nM??C",
"output": "Yes"
},
{
"input": "6\nY?C??C",
"output": "Yes"
},
{
"input": "5\nC???Y",
"output": "Yes"
},
{
"input": "5\nC??MY",
"output": "Yes"
},
{
"input": "5\nCY??M",
"output": "Yes"
},
{
"input": "4\nC??Y",
"output": "Yes"
},
{
"input": "52\n??????????????????????????????????????????????????YY",
"output": "No"
},
{
"input": "3\nYY?",
"output": "No"
},
{
"input": "5\nCC??Y",
"output": "No"
},
{
"input": "8\nCMC??MCM",
"output": "Yes"
},
{
"input": "7\nM?YCM??",
"output": "Yes"
},
{
"input": "6\n?CC???",
"output": "No"
},
{
"input": "100\n??????????????????????????????????????????????????????????????????????????????????????????????????MM",
"output": "No"
},
{
"input": "4\nC??M",
"output": "Yes"
},
{
"input": "4\n?C?M",
"output": "Yes"
},
{
"input": "6\nMC??MC",
"output": "Yes"
}
] | 1,549,918,524 | 3,024 | PyPy 3 | OK | TESTS | 45 | 124 | 0 | n=int(input())
s=list(input())
if s.count("?")==0:
print("No")
exit(0)
f=0
a=s[0]
for i in range(1,n):
if s[i]==s[i-1] and s[i]!="?":
f=1
print("No")
exit(0)
s=["*"]+s+["&"]
#print(s)
y=list("CMY")
#print(y)
for i in range(1,n+1):
g=0
if (s[i-1] in y) and (s[i+1] in y):
g=1
if (s[i]=="?" and s[i-1]==s[i+1] and g==1) or (g==0 and s[i]=="?"):
print("Yes")
exit(0)
#print(i,s[i-1],s[i],s[i+1],g)
print("No") | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
Output Specification:
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Demo Input:
['5\nCY??Y\n', '5\nC?C?Y\n', '5\n?CYC?\n', '5\nC??MM\n', '3\nMMY\n']
Demo Output:
['Yes\n', 'Yes\n', 'Yes\n', 'No\n', 'No\n']
Note:
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | ```python
n=int(input())
s=list(input())
if s.count("?")==0:
print("No")
exit(0)
f=0
a=s[0]
for i in range(1,n):
if s[i]==s[i-1] and s[i]!="?":
f=1
print("No")
exit(0)
s=["*"]+s+["&"]
#print(s)
y=list("CMY")
#print(y)
for i in range(1,n+1):
g=0
if (s[i-1] in y) and (s[i+1] in y):
g=1
if (s[i]=="?" and s[i-1]==s[i+1] and g==1) or (g==0 and s[i]=="?"):
print("Yes")
exit(0)
#print(i,s[i-1],s[i],s[i+1],g)
print("No")
``` | 3 |
|
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,666,003,192 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 409,600 | import io
import sys
import csv
from PyQt5 import uic
from PyQt5.QtWidgets import *
tmp = '''<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>564</width>
<height>455</height>
</rect>
</property>
<property name="windowTitle">
<string>Интерактивный чек</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTableWidget" name="tableWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>541</width>
<height>391</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>250</x>
<y>410</y>
<width>291</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>200</x>
<y>410</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Итого :</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>
'''
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
f = io.StringIO(tmp)
uic.loadUi(f, self)
self.load_table()
def load_table(self):
with open('price.csv', encoding='utf-8') as csvFile:
reader = csv.reader(csvFile, delimiter=';', quotechar='"')
title = next(reader)
title += ['Количество']
self.tableWidget.setColumnCount(len(title))
self.tableWidget.setHorizontalHeaderLabels(title)
self.tableWidget.setRowCount(0)
for i, row in enumerate(reader):
self.tableWidget.setRowCount(self.tableWidget.rowCount() + 1)
for j, elem in enumerate(row):
if not j:
elem += ' ' * 70
self.tableWidget.setItem(i, j, QTableWidgetItem(elem))
self.tableWidget.setItem(i, j + 1, QTableWidgetItem('0'))
self.tableWidget.resizeColumnsToContents()
self.tableWidget.itemChanged.connect(self.operations)
def operations(self):
try:
result = 0
for i in range(self.tableWidget.rowCount()):
value = self.tableWidget.item(i, 2).text()
if int(value) >= 1:
result += int(value) * int(self.tableWidget.item(i, 1).text())
self.lineEdit.setText(str(result))
except:
self.lineEdit.setText('Ошибка')
if __name__ == '__main__':
app = QApplication(sys.argv)
wnd = Window()
wnd.show()
sys.exit(app.exec())
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
import io
import sys
import csv
from PyQt5 import uic
from PyQt5.QtWidgets import *
tmp = '''<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>564</width>
<height>455</height>
</rect>
</property>
<property name="windowTitle">
<string>Интерактивный чек</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTableWidget" name="tableWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>541</width>
<height>391</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>250</x>
<y>410</y>
<width>291</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>200</x>
<y>410</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Итого :</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>
'''
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
f = io.StringIO(tmp)
uic.loadUi(f, self)
self.load_table()
def load_table(self):
with open('price.csv', encoding='utf-8') as csvFile:
reader = csv.reader(csvFile, delimiter=';', quotechar='"')
title = next(reader)
title += ['Количество']
self.tableWidget.setColumnCount(len(title))
self.tableWidget.setHorizontalHeaderLabels(title)
self.tableWidget.setRowCount(0)
for i, row in enumerate(reader):
self.tableWidget.setRowCount(self.tableWidget.rowCount() + 1)
for j, elem in enumerate(row):
if not j:
elem += ' ' * 70
self.tableWidget.setItem(i, j, QTableWidgetItem(elem))
self.tableWidget.setItem(i, j + 1, QTableWidgetItem('0'))
self.tableWidget.resizeColumnsToContents()
self.tableWidget.itemChanged.connect(self.operations)
def operations(self):
try:
result = 0
for i in range(self.tableWidget.rowCount()):
value = self.tableWidget.item(i, 2).text()
if int(value) >= 1:
result += int(value) * int(self.tableWidget.item(i, 1).text())
self.lineEdit.setText(str(result))
except:
self.lineEdit.setText('Ошибка')
if __name__ == '__main__':
app = QApplication(sys.argv)
wnd = Window()
wnd.show()
sys.exit(app.exec())
``` | -1 |
|
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,697,444,390 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x,y = map(int, input().split())
print(x,y)
z = list(map(int,input().split()))
print(y)
counter = 0
for i in z:
if y >= i :
counter = counter + 1
else : counter = counter +2
print (counter)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | ```python
x,y = map(int, input().split())
print(x,y)
z = list(map(int,input().split()))
print(y)
counter = 0
for i in z:
if y >= i :
counter = counter + 1
else : counter = counter +2
print (counter)
``` | 0 |
|
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,688,568,890 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | l,r=list(map(int,input().split()))
if abs(l-r)<2:
l=-1
elif (l%2!=0):
l=l+1
elif r%2!=0:
r=r-1
if l==-1:
print(-1)
else:
print(l,l+1,l+2) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
l,r=list(map(int,input().split()))
if abs(l-r)<2:
l=-1
elif (l%2!=0):
l=l+1
elif r%2!=0:
r=r-1
if l==-1:
print(-1)
else:
print(l,l+1,l+2)
``` | 0 |
|
340 | C | Tourist Problem | PROGRAMMING | 1,600 | [
"combinatorics",
"implementation",
"math"
] | null | null | Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a**k* represents that the *k*th destination is at distance *a**k* kilometers from the starting point. No two destinations are located in the same place.
Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination.
The distance between destination located at kilometer *x* and next destination, located at kilometer *y*, is |*x*<=-<=*y*| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all *n* destinations and he doesn't visit a destination more than once.
Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him. | The first line contains integer *n* (2<=≤<=*n*<=≤<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107). | Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible. | [
"3\n2 3 5\n"
] | [
"22 3"
] | Consider 6 possible routes:
- [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; - [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; - [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; - [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; - [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; - [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3| = 8.
The average travel distance is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/29119d3733c79f70eb2d77186ac1606bf938508a.png" style="max-width: 100.0%;max-height: 100.0%;"/> = <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ee9d5516ed2ca1d2b65ed21f8a64f58f94954c30.png" style="max-width: 100.0%;max-height: 100.0%;"/> = <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ed5cc8cb7dd43cfb27f2459586062538e44de7bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 2,000 | [
{
"input": "3\n2 3 5",
"output": "22 3"
},
{
"input": "4\n1 5 77 2",
"output": "547 4"
},
{
"input": "5\n3 3842 288 199 334",
"output": "35918 5"
},
{
"input": "7\n1 2 3 40 52 33 86",
"output": "255 1"
},
{
"input": "7\n1 10 100 1000 10000 1000000 10000000",
"output": "139050619 7"
},
{
"input": "6\n3835302 971984 8706888 1080445 2224695 1093317",
"output": "114053569 6"
},
{
"input": "40\n8995197 7520501 942559 8012058 3749344 3471059 9817796 3187774 4735591 6477783 7024598 3155420 6039802 2879311 2738670 5930138 4604402 7772492 6089337 317953 4598621 6924769 455347 4360383 1441848 9189601 1838826 5027295 9248947 7562916 8341568 4690450 6877041 507074 2390889 8405736 4562116 2755285 3032168 7770391",
"output": "644565018 5"
},
{
"input": "50\n3987477 8934938 4067156 6712855 7269334 5039822 9533601 9335400 5992073 2619268 438734 8620973 4347619 4307947 2249161 815221 7615258 8244100 8341666 5908546 6646952 4812769 6215114 7479369 6290438 5623785 6466133 9953199 3525873 4326034 3510072 8117068 2342953 1717542 9766539 651627 9541804 4518782 7049159 1159304 2892927 8106441 2222088 8240016 6058981 3924422 743755 4621476 1600677 4234884",
"output": "812321046 5"
},
{
"input": "2\n5555 1242323",
"output": "1860707 1"
},
{
"input": "3\n233232 24332 9010101",
"output": "15070247 1"
},
{
"input": "3\n4054378 7133183 7979825",
"output": "11623058 1"
},
{
"input": "3\n4663018 4080080 6848370",
"output": "26664628 3"
},
{
"input": "4\n5997728 7557181 7228856 8086019",
"output": "10514045 1"
},
{
"input": "4\n2895920 1685207 308573 3045658",
"output": "13389647 2"
},
{
"input": "5\n1789943 1662788 8254265 2248046 2588605",
"output": "72470111 5"
},
{
"input": "5\n6667561 1662704 5626810 4453455 7011856",
"output": "77072026 5"
}
] | 1,588,971,684 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 436 | 14,643,200 | from math import *
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
S1=sum(arr)
sums=0
sumsi=arr[0]
for i in range(1,n):
sums+=(i)*(arr[i])-sumsi
sumsi+=arr[i]
S2=sums
num=S1+2*S2
den=n
#print(num,den)
while(int(gcd(num,den))!=1):
x=gcd(num,den)
num=num//x
den=den//x
print(int(num),int(den))
| Title: Tourist Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a**k* represents that the *k*th destination is at distance *a**k* kilometers from the starting point. No two destinations are located in the same place.
Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination.
The distance between destination located at kilometer *x* and next destination, located at kilometer *y*, is |*x*<=-<=*y*| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all *n* destinations and he doesn't visit a destination more than once.
Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107).
Output Specification:
Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.
Demo Input:
['3\n2 3 5\n']
Demo Output:
['22 3']
Note:
Consider 6 possible routes:
- [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; - [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; - [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; - [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; - [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; - [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3| = 8.
The average travel distance is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/29119d3733c79f70eb2d77186ac1606bf938508a.png" style="max-width: 100.0%;max-height: 100.0%;"/> = <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ee9d5516ed2ca1d2b65ed21f8a64f58f94954c30.png" style="max-width: 100.0%;max-height: 100.0%;"/> = <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ed5cc8cb7dd43cfb27f2459586062538e44de7bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
from math import *
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
S1=sum(arr)
sums=0
sumsi=arr[0]
for i in range(1,n):
sums+=(i)*(arr[i])-sumsi
sumsi+=arr[i]
S2=sums
num=S1+2*S2
den=n
#print(num,den)
while(int(gcd(num,den))!=1):
x=gcd(num,den)
num=num//x
den=den//x
print(int(num),int(den))
``` | 3 |
|
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,621,705,215 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | x=list(map(int, input().split()))
a=x[0]
b=x[1]
c=x[2]
d=x[3]
p1=max(3*a/10,a-a/250*c)
p2=max(3*b/10,b-b/250*d)
if p1>p2:
print("Misha")
elif p2>p1:
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
x=list(map(int, input().split()))
a=x[0]
b=x[1]
c=x[2]
d=x[3]
p1=max(3*a/10,a-a/250*c)
p2=max(3*b/10,b-b/250*d)
if p1>p2:
print("Misha")
elif p2>p1:
print("Vasya")
else:
print("Tie")
``` | 3 |
|
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii". | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
"input": "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa",
"output": "0"
},
{
"input": "3\nxxx",
"output": "1"
},
{
"input": "77\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz",
"output": "0"
},
{
"input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx",
"output": "41"
},
{
"input": "100\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc",
"output": "49"
},
{
"input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx",
"output": "41"
},
{
"input": "34\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "5\nfcyju",
"output": "0"
},
{
"input": "100\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx",
"output": "2"
}
] | 1,694,755,947 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | size=int(input())
s=input()
count,remove=0,0
for i in s:
if i=='x':
count+=1
if count>2:
remove+=1
else:
break
if remove == 0:
print(0)
else:
print(remove)
| Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii".
Input Specification:
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Output Specification:
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
Demo Input:
['6\nxxxiii\n', '5\nxxoxx\n', '10\nxxxxxxxxxx\n']
Demo Output:
['1\n', '0\n', '8\n']
Note:
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | ```python
size=int(input())
s=input()
count,remove=0,0
for i in s:
if i=='x':
count+=1
if count>2:
remove+=1
else:
break
if remove == 0:
print(0)
else:
print(remove)
``` | 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,600,173,144 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 109 | 0 | import math
n,t,k,d = input().split()
n,t,k,d = int(n), int(t), int(k), int(d)
t1,t2 = 0,d
use = math.ceil(n/k)
for i in range(use):
if t1 <= t2: t1+=t
else: t2+=t
if int(max(t1,t2)) >= use*t:
print("NO")
else:
print("YES") | 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
import math
n,t,k,d = input().split()
n,t,k,d = int(n), int(t), int(k), int(d)
t1,t2 = 0,d
use = math.ceil(n/k)
for i in range(use):
if t1 <= t2: t1+=t
else: t2+=t
if int(max(t1,t2)) >= use*t:
print("NO")
else:
print("YES")
``` | 3 |
|
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 1,689,661,789 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | a=list(map(int,input().split()))
b=[]
d=[]
for i in a:
if i not in b:
b.append(i)
for i in b:
c=a.count(i)
d.append(c)
print(max(d)-1)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
Input Specification:
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
Output Specification:
Print a single integer — the minimum number of horseshoes Valera needs to buy.
Demo Input:
['1 7 3 3\n', '7 7 7 7\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
a=list(map(int,input().split()))
b=[]
d=[]
for i in a:
if i not in b:
b.append(i)
for i in b:
c=a.count(i)
d.append(c)
print(max(d)-1)
``` | 0 |
|
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 1,585,421,513 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 280 | 0 | n = int(input())
s = ["c", "bi", "ba"]
d = {}
ans = [0, 0, 0]
for ind, i in enumerate(map(int, input().split())):
d.setdefault(s[(ind % 3)], [0])[0] += i
for i in d:
if i == 'c':
ans[0] = d[i][0]
elif i == 'bi':
ans[1] = d[i][0]
else:
ans[2] = d[i][0]
if ans[0] > ans[1] and ans[0] > ans[2]:
print("chest")
elif ans[1] > ans[0] and ans[1] > ans[2]:
print("biceps")
else:
print("back")
| Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Output Specification:
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Demo Input:
['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n']
Demo Output:
['biceps\n', 'back\n', 'chest\n']
Note:
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | ```python
n = int(input())
s = ["c", "bi", "ba"]
d = {}
ans = [0, 0, 0]
for ind, i in enumerate(map(int, input().split())):
d.setdefault(s[(ind % 3)], [0])[0] += i
for i in d:
if i == 'c':
ans[0] = d[i][0]
elif i == 'bi':
ans[1] = d[i][0]
else:
ans[2] = d[i][0]
if ans[0] > ans[1] and ans[0] > ans[2]:
print("chest")
elif ans[1] > ans[0] and ans[1] > ans[2]:
print("biceps")
else:
print("back")
``` | 3 |
|
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*. | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces. | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1",
"output": "6"
},
{
"input": "15\n0 0\n0 0\n0 0\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": "5\n1 0\n1 0\n1 0\n0 1\n0 1",
"output": "4"
}
] | 1,626,606,990 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,758,400 | n=int(input())
l=[]
for i in range(0,n):
l.append([int(i) for i in input().split()])
scol=list(map(sum,zip(*l)))
print(n-max(scol)+min(scol)) | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
Input Specification:
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
Output Specification:
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Demo Input:
['5\n0 1\n1 0\n0 1\n1 1\n0 1\n']
Demo Output:
['3\n']
Note:
none | ```python
n=int(input())
l=[]
for i in range(0,n):
l.append([int(i) for i in input().split()])
scol=list(map(sum,zip(*l)))
print(n-max(scol)+min(scol))
``` | 0 |
|
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
The second sample case is described in the statement. | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111",
"output": "321"
},
{
"input": "1110010001000101001011111\n00011011000000100001010000010100110011010001111010",
"output": "316"
}
] | 1,605,367,495 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 921,600 | def sub(a, b):
sum = 0
for i in range(len(a)):
c = int(a[i])-int(b[i])
if c < 0:
c = -c
sum += c
return sum
pattern = input()
string = input()
sumt = 0
for i in range(len(string) - len(pattern) + 1):
sumt += sub(pattern, string[i:i+len(pattern)])
print(sumt)
| Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
Input Specification:
The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only.
Output Specification:
Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
Demo Input:
['01\n00111\n', '0011\n0110\n']
Demo Output:
['3\n', '2\n']
Note:
For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
The second sample case is described in the statement. | ```python
def sub(a, b):
sum = 0
for i in range(len(a)):
c = int(a[i])-int(b[i])
if c < 0:
c = -c
sum += c
return sum
pattern = input()
string = input()
sumt = 0
for i in range(len(string) - len(pattern) + 1):
sumt += sub(pattern, string[i:i+len(pattern)])
print(sumt)
``` | 0 |
|
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 1,649,882,702 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 102,400 | from collections import Counter
input()
print(max(Counter(list(map(int, input().split()))).values()))
| Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Output Specification:
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Demo Input:
['6\n1 2 4 3 3 2\n', '1\n100\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
from collections import Counter
input()
print(max(Counter(list(map(int, input().split()))).values()))
``` | 3 |
|
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1"
},
{
"input": "FSFlNEelYY",
"output": "3"
},
{
"input": "lgtyasficu",
"output": "0"
},
{
"input": "WYKUDTDDBT",
"output": "0"
},
{
"input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd",
"output": "0"
},
{
"input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu",
"output": "43"
},
{
"input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR",
"output": "13"
},
{
"input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi",
"output": "27"
},
{
"input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn",
"output": "31"
}
] | 1,685,453,399 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 186 | 2,662,400 | def min_count(q: str) -> int:
w = len(q)
lower = [0] * (w + 1)
upper = [0] * (w + 1)
for n in range(1, w + 1):
lower[n] = lower[n - 1] + q[n - 1].islower()
upper[n] = upper[n - 1] + q[n - 1].isupper()
ans = float('inf')
for n in range(w + 1):
ans = min(ans, lower[n] + upper[w] - upper[n])
return ans
a = input()
print(min_count(a))
| Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
Input Specification:
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Output Specification:
Print a single number — the least number of actions needed to make the message fancy.
Demo Input:
['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n']
Demo Output:
['5\n', '0\n', '0\n']
Note:
none | ```python
def min_count(q: str) -> int:
w = len(q)
lower = [0] * (w + 1)
upper = [0] * (w + 1)
for n in range(1, w + 1):
lower[n] = lower[n - 1] + q[n - 1].islower()
upper[n] = upper[n - 1] + q[n - 1].isupper()
ans = float('inf')
for n in range(w + 1):
ans = min(ans, lower[n] + upper[w] - upper[n])
return ans
a = input()
print(min_count(a))
``` | 3 |
|
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,623,955,519 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | chat = input()
chat = list(chat)
chat = sorted(set(chat), key=chat.index)
new_string = ''
for x in chat:
if x == 'h' or x == 'e' or x == 'l' or x == 'o':
new_string+=x
if(new_string == 'helo'):
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
chat = input()
chat = list(chat)
chat = sorted(set(chat), key=chat.index)
new_string = ''
for x in chat:
if x == 'h' or x == 'e' or x == 'l' or x == 'o':
new_string+=x
if(new_string == 'helo'):
print("YES")
else:
print("NO")
``` | 0 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,635,785,666 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 4,505,600 | y,w=list(map(int,input().split()))
if max(y,w)==6:
print("1/6")
elif max(y,w)==1:
print("1/1")
elif max(y,w)==2:
print("5/6")
elif max(y,w)==3:
print("2/3")
elif max(y,w)==4:
print("1/2")
elif max(y,w)==5:
print("1/6") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
y,w=list(map(int,input().split()))
if max(y,w)==6:
print("1/6")
elif max(y,w)==1:
print("1/1")
elif max(y,w)==2:
print("5/6")
elif max(y,w)==3:
print("2/3")
elif max(y,w)==4:
print("1/2")
elif max(y,w)==5:
print("1/6")
``` | 0 |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'. | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 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 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 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": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 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 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "0"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\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": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,585,829,803 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 0 | n, m = [int(x) for x in input().split()]
acc = 0
while n:
n = n - 1
a_i = [int(x) for x in input().split()]
for i in range(0, 2*m, 2):
if (a_i[i] == 1) or (a_i[i+1] == 1):
acc = acc + 1
print(acc)
| Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Output Specification:
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Demo Input:
['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n']
Demo Output:
['3\n', '2\n']
Note:
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | ```python
n, m = [int(x) for x in input().split()]
acc = 0
while n:
n = n - 1
a_i = [int(x) for x in input().split()]
for i in range(0, 2*m, 2):
if (a_i[i] == 1) or (a_i[i+1] == 1):
acc = acc + 1
print(acc)
``` | 3 |
|
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe from the left is called safe *i*. There are *n* banknotes left in all the safes in total. The *i*-th banknote is in safe *x**i*. Oleg is now at safe *a*. There are two security guards, one of which guards the safe *b* such that *b*<=<<=*a*, i.e. the first guard is to the left of Oleg. The other guard guards the safe *c* so that *c*<=><=*a*, i.e. he is to the right of Oleg.
The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather. | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of banknotes.
The next line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109), denoting that the *i*-th banknote is located in the *x**i*-th safe. Note that *x**i* are not guaranteed to be distinct. | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.
For the second sample, Oleg can't take any banknotes without bumping into any of the security guards. | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output": "0"
},
{
"input": "3 2 5\n4\n1 3 4 5",
"output": "2"
},
{
"input": "3 2 4\n1\n1",
"output": "0"
},
{
"input": "6 4 8\n1\n4",
"output": "0"
},
{
"input": "2 1 3\n1\n3",
"output": "0"
}
] | 1,593,068,507 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 15,360,000 | def solution(l1,v2,l3):
oleg = l1[0]
l1.remove(oleg)
security1 = min(l1)
security2 = max(l1)
ans=0
if oleg<security1:
i=1
while i<security1:
for x in l3:
if i==x:
ans+=1
i+=1
elif oleg>security1 and oleg<security2:
i=security1+1
while i<security2:
for x in l3:
if i==x:
ans+=1
i+=1
else:
i=security2+1
while i<v2:
for x in l3:
if i==x:
ans+=1
i+=1
return ans
def answer():
l1 = [ int(x) for x in input().split() ]
v2 = int(input())
l3 = [ int(x) for x in input().split() ]
print(solution(l1,v2,l3))
answer() | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe from the left is called safe *i*. There are *n* banknotes left in all the safes in total. The *i*-th banknote is in safe *x**i*. Oleg is now at safe *a*. There are two security guards, one of which guards the safe *b* such that *b*<=<<=*a*, i.e. the first guard is to the left of Oleg. The other guard guards the safe *c* so that *c*<=><=*a*, i.e. he is to the right of Oleg.
The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather.
Input Specification:
The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of banknotes.
The next line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109), denoting that the *i*-th banknote is located in the *x**i*-th safe. Note that *x**i* are not guaranteed to be distinct.
Output Specification:
Output a single integer: the maximum number of banknotes Oleg can take.
Demo Input:
['5 3 7\n8\n4 7 5 5 3 6 2 8\n', '6 5 7\n5\n1 5 7 92 3\n']
Demo Output:
['4\n', '0\n']
Note:
In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.
For the second sample, Oleg can't take any banknotes without bumping into any of the security guards. | ```python
def solution(l1,v2,l3):
oleg = l1[0]
l1.remove(oleg)
security1 = min(l1)
security2 = max(l1)
ans=0
if oleg<security1:
i=1
while i<security1:
for x in l3:
if i==x:
ans+=1
i+=1
elif oleg>security1 and oleg<security2:
i=security1+1
while i<security2:
for x in l3:
if i==x:
ans+=1
i+=1
else:
i=security2+1
while i<v2:
for x in l3:
if i==x:
ans+=1
i+=1
return ans
def answer():
l1 = [ int(x) for x in input().split() ]
v2 = int(input())
l3 = [ int(x) for x in input().split() ]
print(solution(l1,v2,l3))
answer()
``` | 0 |
|
76 | E | Points | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | E. Points | 1 | 256 | You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. | The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide. | The only line of output should contain the required sum of squares of distances between all pairs of points. | [
"4\n1 1\n-1 -1\n1 -1\n-1 1\n"
] | [
"32\n"
] | none | 0 | [
{
"input": "4\n1 1\n-1 -1\n1 -1\n-1 1",
"output": "32"
},
{
"input": "1\n6 3",
"output": "0"
},
{
"input": "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1\n-13 -9\n13 17\n-14 -8\n2 5\n18 5",
"output": "265705"
}
] | 1,645,805,099 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 528 | 0 | """**************************************************************\
BISMILLAHIR RAHMANIR RAHIM
****************************************************************
AUTHOR NAME: MD. TAHURUZZOHA TUHIN
\**************************************************************"""
T = int(input())
x = 0
y = 0
s = 0
sx = 0
sy = 0
for _ in range(T):
# n = int(input())
x,y = [int(x) for x in input().split(' ')]
s+=(x*x+y*y)
sx+=x
sy+=y
print(s*T-(sx*sx+sy*sy)) | Title: Points
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points.
Input Specification:
The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide.
Output Specification:
The only line of output should contain the required sum of squares of distances between all pairs of points.
Demo Input:
['4\n1 1\n-1 -1\n1 -1\n-1 1\n']
Demo Output:
['32\n']
Note:
none | ```python
"""**************************************************************\
BISMILLAHIR RAHMANIR RAHIM
****************************************************************
AUTHOR NAME: MD. TAHURUZZOHA TUHIN
\**************************************************************"""
T = int(input())
x = 0
y = 0
s = 0
sx = 0
sy = 0
for _ in range(T):
# n = int(input())
x,y = [int(x) for x in input().split(' ')]
s+=(x*x+y*y)
sx+=x
sy+=y
print(s*T-(sx*sx+sy*sy))
``` | 3.736 |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected? | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428",
"output": "25720377\n661369649"
},
{
"input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482",
"output": "819602309\n796067435"
},
{
"input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780",
"output": "374054998\n902899520"
},
{
"input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990",
"output": "939116221\n323703261"
},
{
"input": "3\n77 77 77\n77 77\n77",
"output": "77\n77"
},
{
"input": "3\n84 30 9\n9 84\n9",
"output": "30\n84"
},
{
"input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3",
"output": "5\n5"
},
{
"input": "4\n1 5 7 8\n1 5 7\n1 5",
"output": "8\n7"
}
] | 1,671,955,504 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n=int(input())
ll=list(map(int,input().split()))
kk=list(map(int,input().split()))
tt=list(map(int,input().split()))
for i in tt:
ll.remove(i)
if ll[0] in kk:
print(ll[1])
print(ll[0])
else:
print(ll[0])
print(ll[1]) | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output Specification:
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Demo Input:
['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n']
Demo Output:
['8\n123\n', '1\n3\n']
Note:
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | ```python
n=int(input())
ll=list(map(int,input().split()))
kk=list(map(int,input().split()))
tt=list(map(int,input().split()))
for i in tt:
ll.remove(i)
if ll[0] in kk:
print(ll[1])
print(ll[0])
else:
print(ll[0])
print(ll[1])
``` | 0 |
|
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).
The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on.
Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5. | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903",
"output": "13"
},
{
"input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94",
"output": "3"
},
{
"input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190",
"output": "31"
},
{
"input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997",
"output": "0"
},
{
"input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176",
"output": "412"
},
{
"input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886",
"output": "938"
},
{
"input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993",
"output": "937"
},
{
"input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7",
"output": "0"
},
{
"input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19",
"output": "12"
},
{
"input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "0"
},
{
"input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17",
"output": "31"
},
{
"input": "2 2\n1000 4",
"output": "996"
},
{
"input": "2 3\n4 502 1000",
"output": "498"
},
{
"input": "3 3\n4 1000 4",
"output": "996"
}
] | 1,681,994,501 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 124 | 0 | n, m = map(int, input().split())
puzzles = sorted(list(map(int, input().split())))
min_diff = float('inf')
diff = 0
for a, _ in enumerate(range(m - n + 1 )):
diff = puzzles[n-1] - puzzles[a]
min_diff = min(min_diff, diff)
# print(diff)
n+=1
min_diff = min(min_diff, diff)
print(min_diff)
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).
The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on.
Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
Input Specification:
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Output Specification:
Print a single integer — the least possible difference the teacher can obtain.
Demo Input:
['4 6\n10 12 10 7 5 22\n']
Demo Output:
['5\n']
Note:
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5. | ```python
n, m = map(int, input().split())
puzzles = sorted(list(map(int, input().split())))
min_diff = float('inf')
diff = 0
for a, _ in enumerate(range(m - n + 1 )):
diff = puzzles[n-1] - puzzles[a]
min_diff = min(min_diff, diff)
# print(diff)
n+=1
min_diff = min(min_diff, diff)
print(min_diff)
``` | 3 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,688,201,679 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | x,y,z=map(int,input().strip().split())
print(z) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
x,y,z=map(int,input().strip().split())
print(z)
``` | 0 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,606,209,008 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,k = map(int,raw_input().split())
L = map(int,raw_input().split())
temp = L[k-1]
count=0
for i in range(0,len(L)):
if L[i]>=temp and L[i]>0 :
count+=1
print count | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n,k = map(int,raw_input().split())
L = map(int,raw_input().split())
temp = L[k-1]
count=0
for i in range(0,len(L)):
if L[i]>=temp and L[i]>0 :
count+=1
print count
``` | -1 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,696,795,227 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n=int(input(""))
while not(1<=n<=1000):
n=int(input(""))
l=[4,7,47,74,477,447,444,44,77,777,774,744,474]
p=len(l)
i=0
test=False
while not test and i<p:
if n%l[i]==0:
test=True
else:
i+=1
if test:
print("YES")
else:
print("NO")
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
n=int(input(""))
while not(1<=n<=1000):
n=int(input(""))
l=[4,7,47,74,477,447,444,44,77,777,774,744,474]
p=len(l)
i=0
test=False
while not test and i<p:
if n%l[i]==0:
test=True
else:
i+=1
if test:
print("YES")
else:
print("NO")
``` | 3 |
|
997 | A | Convert to Ones | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones? | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones. | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | 500 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
{
"input": "1 314253869 261764879\n0",
"output": "261764879"
},
{
"input": "1 491511050 399084767\n1",
"output": "0"
},
{
"input": "2 163093925 214567542\n00",
"output": "214567542"
},
{
"input": "2 340351106 646854722\n10",
"output": "646854722"
},
{
"input": "2 222640995 489207317\n01",
"output": "489207317"
},
{
"input": "2 399898176 552898277\n11",
"output": "0"
},
{
"input": "2 690218164 577155357\n00",
"output": "577155357"
},
{
"input": "2 827538051 754412538\n10",
"output": "754412538"
},
{
"input": "2 636702427 259825230\n01",
"output": "259825230"
},
{
"input": "2 108926899 102177825\n11",
"output": "0"
},
{
"input": "3 368381052 440077270\n000",
"output": "440077270"
},
{
"input": "3 505700940 617334451\n100",
"output": "617334451"
},
{
"input": "3 499624340 643020827\n010",
"output": "1142645167"
},
{
"input": "3 75308005 971848814\n110",
"output": "971848814"
},
{
"input": "3 212627893 854138703\n001",
"output": "854138703"
},
{
"input": "3 31395883 981351561\n101",
"output": "981351561"
},
{
"input": "3 118671447 913685773\n011",
"output": "913685773"
},
{
"input": "3 255991335 385910245\n111",
"output": "0"
},
{
"input": "3 688278514 268200134\n000",
"output": "268200134"
},
{
"input": "3 825598402 445457315\n100",
"output": "445457315"
},
{
"input": "3 300751942 45676507\n010",
"output": "91353014"
},
{
"input": "3 517900980 438071829\n110",
"output": "438071829"
},
{
"input": "3 400190869 280424424\n001",
"output": "280424424"
},
{
"input": "3 577448050 344115384\n101",
"output": "344115384"
},
{
"input": "3 481435271 459737939\n011",
"output": "459737939"
},
{
"input": "3 931962412 913722450\n111",
"output": "0"
},
{
"input": "4 522194562 717060616\n0000",
"output": "717060616"
},
{
"input": "4 659514449 894317797\n1000",
"output": "894317797"
},
{
"input": "4 71574977 796834337\n0100",
"output": "868409314"
},
{
"input": "4 248832158 934154224\n1100",
"output": "934154224"
},
{
"input": "4 71474110 131122047\n0010",
"output": "202596157"
},
{
"input": "4 308379228 503761290\n1010",
"output": "812140518"
},
{
"input": "4 272484957 485636409\n0110",
"output": "758121366"
},
{
"input": "4 662893590 704772137\n1110",
"output": "704772137"
},
{
"input": "4 545183479 547124732\n0001",
"output": "547124732"
},
{
"input": "4 684444619 722440661\n1001",
"output": "722440661"
},
{
"input": "4 477963686 636258459\n0101",
"output": "1114222145"
},
{
"input": "4 360253575 773578347\n1101",
"output": "773578347"
},
{
"input": "4 832478048 910898234\n0011",
"output": "910898234"
},
{
"input": "4 343185412 714767937\n1011",
"output": "714767937"
},
{
"input": "4 480505300 892025118\n0111",
"output": "892025118"
},
{
"input": "4 322857895 774315007\n1111",
"output": "0"
},
{
"input": "4 386548854 246539479\n0000",
"output": "246539479"
},
{
"input": "4 523868742 128829368\n1000",
"output": "128829368"
},
{
"input": "4 956155921 11119257\n0100",
"output": "22238514"
},
{
"input": "4 188376438 93475808\n1100",
"output": "93475808"
},
{
"input": "4 754947032 158668188\n0010",
"output": "317336376"
},
{
"input": "4 927391856 637236921\n1010",
"output": "1274473842"
},
{
"input": "4 359679035 109461393\n0110",
"output": "218922786"
},
{
"input": "4 991751283 202031630\n1110",
"output": "202031630"
},
{
"input": "4 339351517 169008463\n0001",
"output": "169008463"
},
{
"input": "4 771638697 346265644\n1001",
"output": "346265644"
},
{
"input": "4 908958584 523522825\n0101",
"output": "1047045650"
},
{
"input": "4 677682252 405812714\n1101",
"output": "405812714"
},
{
"input": "4 815002139 288102603\n0011",
"output": "288102603"
},
{
"input": "4 952322026 760327076\n1011",
"output": "760327076"
},
{
"input": "4 663334158 312481698\n0111",
"output": "312481698"
},
{
"input": "4 840591339 154834293\n1111",
"output": "0"
},
{
"input": "14 3 11\n10110100011001",
"output": "20"
},
{
"input": "19 1 1\n1010101010101010101",
"output": "9"
},
{
"input": "1 10 1\n1",
"output": "0"
},
{
"input": "1 100 1\n1",
"output": "0"
},
{
"input": "5 1000 1\n11111",
"output": "0"
},
{
"input": "5 10 1\n11111",
"output": "0"
},
{
"input": "7 3 2\n1111111",
"output": "0"
},
{
"input": "5 1 10\n10101",
"output": "11"
},
{
"input": "1 3 2\n1",
"output": "0"
},
{
"input": "2 10 1\n11",
"output": "0"
},
{
"input": "4 148823922 302792601\n1010",
"output": "451616523"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "5 2 3\n00011",
"output": "3"
},
{
"input": "1 5 0\n1",
"output": "0"
},
{
"input": "7 2 3\n1001001",
"output": "5"
},
{
"input": "10 1 1000000000\n1111010111",
"output": "1000000001"
},
{
"input": "25 999999998 999999999\n1011001110101010100111001",
"output": "7999999985"
},
{
"input": "2 0 1\n00",
"output": "1"
},
{
"input": "2 1 100\n10",
"output": "100"
},
{
"input": "7 20 3\n1111111",
"output": "0"
},
{
"input": "1 1 0\n1",
"output": "0"
},
{
"input": "3 1 10\n010",
"output": "11"
},
{
"input": "2 1 0\n11",
"output": "0"
},
{
"input": "7 100 3\n1111111",
"output": "0"
},
{
"input": "5 1 1000\n10101",
"output": "1001"
},
{
"input": "5 2 1\n11111",
"output": "0"
},
{
"input": "1 1000 1\n1",
"output": "0"
},
{
"input": "1 799543940 488239239\n1",
"output": "0"
},
{
"input": "6 1 1000\n010101",
"output": "1002"
},
{
"input": "5 11 1\n11111",
"output": "0"
},
{
"input": "5 2 3\n10101",
"output": "5"
},
{
"input": "3 10 1\n111",
"output": "0"
},
{
"input": "7 9 10\n1001011",
"output": "19"
},
{
"input": "5 5 6\n10101",
"output": "11"
},
{
"input": "1 1000000000 0\n1",
"output": "0"
},
{
"input": "4 0 1\n0101",
"output": "1"
},
{
"input": "8 2 3\n10101010",
"output": "9"
},
{
"input": "6 3 100\n010101",
"output": "106"
},
{
"input": "3 3 2\n111",
"output": "0"
},
{
"input": "1 20 1\n1",
"output": "0"
},
{
"input": "2 1 2\n01",
"output": "2"
}
] | 1,643,166,736 | 2,147,483,647 | Python 3 | OK | TESTS | 115 | 124 | 1,433,600 | import math
import sys
import queue
def solve():
n, x, y = map(int, input().split())
s = str(input())
subsq = 1
zeros = int(s[0] == "0")
for i in range(1, n):
if s[i] != s[i - 1]:
subsq += 1
if s[i] == "0":
zeros += 1
res = 0
if subsq == 1:
if s[0] == "0":
res = y
else:
res = 0
elif subsq == 2:
res = y
else:
if s[0] == "0":
res = ((subsq - 1) // 2 * x + y)
else:
if subsq == 3:
res = (x + y)
else:
res = ((subsq - 2) // 2 * x + y)
res = min(res, zeros * y)
print(res)
if __name__ == '__main__':
multi_test = 0
if multi_test:
t = int(input())
for _ in range(t):
solve()
else:
solve()
| Title: Convert to Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input Specification:
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones.
Output Specification:
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
Demo Input:
['5 1 10\n01000\n', '5 10 1\n01000\n', '7 2 3\n1111111\n']
Demo Output:
['11\n', '2\n', '0\n']
Note:
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | ```python
import math
import sys
import queue
def solve():
n, x, y = map(int, input().split())
s = str(input())
subsq = 1
zeros = int(s[0] == "0")
for i in range(1, n):
if s[i] != s[i - 1]:
subsq += 1
if s[i] == "0":
zeros += 1
res = 0
if subsq == 1:
if s[0] == "0":
res = y
else:
res = 0
elif subsq == 2:
res = y
else:
if s[0] == "0":
res = ((subsq - 1) // 2 * x + y)
else:
if subsq == 3:
res = (x + y)
else:
res = ((subsq - 2) // 2 * x + y)
res = min(res, zeros * y)
print(res)
if __name__ == '__main__':
multi_test = 0
if multi_test:
t = int(input())
for _ in range(t):
solve()
else:
solve()
``` | 3 |
|
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output": "12"
},
{
"input": "4 5\n5 2 6 4\n8 9 1 3 7",
"output": "12"
},
{
"input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1",
"output": "1"
},
{
"input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6",
"output": "1"
},
{
"input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7",
"output": "1"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n8\n9",
"output": "89"
},
{
"input": "1 1\n9\n8",
"output": "89"
},
{
"input": "1 1\n1\n2",
"output": "12"
},
{
"input": "1 1\n2\n1",
"output": "12"
},
{
"input": "1 1\n9\n9",
"output": "9"
},
{
"input": "1 1\n1\n1",
"output": "1"
},
{
"input": "4 5\n3 2 4 5\n1 6 5 9 8",
"output": "5"
},
{
"input": "3 2\n4 5 6\n1 5",
"output": "5"
},
{
"input": "5 4\n1 3 5 6 7\n2 4 3 9",
"output": "3"
},
{
"input": "5 5\n1 3 5 7 9\n2 4 6 8 9",
"output": "9"
},
{
"input": "2 2\n1 8\n2 8",
"output": "8"
},
{
"input": "5 5\n5 6 7 8 9\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 5\n1 2 3 4 5\n1 2 3 4 5",
"output": "1"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6",
"output": "2"
},
{
"input": "2 2\n1 5\n2 5",
"output": "5"
},
{
"input": "4 4\n1 3 5 8\n2 4 6 8",
"output": "8"
},
{
"input": "3 3\n1 5 3\n2 5 7",
"output": "5"
},
{
"input": "3 3\n3 6 8\n2 6 9",
"output": "6"
},
{
"input": "2 2\n1 4\n2 4",
"output": "4"
},
{
"input": "5 3\n3 4 5 6 7\n1 5 9",
"output": "5"
},
{
"input": "4 4\n1 2 3 4\n2 5 6 7",
"output": "2"
},
{
"input": "5 5\n1 2 3 4 5\n9 2 1 7 5",
"output": "1"
},
{
"input": "2 2\n1 3\n2 3",
"output": "3"
},
{
"input": "3 3\n3 2 1\n3 2 1",
"output": "1"
},
{
"input": "3 3\n1 3 5\n2 3 6",
"output": "3"
},
{
"input": "3 3\n5 6 7\n5 6 7",
"output": "5"
},
{
"input": "1 2\n5\n2 5",
"output": "5"
},
{
"input": "3 3\n2 4 9\n7 8 9",
"output": "9"
},
{
"input": "3 3\n1 2 4\n3 4 5",
"output": "4"
},
{
"input": "3 2\n1 4 9\n2 4",
"output": "4"
},
{
"input": "3 3\n3 5 6\n1 5 9",
"output": "5"
},
{
"input": "3 2\n1 2 4\n3 4",
"output": "4"
},
{
"input": "2 4\n8 9\n1 2 3 9",
"output": "9"
},
{
"input": "1 2\n9\n8 9",
"output": "9"
},
{
"input": "3 2\n1 2 4\n4 2",
"output": "2"
},
{
"input": "2 3\n4 5\n1 3 5",
"output": "5"
},
{
"input": "3 2\n1 2 3\n2 3",
"output": "2"
},
{
"input": "4 3\n1 3 5 9\n2 8 9",
"output": "9"
},
{
"input": "2 2\n1 9\n9 2",
"output": "9"
}
] | 1,584,169,211 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | input()
print((lambda x,y: x if x==y else str(x)+str(y))(min(list(map(int,input().split()))),min(list(map(int,input().split()))))) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Output Specification:
Print the smallest pretty integer.
Demo Input:
['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n']
Demo Output:
['25\n', '1\n']
Note:
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | ```python
input()
print((lambda x,y: x if x==y else str(x)+str(y))(min(list(map(int,input().split()))),min(list(map(int,input().split())))))
``` | 0 |
|
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n1 3",
"output": "3"
},
{
"input": "2\n2 2",
"output": "3"
},
{
"input": "2\n2 3",
"output": "3"
},
{
"input": "2\n3 3",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "3"
},
{
"input": "3\n3 1 1",
"output": "3"
},
{
"input": "3\n1 1 4",
"output": "3"
},
{
"input": "3\n2 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "4"
},
{
"input": "3\n2 4 1",
"output": "4"
},
{
"input": "3\n3 3 1",
"output": "4"
},
{
"input": "3\n1 3 4",
"output": "4"
},
{
"input": "3\n4 1 4",
"output": "4"
},
{
"input": "3\n2 2 2",
"output": "3"
},
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "3\n4 2 2",
"output": "4"
},
{
"input": "3\n2 3 3",
"output": "4"
},
{
"input": "3\n4 2 3",
"output": "4"
},
{
"input": "3\n4 4 2",
"output": "4"
},
{
"input": "3\n3 3 3",
"output": "4"
},
{
"input": "3\n4 3 3",
"output": "4"
},
{
"input": "3\n4 3 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "4\n1 1 1 1",
"output": "2"
},
{
"input": "4\n1 1 2 1",
"output": "3"
},
{
"input": "4\n1 1 3 1",
"output": "3"
},
{
"input": "4\n1 4 1 1",
"output": "3"
},
{
"input": "4\n1 2 1 2",
"output": "3"
},
{
"input": "4\n1 3 2 1",
"output": "4"
},
{
"input": "4\n2 1 4 1",
"output": "4"
},
{
"input": "4\n3 3 1 1",
"output": "4"
},
{
"input": "4\n1 3 4 1",
"output": "4"
},
{
"input": "4\n1 1 4 4",
"output": "4"
},
{
"input": "4\n2 2 2 1",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "4"
},
{
"input": "4\n2 4 1 2",
"output": "4"
},
{
"input": "4\n3 3 1 2",
"output": "4"
},
{
"input": "4\n2 3 4 1",
"output": "5"
},
{
"input": "4\n1 4 2 4",
"output": "5"
},
{
"input": "4\n3 1 3 3",
"output": "4"
},
{
"input": "4\n3 4 3 1",
"output": "5"
},
{
"input": "4\n1 4 4 3",
"output": "5"
},
{
"input": "4\n4 1 4 4",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "4\n2 2 3 2",
"output": "4"
},
{
"input": "4\n2 2 2 4",
"output": "4"
},
{
"input": "4\n2 2 3 3",
"output": "4"
},
{
"input": "4\n2 2 3 4",
"output": "5"
},
{
"input": "4\n2 4 4 2",
"output": "5"
},
{
"input": "4\n2 3 3 3",
"output": "4"
},
{
"input": "4\n2 4 3 3",
"output": "5"
},
{
"input": "4\n4 4 2 3",
"output": "5"
},
{
"input": "4\n4 4 4 2",
"output": "5"
},
{
"input": "4\n3 3 3 3",
"output": "4"
},
{
"input": "4\n3 3 3 4",
"output": "5"
},
{
"input": "4\n4 3 3 4",
"output": "5"
},
{
"input": "4\n4 4 3 4",
"output": "5"
},
{
"input": "4\n4 4 4 4",
"output": "5"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 3 3",
"output": "4"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8",
"output": "9"
},
{
"input": "4\n2 2 2 3",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100",
"output": "15"
},
{
"input": "7\n1 2 2 2 5 5 1",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "5\n1 1 1 1 10000",
"output": "3"
},
{
"input": "5\n1 1 1 1 2",
"output": "3"
},
{
"input": "7\n1 3 3 3 3 3 6",
"output": "5"
},
{
"input": "4\n1 1 1 3",
"output": "3"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 100",
"output": "3"
},
{
"input": "4\n1 1 2 2",
"output": "3"
},
{
"input": "5\n1 1 1 3 4",
"output": "4"
},
{
"input": "8\n1 1 1 1 2 2 3 40",
"output": "5"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "7\n1 2 2 2 2 2 4",
"output": "4"
},
{
"input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 3",
"output": "4"
},
{
"input": "4\n8 8 8 8",
"output": "5"
},
{
"input": "5\n5 6 6 6 7",
"output": "6"
}
] | 1,467,867,432 | 2,147,483,647 | Python 3 | OK | TESTS | 127 | 155 | 9,011,200 | n = input()
a = list(map(int, input().split()))
a.sort()
mex = 1
for x in a:
if x >= mex: mex += 1
print(mex) | Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Output Specification:
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
Demo Input:
['5\n1 3 3 3 6\n', '2\n2 1\n']
Demo Output:
['5\n', '3\n']
Note:
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | ```python
n = input()
a = list(map(int, input().split()))
a.sort()
mex = 1
for x in a:
if x >= mex: mex += 1
print(mex)
``` | 3 |
|
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 1,693,922,695 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
bact = 0
while(n>0):
if(n%2==0):
n=n//2
else:
n=(n-1)//2
bact = bact + 1
print(bact)
| Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
n = int(input())
bact = 0
while(n>0):
if(n%2==0):
n=n//2
else:
n=(n-1)//2
bact = bact + 1
print(bact)
``` | 3 |
|
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,645,683,992 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
/*
_____ _ __ __ ____
/ ___/____ _____ ____ _(_)___ ____ _ __ \ \/ /_ _________ __/ __/
\__ \/ __ `/ __ \/ __ `/ / __ \/ __ \ | / / \ / / / / ___/ / / / /_
___/ / /_/ / / / / /_/ / / / / / /_/ / |/ / / / /_/ (__ ) /_/ / __/
_____/____/\__,_/_/ /_/\__, /_/_/ /_/\____/|___/____/_/\__,_/____/\__,_/_/_____
/_____/ /____/ /_____/ /_____/
*/
long long i , n , t , k , p;
int main()
{
FAST
cin >> n >> k;
long long a[n + 1] = {};
for (i = 1 ; i <= n ; i ++)
{
cin >> a[i];
}
for (i = 2 ; i <= n ; i ++)
{
if (a[i] <= a[i - 1])
{
a[i] += (a[i - 1] - a[i] + k - 1) / k;
t += (a[i - 1] - a[i] + k - 1) / k;
t ++;
a[i] ++;
}
}
cout << t;
}
| Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
/*
_____ _ __ __ ____
/ ___/____ _____ ____ _(_)___ ____ _ __ \ \/ /_ _________ __/ __/
\__ \/ __ `/ __ \/ __ `/ / __ \/ __ \ | / / \ / / / / ___/ / / / /_
___/ / /_/ / / / / /_/ / / / / / /_/ / |/ / / / /_/ (__ ) /_/ / __/
_____/____/\__,_/_/ /_/\__, /_/_/ /_/\____/|___/____/_/\__,_/____/\__,_/_/_____
/_____/ /____/ /_____/ /_____/
*/
long long i , n , t , k , p;
int main()
{
FAST
cin >> n >> k;
long long a[n + 1] = {};
for (i = 1 ; i <= n ; i ++)
{
cin >> a[i];
}
for (i = 2 ; i <= n ; i ++)
{
if (a[i] <= a[i - 1])
{
a[i] += (a[i - 1] - a[i] + k - 1) / k;
t += (a[i - 1] - a[i] + k - 1) / k;
t ++;
a[i] ++;
}
}
cout << t;
}
``` | -1 |
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning. | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"2 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},
{
"input": "5 10\n3 81\n3 49\n1 20\n1 12\n1 30",
"output": "-1"
},
{
"input": "5 10\n4 3\n1 54\n2 57\n2 31\n1 99",
"output": "-1"
},
{
"input": "5 10\n2 81\n3 31\n4 49\n1 35\n1 67",
"output": "263.0000000000"
},
{
"input": "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92",
"output": "102.2222222222"
},
{
"input": "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16",
"output": "17.7777777778"
},
{
"input": "10 1\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40",
"output": "44.4444444444"
},
{
"input": "2 1\n1 10\n1 10",
"output": "20.0000000000"
},
{
"input": "20 16807\n75250 50074\n43659 8931\n11273 27545\n50879 77924\n37710 64441\n38166 84493\n43043 7988\n22504 82328\n31730 78841\n42613 44304\n33170 17710\n97158 29561\n70934 93100\n80279 51817\n95336 99098\n7827 13513\n29268 23811\n77634 80980\n79150 36580\n58822 11968",
"output": "0.2244225704"
}
] | 1,696,159,515 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def can_use_indefinitely(n, p, devices):
low = 0.0
high = float("inf")
while high - low > 1e-6:
mid = (low + high) / 2.0
total_power_needed = 0
for a, b in devices:
power_needed = max(0, mid * a - b)
total_power_needed += power_needed
if total_power_needed > mid * p:
high = mid
else:
low = mid
if low == float("inf"):
return -1
return low
n, p = map(int, input().split())
devices = []
for _ in range(n):
a, b = map(int, input().split())
devices.append((a, b))
result = can_use_indefinitely(n, p, devices)
print("{:.9f}".format(result))
| Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input Specification:
The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning.
Output Specification:
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['2 1\n2 2\n2 1000\n', '1 100\n1 1\n', '3 5\n4 3\n5 2\n6 1\n']
Demo Output:
['2.0000000000', '-1\n', '0.5000000000']
Note:
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | ```python
def can_use_indefinitely(n, p, devices):
low = 0.0
high = float("inf")
while high - low > 1e-6:
mid = (low + high) / 2.0
total_power_needed = 0
for a, b in devices:
power_needed = max(0, mid * a - b)
total_power_needed += power_needed
if total_power_needed > mid * p:
high = mid
else:
low = mid
if low == float("inf"):
return -1
return low
n, p = map(int, input().split())
devices = []
for _ in range(n):
a, b = map(int, input().split())
devices.append((a, b))
result = can_use_indefinitely(n, p, devices)
print("{:.9f}".format(result))
``` | 0 |
|
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "10 10 42",
"output": "YES"
},
{
"input": "-1000000000 1000000000 -1",
"output": "NO"
},
{
"input": "10 16 4",
"output": "NO"
},
{
"input": "-1000000000 1000000000 5",
"output": "YES"
},
{
"input": "1000000000 -1000000000 5",
"output": "NO"
},
{
"input": "1000000000 -1000000000 0",
"output": "NO"
},
{
"input": "1000000000 1000000000 0",
"output": "YES"
},
{
"input": "115078364 -899474523 -1",
"output": "YES"
},
{
"input": "-245436499 416383245 992",
"output": "YES"
},
{
"input": "-719636354 536952440 2",
"output": "YES"
},
{
"input": "-198350539 963391024 68337739",
"output": "YES"
},
{
"input": "-652811055 875986516 1091",
"output": "YES"
},
{
"input": "119057893 -516914539 -39748277",
"output": "YES"
},
{
"input": "989140430 731276607 -36837689",
"output": "YES"
},
{
"input": "677168390 494583489 -985071853",
"output": "NO"
},
{
"input": "58090193 777423708 395693923",
"output": "NO"
},
{
"input": "479823846 -403424770 -653472589",
"output": "NO"
},
{
"input": "-52536829 -132023273 -736287999",
"output": "NO"
},
{
"input": "-198893776 740026818 -547885271",
"output": "NO"
},
{
"input": "-2 -2 -2",
"output": "YES"
},
{
"input": "-2 -2 -1",
"output": "YES"
},
{
"input": "-2 -2 0",
"output": "YES"
},
{
"input": "-2 -2 1",
"output": "YES"
},
{
"input": "-2 -2 2",
"output": "YES"
},
{
"input": "-2 -1 -2",
"output": "NO"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "-2 -1 0",
"output": "NO"
},
{
"input": "-2 -1 1",
"output": "YES"
},
{
"input": "-2 -1 2",
"output": "NO"
},
{
"input": "-2 0 -2",
"output": "NO"
},
{
"input": "-2 0 -1",
"output": "NO"
},
{
"input": "-2 0 0",
"output": "NO"
},
{
"input": "-2 0 1",
"output": "YES"
},
{
"input": "-2 0 2",
"output": "YES"
},
{
"input": "-2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -1",
"output": "NO"
},
{
"input": "-2 1 0",
"output": "NO"
},
{
"input": "-2 1 1",
"output": "YES"
},
{
"input": "-2 1 2",
"output": "NO"
},
{
"input": "-2 2 -2",
"output": "NO"
},
{
"input": "-2 2 -1",
"output": "NO"
},
{
"input": "-2 2 0",
"output": "NO"
},
{
"input": "-2 2 1",
"output": "YES"
},
{
"input": "-2 2 2",
"output": "YES"
},
{
"input": "-1 -2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1",
"output": "YES"
},
{
"input": "-1 -2 0",
"output": "NO"
},
{
"input": "-1 -2 1",
"output": "NO"
},
{
"input": "-1 -2 2",
"output": "NO"
},
{
"input": "-1 -1 -2",
"output": "YES"
},
{
"input": "-1 -1 -1",
"output": "YES"
},
{
"input": "-1 -1 0",
"output": "YES"
},
{
"input": "-1 -1 1",
"output": "YES"
},
{
"input": "-1 -1 2",
"output": "YES"
},
{
"input": "-1 0 -2",
"output": "NO"
},
{
"input": "-1 0 -1",
"output": "NO"
},
{
"input": "-1 0 0",
"output": "NO"
},
{
"input": "-1 0 1",
"output": "YES"
},
{
"input": "-1 0 2",
"output": "NO"
},
{
"input": "-1 1 -2",
"output": "NO"
},
{
"input": "-1 1 -1",
"output": "NO"
},
{
"input": "-1 1 0",
"output": "NO"
},
{
"input": "-1 1 1",
"output": "YES"
},
{
"input": "-1 1 2",
"output": "YES"
},
{
"input": "-1 2 -2",
"output": "NO"
},
{
"input": "-1 2 -1",
"output": "NO"
},
{
"input": "-1 2 0",
"output": "NO"
},
{
"input": "-1 2 1",
"output": "YES"
},
{
"input": "-1 2 2",
"output": "NO"
},
{
"input": "0 -2 -2",
"output": "YES"
},
{
"input": "0 -2 -1",
"output": "YES"
},
{
"input": "0 -2 0",
"output": "NO"
},
{
"input": "0 -2 1",
"output": "NO"
},
{
"input": "0 -2 2",
"output": "NO"
},
{
"input": "0 -1 -2",
"output": "NO"
},
{
"input": "0 -1 -1",
"output": "YES"
},
{
"input": "0 -1 0",
"output": "NO"
},
{
"input": "0 -1 1",
"output": "NO"
},
{
"input": "0 -1 2",
"output": "NO"
},
{
"input": "0 0 -2",
"output": "YES"
},
{
"input": "0 0 -1",
"output": "YES"
},
{
"input": "0 0 0",
"output": "YES"
},
{
"input": "0 0 1",
"output": "YES"
},
{
"input": "0 0 2",
"output": "YES"
},
{
"input": "0 1 -2",
"output": "NO"
},
{
"input": "0 1 -1",
"output": "NO"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "0 1 1",
"output": "YES"
},
{
"input": "0 1 2",
"output": "NO"
},
{
"input": "0 2 -2",
"output": "NO"
},
{
"input": "0 2 -1",
"output": "NO"
},
{
"input": "0 2 0",
"output": "NO"
},
{
"input": "0 2 1",
"output": "YES"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "1 -2 -2",
"output": "NO"
},
{
"input": "1 -2 -1",
"output": "YES"
},
{
"input": "1 -2 0",
"output": "NO"
},
{
"input": "1 -2 1",
"output": "NO"
},
{
"input": "1 -2 2",
"output": "NO"
},
{
"input": "1 -1 -2",
"output": "YES"
},
{
"input": "1 -1 -1",
"output": "YES"
},
{
"input": "1 -1 0",
"output": "NO"
},
{
"input": "1 -1 1",
"output": "NO"
},
{
"input": "1 -1 2",
"output": "NO"
},
{
"input": "1 0 -2",
"output": "NO"
},
{
"input": "1 0 -1",
"output": "YES"
},
{
"input": "1 0 0",
"output": "NO"
},
{
"input": "1 0 1",
"output": "NO"
},
{
"input": "1 0 2",
"output": "NO"
},
{
"input": "1 1 -2",
"output": "YES"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "1 1 0",
"output": "YES"
},
{
"input": "1 1 1",
"output": "YES"
},
{
"input": "1 1 2",
"output": "YES"
},
{
"input": "1 2 -2",
"output": "NO"
},
{
"input": "1 2 -1",
"output": "NO"
},
{
"input": "1 2 0",
"output": "NO"
},
{
"input": "1 2 1",
"output": "YES"
},
{
"input": "1 2 2",
"output": "NO"
},
{
"input": "2 -2 -2",
"output": "YES"
},
{
"input": "2 -2 -1",
"output": "YES"
},
{
"input": "2 -2 0",
"output": "NO"
},
{
"input": "2 -2 1",
"output": "NO"
},
{
"input": "2 -2 2",
"output": "NO"
},
{
"input": "2 -1 -2",
"output": "NO"
},
{
"input": "2 -1 -1",
"output": "YES"
},
{
"input": "2 -1 0",
"output": "NO"
},
{
"input": "2 -1 1",
"output": "NO"
},
{
"input": "2 -1 2",
"output": "NO"
},
{
"input": "2 0 -2",
"output": "YES"
},
{
"input": "2 0 -1",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "2 0 1",
"output": "NO"
},
{
"input": "2 0 2",
"output": "NO"
},
{
"input": "2 1 -2",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "2 1 0",
"output": "NO"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "2 1 2",
"output": "NO"
},
{
"input": "2 2 -2",
"output": "YES"
},
{
"input": "2 2 -1",
"output": "YES"
},
{
"input": "2 2 0",
"output": "YES"
},
{
"input": "2 2 1",
"output": "YES"
},
{
"input": "2 2 2",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 2",
"output": "YES"
},
{
"input": "1000000000 -1000000000 -1",
"output": "YES"
},
{
"input": "5 2 3",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "3 2 1",
"output": "NO"
},
{
"input": "0 -5 -3",
"output": "NO"
},
{
"input": "2 5 5",
"output": "NO"
},
{
"input": "0 10 1",
"output": "YES"
},
{
"input": "15 5 -5",
"output": "YES"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "20 10 0",
"output": "NO"
},
{
"input": "20 15 5",
"output": "NO"
},
{
"input": "1 6 1",
"output": "YES"
},
{
"input": "1000000000 0 -1000000000",
"output": "YES"
},
{
"input": "1 1 -5",
"output": "YES"
},
{
"input": "4 6 1",
"output": "YES"
},
{
"input": "-5 -10 -5",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "10 9 -1",
"output": "YES"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "1 13 3",
"output": "YES"
},
{
"input": "2 3 0",
"output": "NO"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "5 -10 -5",
"output": "YES"
},
{
"input": "5 3 1",
"output": "NO"
},
{
"input": "1 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1000000000",
"output": "YES"
}
] | 1,498,032,765 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 4,608,000 | a,b,c=map(int,input().split())
if c==0:print(['NO','YES'][a==b])
else:print(['NO','YES'][(b-a)//c>0and(b-a)%c==0]) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
Input Specification:
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output Specification:
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
Demo Input:
['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | ```python
a,b,c=map(int,input().split())
if c==0:print(['NO','YES'][a==b])
else:print(['NO','YES'][(b-a)//c>0and(b-a)%c==0])
``` | 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,633,066,857 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 31 | 0 | n=int(input())
n-=1
p=['Sheldon','Leonard','Penny','Rajesh','Howard']
if n>5:
n=(n-5)//2
print(p[n]) | 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())
n-=1
p=['Sheldon','Leonard','Penny','Rajesh','Howard']
if n>5:
n=(n-5)//2
print(p[n])
``` | -1 |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,653,484,268 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | angles = [60,90,120,150,180]
for _ in range(int(input())):
a = int(input())
if a in angles:
print("YES")
else:
print("NO") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
angles = [60,90,120,150,180]
for _ in range(int(input())):
a = int(input())
if a in angles:
print("YES")
else:
print("NO")
``` | 0 |
|
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as there is no such representation for it.
Such interval of years that there are no unlucky years in it is called The Golden Age.
You should write a program which will find maximum length of The Golden Age which starts no earlier than the year *l* and ends no later than the year *r*. If all years in the interval [*l*,<=*r*] are unlucky then the answer is 0. | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
"output": "144115188075855871"
},
{
"input": "2 3 1 1000000",
"output": "206415"
},
{
"input": "2 3 1 1000000000000000000",
"output": "261485717957290893"
},
{
"input": "12345 54321 1 1000000",
"output": "933334"
},
{
"input": "54321 12345 1 1000000000000000000",
"output": "976614248345331214"
},
{
"input": "2 3 100000000 1000000000000",
"output": "188286357653"
},
{
"input": "2 14 732028847861235712 732028847861235712",
"output": "0"
},
{
"input": "14 2 732028847861235713 732028847861235713",
"output": "1"
},
{
"input": "3 2 6 7",
"output": "1"
},
{
"input": "16 5 821690667 821691481",
"output": "815"
},
{
"input": "1000000000000000000 2 1 1000000000000000000",
"output": "423539247696576511"
},
{
"input": "2 1000000000000000000 1000000000000000 1000000000000000000",
"output": "423539247696576511"
},
{
"input": "2 2 1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "3 3 1 1",
"output": "1"
},
{
"input": "2 3 626492297402423196 726555387600422608",
"output": "100063090197999413"
},
{
"input": "4 4 1 1",
"output": "1"
},
{
"input": "304279187938024110 126610724244348052 78460471576735729 451077737144268785",
"output": "177668463693676057"
},
{
"input": "510000000000 510000000000 1 1000000000000000000",
"output": "999998980000000000"
},
{
"input": "2 10000000000000000 1 1000000000000000000",
"output": "413539247696576512"
},
{
"input": "84826654960259 220116531311479700 375314289098080160 890689132792406667",
"output": "515374843694326508"
},
{
"input": "1001 9999 1 1000000000000000000",
"output": "988998989390034998"
},
{
"input": "106561009498593483 3066011339919949 752858505287719337 958026822891358781",
"output": "205168317603639445"
},
{
"input": "650233444262690661 556292951587380938 715689923804218376 898772439356652923",
"output": "183082515552434548"
},
{
"input": "4294967297 4294967297 1 1000000000000000000",
"output": "999999991410065406"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "73429332516742239 589598864615747534 555287238606698050 981268715519611449",
"output": "318240518387121676"
},
{
"input": "282060925969693883 446418005951342865 709861829378794811 826972744183396568",
"output": "98493812262359820"
},
{
"input": "97958277744315833 443452631396066615 33878596673318768 306383421710156519",
"output": "208425143965840685"
},
{
"input": "40975442958818854 7397733549114401 299774870238987084 658001214206968260",
"output": "358226343967981177"
},
{
"input": "699 700 1 1000",
"output": "697"
},
{
"input": "483076744475822225 425097332543006422 404961220953110704 826152774360856248",
"output": "343076029885034022"
},
{
"input": "4294967297 4294967297 1 999999999999999999",
"output": "999999991410065405"
},
{
"input": "702012794 124925148 2623100012 1000000000000000000",
"output": "491571744457491660"
},
{
"input": "433333986179614514 1000000000000000000 433333986179614515 726628630292055493",
"output": "293294644112440978"
},
{
"input": "999999999999999999 364973116927770629 4 4",
"output": "1"
},
{
"input": "4 2 40 812",
"output": "191"
},
{
"input": "2 3 1 1",
"output": "1"
},
{
"input": "1556368728 1110129598 120230736 1258235681",
"output": "989898863"
},
{
"input": "7 9 164249007852879073 459223650245359577",
"output": "229336748650748455"
},
{
"input": "324693328712373699 541961409169732375 513851377473048715 873677521504257312",
"output": "324693328712373697"
},
{
"input": "370083000139673112 230227213530985315 476750241623737312 746365058930029530",
"output": "146054845259371103"
},
{
"input": "4 3 584 899",
"output": "146"
},
{
"input": "4 3 286 581",
"output": "161"
},
{
"input": "304045744870965151 464630021384225732 142628934177558000 844155070300317027",
"output": "304045744870965149"
},
{
"input": "195627622825327857 666148746663834172 1 1000000000000000000",
"output": "470521123838506314"
},
{
"input": "459168731438725410 459955118458373596 410157890472128901 669197645706452507",
"output": "209242527248078910"
},
{
"input": "999999999999999999 999999999999999999 1 1000000000000000000",
"output": "999999999999999997"
},
{
"input": "752299248283963354 680566564599126819 73681814274367577 960486443362068685",
"output": "606884750324759243"
},
{
"input": "20373217421623606 233158243228114207 97091516440255589 395722640217125926",
"output": "142191179567388113"
},
{
"input": "203004070900 20036005000 1 1000000000000000000",
"output": "999999776959924100"
},
{
"input": "565269817339236857 318270460838647700 914534538271870694 956123707310168659",
"output": "41589169038297966"
},
{
"input": "2 5 330 669",
"output": "131"
},
{
"input": "9 9 91 547",
"output": "385"
},
{
"input": "9 4 866389615074294253 992899492208527253",
"output": "126509877134233001"
},
{
"input": "3037000500 3037000500 1 1000000000000000000",
"output": "999999993925999000"
},
{
"input": "4294967297 4294967297 12 1000000000000000000",
"output": "999999991410065406"
},
{
"input": "5 3 78510497842978003 917156799600023483",
"output": "238418579101562499"
},
{
"input": "749206377024033575 287723056504284448 387669391392789697 931234393488075794",
"output": "361536985631243879"
},
{
"input": "999999999999999999 454135 1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "759826429841877401 105086867783910112 667080043736858072 797465019478234768",
"output": "92746386105019330"
},
{
"input": "1000000000000000000 1000000000000000000 5 7",
"output": "3"
},
{
"input": "440968000218771383 43378854522801881 169393324037146024 995429539593716237",
"output": "511082684852142973"
},
{
"input": "15049917793417622 113425474361704411 87565655389309185 803955352361026671",
"output": "675479960205904638"
},
{
"input": "4 6 264626841724745187 925995096479842591",
"output": "369878143059623936"
},
{
"input": "4294967297 4294967297 13 1000000000000000000",
"output": "999999991410065406"
},
{
"input": "315729630349763416 22614591055604717 66895291338255006 947444311481017774",
"output": "609100090075649641"
},
{
"input": "3 10 173 739",
"output": "386"
},
{
"input": "161309010783040325 128259041753158864 5843045875031294 854024306926137845",
"output": "564456254389938656"
},
{
"input": "239838434825939759 805278168279318096 202337849919104640 672893754916863788",
"output": "433055320090924028"
},
{
"input": "9 9 435779695685310822 697902619874412541",
"output": "262122924189101720"
},
{
"input": "967302429573451368 723751675006196376 143219686319239751 266477897142546404",
"output": "123258210823306654"
},
{
"input": "10 8 139979660652061677 941135332855173888",
"output": "697020144779318016"
},
{
"input": "4294967297 1000000000000000000 4294967296 17179869184",
"output": "12884901886"
},
{
"input": "100914030314340517 512922595840756536 812829791042966971 966156272123068006",
"output": "153326481080101036"
},
{
"input": "288230376151711744 288230376151711744 1 1000000000000000000",
"output": "423539247696576512"
},
{
"input": "6 9 681 750",
"output": "49"
},
{
"input": "880356874212472951 178538501711453307 162918237570625233 224969951233811739",
"output": "46431449522358431"
},
{
"input": "2 7 405373082004080437 771991379629433514",
"output": "153172782079203571"
},
{
"input": "10 11 10 11",
"output": "1"
}
] | 1,496,676,756 | 1,656 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 307,200 | [x, y, l, r] = map(int, input().rstrip().split())
data = []
lbad = False
rbad = False
for i in range(0, 61):
for j in range(0, 61):
num = x ** i + y ** j
if num == l:
lbad = True
if num == r:
rbad = True
if l <= num <= r:
data.append(num)
elif num > r:
break
data.sort()
max_time = max(data[0] - l - (1 if lbad else 0), r - data[-1] - (1 if rbad else 0))
for i in range(0, len(data) - 1):
max_time = max(data[i + 1] - data[i] - 1, max_time)
print(max_time)
| Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as there is no such representation for it.
Such interval of years that there are no unlucky years in it is called The Golden Age.
You should write a program which will find maximum length of The Golden Age which starts no earlier than the year *l* and ends no later than the year *r*. If all years in the interval [*l*,<=*r*] are unlucky then the answer is 0.
Input Specification:
The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Output Specification:
Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0.
Demo Input:
['2 3 1 10\n', '3 5 10 22\n', '2 3 3 5\n']
Demo Output:
['1\n', '8\n', '0\n']
Note:
In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | ```python
[x, y, l, r] = map(int, input().rstrip().split())
data = []
lbad = False
rbad = False
for i in range(0, 61):
for j in range(0, 61):
num = x ** i + y ** j
if num == l:
lbad = True
if num == r:
rbad = True
if l <= num <= r:
data.append(num)
elif num > r:
break
data.sort()
max_time = max(data[0] - l - (1 if lbad else 0), r - data[-1] - (1 if rbad else 0))
for i in range(0, len(data) - 1):
max_time = max(data[i + 1] - data[i] - 1, max_time)
print(max_time)
``` | 0 |
|
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n500\n500",
"output": "0.5"
},
{
"input": "1000\n1\n1",
"output": "500"
},
{
"input": "1000\n1\n500",
"output": "1.996007984"
},
{
"input": "1000\n500\n1",
"output": "998.003992"
},
{
"input": "1000\n500\n500",
"output": "500"
},
{
"input": "101\n11\n22",
"output": "33.66666667"
},
{
"input": "987\n1\n3",
"output": "246.75"
},
{
"input": "258\n25\n431",
"output": "14.14473684"
},
{
"input": "979\n39\n60",
"output": "385.6666667"
},
{
"input": "538\n479\n416",
"output": "287.9351955"
},
{
"input": "583\n112\n248",
"output": "181.3777778"
},
{
"input": "978\n467\n371",
"output": "545.0190931"
},
{
"input": "980\n322\n193",
"output": "612.7378641"
},
{
"input": "871\n401\n17",
"output": "835.576555"
},
{
"input": "349\n478\n378",
"output": "194.885514"
},
{
"input": "425\n458\n118",
"output": "337.9340278"
},
{
"input": "919\n323\n458",
"output": "380.0729834"
},
{
"input": "188\n59\n126",
"output": "59.95675676"
},
{
"input": "644\n428\n484",
"output": "302.2280702"
},
{
"input": "253\n80\n276",
"output": "56.85393258"
},
{
"input": "745\n152\n417",
"output": "199.0158172"
},
{
"input": "600\n221\n279",
"output": "265.2"
},
{
"input": "690\n499\n430",
"output": "370.6243272"
},
{
"input": "105\n68\n403",
"output": "15.15923567"
},
{
"input": "762\n462\n371",
"output": "422.6218487"
},
{
"input": "903\n460\n362",
"output": "505.3284672"
},
{
"input": "886\n235\n95",
"output": "630.9393939"
},
{
"input": "655\n203\n18",
"output": "601.6515837"
},
{
"input": "718\n29\n375",
"output": "51.53960396"
},
{
"input": "296\n467\n377",
"output": "163.7819905"
},
{
"input": "539\n61\n56",
"output": "281.017094"
},
{
"input": "133\n53\n124",
"output": "39.82485876"
},
{
"input": "998\n224\n65",
"output": "773.5363322"
},
{
"input": "961\n173\n47",
"output": "755.6954545"
},
{
"input": "285\n468\n62",
"output": "251.6603774"
},
{
"input": "496\n326\n429",
"output": "214.1668874"
},
{
"input": "627\n150\n285",
"output": "216.2068966"
},
{
"input": "961\n443\n50",
"output": "863.535497"
},
{
"input": "623\n422\n217",
"output": "411.4334898"
},
{
"input": "678\n295\n29",
"output": "617.3148148"
}
] | 1,699,394,429 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | #input_values = input().split()
x = int(input())
p = int(input())
q = int(input())
d = ((x*p) / (p+q))
print(d)
| Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
Input Specification:
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Output Specification:
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['100\n50\n50\n', '199\n60\n40\n']
Demo Output:
['50\n', '119.4\n']
Note:
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | ```python
#input_values = input().split()
x = int(input())
p = int(input())
q = int(input())
d = ((x*p) / (p+q))
print(d)
``` | 3 |
|
549 | A | Face Detection | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. | The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters. | In the single line print the number of faces on the image. | [
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] | [
"1\n",
"1\n",
"2\n",
"0\n"
] | In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In the fourth sample the image has no faces on it. | 250 | [
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "0"
},
{
"input": "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk",
"output": "1"
},
{
"input": "1 1\np",
"output": "0"
},
{
"input": "2 5\nacdmw\nefazb",
"output": "1"
},
{
"input": "5 2\ndz\nda\nsx\nyu\nzz",
"output": "0"
},
{
"input": "5 5\nxeljd\nwriac\nveief\nlcacf\nbqefn",
"output": "2"
},
{
"input": "5 5\nacnbx\nefacp\nlrefa\norqce\nzvbay",
"output": "3"
},
{
"input": "5 5\nbyjvu\nkmaca\nalefe\nwcacg\nrefez",
"output": "5"
},
{
"input": "5 5\npuxac\nbbaef\naccfa\nefaec\nligsr",
"output": "5"
},
{
"input": "37 4\nacjo\nefac\nacef\nefac\nwpef\nicac\naefe\ncfac\naece\ncfaf\nyqce\nmiaf\nirce\nycaf\naefc\ncfae\nrsnc\nbacz\nqefb\npdhs\nffac\nfaef\nacfd\nacmi\nefvm\nacaz\nefpn\nacao\nefer\nacap\nefec\nacaf\nefef\nacbj\nefac\nacef\nefoz",
"output": "49"
},
{
"input": "7 3\njac\naef\ncfa\naec\ncfq\ndig\nxyq",
"output": "5"
},
{
"input": "35 1\ny\na\nk\ng\ni\nd\nv\nn\nl\nx\nu\nx\nu\no\nd\nf\nk\nj\nr\nm\nq\ns\nc\nd\nc\nm\nv\nh\nn\ne\nl\nt\nz\ny\no",
"output": "0"
},
{
"input": "9 46\nuuexbaacesjclggslacermcbkxlcxhdgqtacdwfryxzuxc\naclrsaefakndbnzlkefenuphgcgoedhkaxefjtnkgfeaca\nefuqunpmfxdyyffyhvracozzrxlpekhtsrfhlilfmyhefg\numyacfzffvicqtdpiulefnwcojuwtfbvlxkfsiapdnzpqo\nactefvuxqptremlqjhdbdwacjxdxitxjktecvefacamjcz\neflarseklqrkayhosverpfefzirqigzlxezabhzeferkwm\nztpypwxyohtacsnnvoigqwcachtaceyxlkhfhgwbnfmklb\nfzpqeymhljiefctvqtbgcdjefkxefarbciyosmktmoziac\nbssxizyrzyhacszttwhrzspbfkgfcejybdjcpuczhrkqef",
"output": "20"
},
{
"input": "7 30\nmjfracgaacacctacrreyrlkacuacay\nrlacefacefeftaeftkacacaefcefev\nacefacefacraccfaeaefefecaeacaf\nefacefacefaefaecfcfacacaecfefa\nncefacefacecacfaeaecefefcaeace\nfafaceacuafaefadcfcafacaefcfea\nzsvefafukcecfarkaeaecefecailgu",
"output": "95"
},
{
"input": "2 2\nff\nee",
"output": "0"
},
{
"input": "2 2\nfa\ncc",
"output": "0"
},
{
"input": "2 2\nfa\naa",
"output": "0"
},
{
"input": "2 2\nfa\nea",
"output": "0"
},
{
"input": "2 2\nfa\ndd",
"output": "0"
},
{
"input": "2 2\nee\nff",
"output": "0"
},
{
"input": "2 2\ncc\ncf",
"output": "0"
},
{
"input": "2 2\naa\nae",
"output": "0"
},
{
"input": "2 2\nef\nac",
"output": "1"
},
{
"input": "2 2\nfe\nca",
"output": "1"
}
] | 1,595,233,535 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 108 | 6,963,200 | n,m=map(int,input().split())
a=[list(input()) for i in range(n)]
d=set(['f','a','c','e'])
k=0
for i in range(n-1):
for j in range(m-1):
if a[i][j] in d:
s=set()
s.add(a[i][j])
s.add(a[i+1][j])
s.add(a[i+1][j+1])
s.add(a[i][j+1])
if s==d:
k+=1
print(k) | Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input Specification:
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
Output Specification:
In the single line print the number of faces on the image.
Demo Input:
['4 4\nxxxx\nxfax\nxcex\nxxxx\n', '4 2\nxx\ncf\nae\nxx\n', '2 3\nfac\ncef\n', '1 4\nface\n']
Demo Output:
['1\n', '1\n', '2\n', '0\n']
Note:
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In the fourth sample the image has no faces on it. | ```python
n,m=map(int,input().split())
a=[list(input()) for i in range(n)]
d=set(['f','a','c','e'])
k=0
for i in range(n-1):
for j in range(m-1):
if a[i][j] in d:
s=set()
s.add(a[i][j])
s.add(a[i+1][j])
s.add(a[i+1][j+1])
s.add(a[i][j+1])
if s==d:
k+=1
print(k)
``` | 3 |
|
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's and Eeyore's house is *b* meters, between Owl's and Eeyore's house is *c* meters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal *n* times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal *n* times, traveling minimum possible distance. Help him to find this distance. | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* (1<=≤<=*c*<=≤<=100) — distance between Owl's and Eeyore's houses. | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"output": "296"
},
{
"input": "76\n46\n77\n11",
"output": "860"
},
{
"input": "80\n42\n1\n37",
"output": "79"
},
{
"input": "8\n80\n55\n1",
"output": "61"
},
{
"input": "10\n13\n72\n17",
"output": "117"
},
{
"input": "9\n24\n1\n63",
"output": "8"
},
{
"input": "65\n5\n8\n7",
"output": "320"
},
{
"input": "56\n8\n9\n3",
"output": "170"
},
{
"input": "59\n8\n1\n2",
"output": "58"
},
{
"input": "75\n50\n50\n5",
"output": "415"
},
{
"input": "75\n54\n76\n66",
"output": "3996"
},
{
"input": "73\n71\n69\n66",
"output": "4755"
},
{
"input": "83\n58\n88\n16",
"output": "1354"
},
{
"input": "74\n31\n11\n79",
"output": "803"
},
{
"input": "62\n27\n16\n72",
"output": "976"
},
{
"input": "72\n95\n27\n9",
"output": "657"
},
{
"input": "1\n2\n2\n1",
"output": "0"
},
{
"input": "1\n1\n1\n1",
"output": "0"
},
{
"input": "1\n1\n1\n99",
"output": "0"
},
{
"input": "100\n100\n100\n100",
"output": "9900"
},
{
"input": "2\n1\n1\n3",
"output": "1"
},
{
"input": "1\n3\n2\n1",
"output": "0"
},
{
"input": "1\n5\n6\n1",
"output": "0"
},
{
"input": "1\n2\n6\n1",
"output": "0"
},
{
"input": "1\n30\n20\n1",
"output": "0"
},
{
"input": "1\n15\n13\n11",
"output": "0"
},
{
"input": "1\n100\n50\n1",
"output": "0"
},
{
"input": "1\n2\n3\n1",
"output": "0"
},
{
"input": "5\n5\n5\n5",
"output": "20"
},
{
"input": "1\n100\n50\n5",
"output": "0"
},
{
"input": "1\n5\n7\n3",
"output": "0"
},
{
"input": "1\n3\n4\n2",
"output": "0"
},
{
"input": "3\n3\n3\n3",
"output": "6"
},
{
"input": "1\n99\n98\n1",
"output": "0"
},
{
"input": "5\n3\n3\n1",
"output": "6"
},
{
"input": "2\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1\n7\n8",
"output": "1"
},
{
"input": "2\n2\n2\n1",
"output": "2"
},
{
"input": "2\n2\n3\n1",
"output": "2"
},
{
"input": "1\n5\n6\n2",
"output": "0"
},
{
"input": "100\n1\n1\n100",
"output": "99"
},
{
"input": "2\n3\n2\n1",
"output": "2"
},
{
"input": "1\n99\n98\n97",
"output": "0"
}
] | 1,623,898,993 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 77 | 0 | n, ro, re, oe = int(input()), int(input()), int(input()), int(input())
d, a, c, b = {0: ro, 1: re, 2: oe}, [ro, re, oe], 0, [0, 1]
for i in range(n - 1):
if d[b[0]] >= d[b[1]]:
c += d[b[1]]
b.append(3 - sum(b))
b.remove(b[0])
else:
c += d[b[0]]
b.append(3 - sum(b))
b.remove(b[1])
print(c) | Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's and Eeyore's house is *b* meters, between Owl's and Eeyore's house is *c* meters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal *n* times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal *n* times, traveling minimum possible distance. Help him to find this distance.
Input Specification:
First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* (1<=≤<=*c*<=≤<=100) — distance between Owl's and Eeyore's houses.
Output Specification:
Output one number — minimum distance in meters Winnie must go through to have a meal *n* times.
Demo Input:
['3\n2\n3\n1\n', '1\n2\n3\n5\n']
Demo Output:
['3\n', '0\n']
Note:
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | ```python
n, ro, re, oe = int(input()), int(input()), int(input()), int(input())
d, a, c, b = {0: ro, 1: re, 2: oe}, [ro, re, oe], 0, [0, 1]
for i in range(n - 1):
if d[b[0]] >= d[b[1]]:
c += d[b[1]]
b.append(3 - sum(b))
b.remove(b[0])
else:
c += d[b[0]]
b.append(3 - sum(b))
b.remove(b[1])
print(c)
``` | 3 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,663,799,226 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | x=input()
n1,m1,a1=x.split()
n,m,a=int(n1),int(m1),int(a1)
if m%a==0 :
v1=m//a
else :
v1=m//a + 1
if n%a==0 :
v2=n//a
else :
v2=n//a + 1
print(v1*v2) | 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
x=input()
n1,m1,a1=x.split()
n,m,a=int(n1),int(m1),int(a1)
if m%a==0 :
v1=m//a
else :
v1=m//a + 1
if n%a==0 :
v2=n//a
else :
v2=n//a + 1
print(v1*v2)
``` | 3.977 |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n500\n500",
"output": "0.5"
},
{
"input": "1000\n1\n1",
"output": "500"
},
{
"input": "1000\n1\n500",
"output": "1.996007984"
},
{
"input": "1000\n500\n1",
"output": "998.003992"
},
{
"input": "1000\n500\n500",
"output": "500"
},
{
"input": "101\n11\n22",
"output": "33.66666667"
},
{
"input": "987\n1\n3",
"output": "246.75"
},
{
"input": "258\n25\n431",
"output": "14.14473684"
},
{
"input": "979\n39\n60",
"output": "385.6666667"
},
{
"input": "538\n479\n416",
"output": "287.9351955"
},
{
"input": "583\n112\n248",
"output": "181.3777778"
},
{
"input": "978\n467\n371",
"output": "545.0190931"
},
{
"input": "980\n322\n193",
"output": "612.7378641"
},
{
"input": "871\n401\n17",
"output": "835.576555"
},
{
"input": "349\n478\n378",
"output": "194.885514"
},
{
"input": "425\n458\n118",
"output": "337.9340278"
},
{
"input": "919\n323\n458",
"output": "380.0729834"
},
{
"input": "188\n59\n126",
"output": "59.95675676"
},
{
"input": "644\n428\n484",
"output": "302.2280702"
},
{
"input": "253\n80\n276",
"output": "56.85393258"
},
{
"input": "745\n152\n417",
"output": "199.0158172"
},
{
"input": "600\n221\n279",
"output": "265.2"
},
{
"input": "690\n499\n430",
"output": "370.6243272"
},
{
"input": "105\n68\n403",
"output": "15.15923567"
},
{
"input": "762\n462\n371",
"output": "422.6218487"
},
{
"input": "903\n460\n362",
"output": "505.3284672"
},
{
"input": "886\n235\n95",
"output": "630.9393939"
},
{
"input": "655\n203\n18",
"output": "601.6515837"
},
{
"input": "718\n29\n375",
"output": "51.53960396"
},
{
"input": "296\n467\n377",
"output": "163.7819905"
},
{
"input": "539\n61\n56",
"output": "281.017094"
},
{
"input": "133\n53\n124",
"output": "39.82485876"
},
{
"input": "998\n224\n65",
"output": "773.5363322"
},
{
"input": "961\n173\n47",
"output": "755.6954545"
},
{
"input": "285\n468\n62",
"output": "251.6603774"
},
{
"input": "496\n326\n429",
"output": "214.1668874"
},
{
"input": "627\n150\n285",
"output": "216.2068966"
},
{
"input": "961\n443\n50",
"output": "863.535497"
},
{
"input": "623\n422\n217",
"output": "411.4334898"
},
{
"input": "678\n295\n29",
"output": "617.3148148"
}
] | 1,624,114,050 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | l = int(input())
p = int(input())
q = int(input())
if p*(p+q)/l == int(p*(p+q)/l):
print(int(p*(p+q)/l))
else:
print(p*(p+q)/l) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
Input Specification:
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Output Specification:
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['100\n50\n50\n', '199\n60\n40\n']
Demo Output:
['50\n', '119.4\n']
Note:
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | ```python
l = int(input())
p = int(input())
q = int(input())
if p*(p+q)/l == int(p*(p+q)/l):
print(int(p*(p+q)/l))
else:
print(p*(p+q)/l)
``` | 0 |
|
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
"output": "18"
},
{
"input": "z\na",
"output": "2"
},
{
"input": "ama\nsama",
"output": "1"
},
{
"input": "aaabc\nbc",
"output": "3"
},
{
"input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa",
"output": "32"
},
{
"input": "ahmedaly\naly",
"output": "5"
},
{
"input": "aa\na",
"output": "1"
},
{
"input": "aa\nba",
"output": "2"
},
{
"input": "cccba\nba",
"output": "3"
},
{
"input": "a\nab",
"output": "3"
},
{
"input": "dadc\ndddc",
"output": "4"
},
{
"input": "aacaaab\nb",
"output": "6"
},
{
"input": "dddc\ncdcde",
"output": "9"
},
{
"input": "bbdab\ndab",
"output": "2"
},
{
"input": "a\naa",
"output": "1"
},
{
"input": "aa\nab",
"output": "4"
},
{
"input": "codeforces\nces",
"output": "7"
}
] | 1,644,765,815 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 9,728,000 | s1 = input()
s2 = input()
n = 0
i = 0
j = 0
while(s1[i:]!=s2[j:]):
if(len(s1[i:]) > len(s2[j:])):
i+=1
elif(len(s2[j:]) > len(s1[i:])):
j+=1
else:
i+=1
j+=1
n+=1
n+=1
print(n) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
Input Specification:
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output Specification:
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
Demo Input:
['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n']
Demo Output:
['2\n', '9\n', '7\n', '1\n']
Note:
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | ```python
s1 = input()
s2 = input()
n = 0
i = 0
j = 0
while(s1[i:]!=s2[j:]):
if(len(s1[i:]) > len(s2[j:])):
i+=1
elif(len(s2[j:]) > len(s1[i:])):
j+=1
else:
i+=1
j+=1
n+=1
n+=1
print(n)
``` | 0 |
|
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 1,688,843,494 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | n = input()
n = int(n)
if n % 100 == 0:
bill = n // 100
elif n % 20 == 0:
bill = n // 20
if n - (n//100) < 5:
bill += n - (n//100)
elif n % 10 == 0:
bill = (n // 100) + 1
elif n % 5 == 0:
bill = (n // 100) + 2
else:
bill = (n // 20 )+3
print(bill)
| Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input Specification:
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output Specification:
Output the minimum number of bills that Allen could receive.
Demo Input:
['125\n', '43\n', '1000000000\n']
Demo Output:
['3\n', '5\n', '10000000\n']
Note:
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | ```python
n = input()
n = int(n)
if n % 100 == 0:
bill = n // 100
elif n % 20 == 0:
bill = n // 20
if n - (n//100) < 5:
bill += n - (n//100)
elif n % 10 == 0:
bill = (n // 100) + 1
elif n % 5 == 0:
bill = (n // 100) + 2
else:
bill = (n // 20 )+3
print(bill)
``` | 0 |
|
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match. | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
},
{
"input": "4 5 4 5",
"output": "0.833333333333"
},
{
"input": "466 701 95 721",
"output": "0.937693791148"
},
{
"input": "268 470 444 885",
"output": "0.725614009325"
},
{
"input": "632 916 713 821",
"output": "0.719292895126"
},
{
"input": "269 656 918 992",
"output": "0.428937461623"
},
{
"input": "71 657 187 695",
"output": "0.310488463257"
},
{
"input": "435 852 973 978",
"output": "0.511844133157"
},
{
"input": "518 816 243 359",
"output": "0.719734031025"
},
{
"input": "882 962 311 811",
"output": "0.966386645447"
},
{
"input": "684 774 580 736",
"output": "0.906051574446"
},
{
"input": "486 868 929 999",
"output": "0.577723252958"
},
{
"input": "132 359 996 998",
"output": "0.368154532345"
},
{
"input": "933 977 266 450",
"output": "0.972879407907"
},
{
"input": "298 833 615 872",
"output": "0.441270817024"
},
{
"input": "34 554 14 958",
"output": "0.817324099167"
},
{
"input": "836 934 800 905",
"output": "0.906105535462"
},
{
"input": "482 815 69 509",
"output": "0.914365577772"
},
{
"input": "284 423 137 521",
"output": "0.885974839378"
},
{
"input": "648 881 486 703",
"output": "0.800911421248"
},
{
"input": "450 885 755 836",
"output": "0.533901011176"
},
{
"input": "533 773 823 998",
"output": "0.729222130525"
},
{
"input": "897 957 92 898",
"output": "0.993193806364"
},
{
"input": "699 925 441 928",
"output": "0.866816866175"
},
{
"input": "64 704 148 603",
"output": "0.289486317811"
},
{
"input": "719 735 626 990",
"output": "0.986124079764"
},
{
"input": "1 1000 1 1000",
"output": "0.500250125063"
}
] | 1,602,871,297 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 108 | 0 | entrada = input()
itens = entrada.split()
a, b, c, d = float(itens[0]), int(itens[1]), int(itens[2]), int(itens[3])
prob_win_sr = a/b
prob_win_zn = c/d
prob_failure = (1-prob_win_sr) * (1-prob_win_zn)
result = prob_win_sr/(1-prob_failure)
print(result)
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match.
Input Specification:
A single line contains four integers .
Output Specification:
Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['1 2 1 2\n']
Demo Output:
['0.666666666667']
Note:
none | ```python
entrada = input()
itens = entrada.split()
a, b, c, d = float(itens[0]), int(itens[1]), int(itens[2]), int(itens[3])
prob_win_sr = a/b
prob_win_zn = c/d
prob_failure = (1-prob_win_sr) * (1-prob_win_zn)
result = prob_win_sr/(1-prob_failure)
print(result)
``` | 3 |
|
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,692,667,938 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | def read_numbers() -> list[int]:
return [int(n) for n in input().split()]
n, k = read_numbers()
j = read_numbers()
new_sum = None
new_index = None
for a in range(n - k + 1):
s = 0
for b in range(k):
s += j[a + b]
if new_sum is None or s < new_sum:
new_sum = s
new_index = a +1
print(new_index)
| 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
def read_numbers() -> list[int]:
return [int(n) for n in input().split()]
n, k = read_numbers()
j = read_numbers()
new_sum = None
new_index = None
for a in range(n - k + 1):
s = 0
for b in range(k):
s += j[a + b]
if new_sum is None or s < new_sum:
new_sum = s
new_index = a +1
print(new_index)
``` | -1 |
|
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,641,984,740 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 0 | word=input()
u=0
l=0
for char in word:
if char.isupper():
u=u+1
else:
l=l+1
if u>l:
word=word.upper()
else:
word=word.lower()
print(word)
| 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
word=input()
u=0
l=0
for char in word:
if char.isupper():
u=u+1
else:
l=l+1
if u>l:
word=word.upper()
else:
word=word.lower()
print(word)
``` | 3.9615 |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
},
{
"input": "6 2\nABCABC",
"output": "YES"
},
{
"input": "8 3\nABCBCDCA",
"output": "NO"
},
{
"input": "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD",
"output": "YES"
},
{
"input": "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA",
"output": "NO"
},
{
"input": "41 19\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP",
"output": "NO"
},
{
"input": "377 3\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE",
"output": "YES"
},
{
"input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG",
"output": "YES"
},
{
"input": "5 2\nABCAB",
"output": "YES"
},
{
"input": "5 1\nAZAZA",
"output": "YES"
},
{
"input": "7 2\nABCDBCD",
"output": "YES"
},
{
"input": "3 26\nAAB",
"output": "NO"
}
] | 1,501,427,862 | 2,562 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 4,608,000 | def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))
alf = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split()
n, guard = rli()
s = rls()
check = [0 for i in range(n)]
for k in range(26):
for j in range(n):
if(s[j] == alf[k]):
check[j] += 1
break
for j in range(1, n+1):
if(s[-j] == alf[k]):
check[-j] -= 1
break
for i in range(1, n):
check[i] = check[i-1] + check[i]
print("YES" if max(check) > guard else "NO") | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened.
Input Specification:
Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest.
Output Specification:
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['5 1\nAABBB\n', '5 1\nABABB\n']
Demo Output:
['NO\n', 'YES\n']
Note:
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | ```python
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))
alf = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split()
n, guard = rli()
s = rls()
check = [0 for i in range(n)]
for k in range(26):
for j in range(n):
if(s[j] == alf[k]):
check[j] += 1
break
for j in range(1, n+1):
if(s[-j] == alf[k]):
check[-j] -= 1
break
for i in range(1, n):
check[i] = check[i-1] + check[i]
print("YES" if max(check) > guard else "NO")
``` | 0 |
|
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 1,607,675,373 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = int(input())
b = list(map(int, str(input()).split()))
g = b[0:len(b):3]
b = b[1:len(b):3]
s = b{2:len(b):3]
r = [sum(g), sum(b), sum(s)]
if max(r) == sum(g):
print("chest")
elif max(r) == sum(b):
print("back")
else:
print("biceps") | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Output Specification:
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Demo Input:
['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n']
Demo Output:
['biceps\n', 'back\n', 'chest\n']
Note:
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | ```python
a = int(input())
b = list(map(int, str(input()).split()))
g = b[0:len(b):3]
b = b[1:len(b):3]
s = b{2:len(b):3]
r = [sum(g), sum(b), sum(s)]
if max(r) == sum(g):
print("chest")
elif max(r) == sum(b):
print("back")
else:
print("biceps")
``` | -1 |
|
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected? | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428",
"output": "25720377\n661369649"
},
{
"input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482",
"output": "819602309\n796067435"
},
{
"input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780",
"output": "374054998\n902899520"
},
{
"input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990",
"output": "939116221\n323703261"
},
{
"input": "3\n77 77 77\n77 77\n77",
"output": "77\n77"
},
{
"input": "3\n84 30 9\n9 84\n9",
"output": "30\n84"
},
{
"input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3",
"output": "5\n5"
},
{
"input": "4\n1 5 7 8\n1 5 7\n1 5",
"output": "8\n7"
}
] | 1,656,986,009 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 217 | 23,552,000 | n = int(input())
# n, m = map(int, input().split())
arr = sorted(list(map(int, input().split())))
arr2 = sorted(list(map(int, input().split())))
arr3 = sorted(list(map(int, input().split())))
for i in range(n):
if i == n-1:
print(arr[i])
break
if arr[i] != arr2[i]:
print(arr[i])
break
for i in range(n-1):
if i == n - 2:
print(arr2[i])
break
if arr2[i] != arr3[i]:
print(arr2[i])
break | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output Specification:
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Demo Input:
['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n']
Demo Output:
['8\n123\n', '1\n3\n']
Note:
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | ```python
n = int(input())
# n, m = map(int, input().split())
arr = sorted(list(map(int, input().split())))
arr2 = sorted(list(map(int, input().split())))
arr3 = sorted(list(map(int, input().split())))
for i in range(n):
if i == n-1:
print(arr[i])
break
if arr[i] != arr2[i]:
print(arr[i])
break
for i in range(n-1):
if i == n - 2:
print(arr2[i])
break
if arr2[i] != arr3[i]:
print(arr2[i])
break
``` | 3 |
|
776 | C | Molly's Chemicals | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"data structures",
"implementation",
"math"
] | null | null | Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of *k*. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments. | The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=≤<=*n*<=≤<=105, 1<=≤<=|*k*|<=≤<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — affection values of chemicals. | Output a single integer — the number of valid segments. | [
"4 2\n2 2 2 2\n",
"4 -3\n3 -6 -3 12\n"
] | [
"8\n",
"3\n"
] | Do keep in mind that *k*<sup class="upper-index">0</sup> = 1.
In the first sample, Molly can get following different affection values:
- 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; - 4: segments [1, 2], [2, 3], [3, 4]; - 6: segments [1, 3], [2, 4]; - 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of *k* = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | 1,500 | [
{
"input": "4 2\n2 2 2 2",
"output": "8"
},
{
"input": "4 -3\n3 -6 -3 12",
"output": "3"
},
{
"input": "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39",
"output": "0"
},
{
"input": "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85",
"output": "1"
},
{
"input": "89 -7\n5972 4011 3914 670 3727 2913 6935 6927 2118 6645 7141 3585 9811 2859 459 8870 6578 8667 468 5152 3241 7455 7323 8817 4866 1040 5102 9146 621 5002 396 4967 9822 4200 3899 4416 5225 9415 9606 4802 5589 1798 9094 5453 7163 264 1026 6187 3918 4237 -17 4306 8960 3321 2927 9205 6248 7607 564 364 3503 8149 2235 8278 6249 3987 524 5718 9359 3549 1474 9204 3870 6996 3932 8295 612 6310 4461 1129 6441 3465 4654 7583 3274 6309 4831 4918 558",
"output": "0"
},
{
"input": "10 2\n2 4 8 16 32 64 128 256 512 1024",
"output": "10"
},
{
"input": "10 1\n-1 1 -1 1 -1 1 -1 1 -1 1",
"output": "15"
},
{
"input": "32 2\n8 16384 32768 65536 32 8388608 1048576 16777216 65536 8 16384 128 2097152 1024 16777216 4 8192 8388608 65536 1024 1024 16 8 16 128 2 1024 128 8 33554432 32768 2048",
"output": "33"
},
{
"input": "1 2\n2",
"output": "1"
},
{
"input": "14 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "45"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "4 1\n1 1 1 1",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 -1\n1 0 -1 1 0 -1 1 0 -1 1",
"output": "28"
},
{
"input": "4 1\n-1 -2 3 1",
"output": "3"
},
{
"input": "26 -1\n0 0 1 1 -1 -1 0 0 1 0 0 0 -1 1 0 0 -1 1 -1 1 -1 1 0 0 5 -4",
"output": "168"
},
{
"input": "1 -1\n-1",
"output": "1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "1 2\n1048576",
"output": "1"
},
{
"input": "4 -1\n1 1 1 1",
"output": "4"
},
{
"input": "5 -1\n1 1 1 1 1",
"output": "5"
},
{
"input": "33 2\n536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912",
"output": "141"
},
{
"input": "1 1\n-1",
"output": "0"
}
] | 1,667,602,764 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 2,500 | 407,961,600 | def solve(v, a):
mp = {}
mp[0]=1
tmp=0
ans=0
for i in v:
tmp+=i
if a==1:
if tmp-1 in mp:
ans+=mp[tmp-1]
else:
ans+=0
mp[tmp-1]=0
elif a==-1:
if tmp-1 in mp:
ans+=mp[tmp-1]
else:
ans+=0
mp[tmp-1]=0
if tmp+1 in mp:
ans+=mp[tmp+1]
else:
ans+=0
mp[tmp+1]=0
else:
cur=1
while True:
if tmp-cur in mp:
ans+=mp[tmp-cur]
else:
mp[tmp-cur]=0
cur*=a
if cur>10**15 or -cur>10**15:
break
if tmp in mp:
mp[tmp]+=1
else:
mp[tmp]=1
return ans
n,a=map(int,input().split())
v=list(map(int,input().split()))
print(solve(v,a))
| Title: Molly's Chemicals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of *k*. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input Specification:
The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=≤<=*n*<=≤<=105, 1<=≤<=|*k*|<=≤<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — affection values of chemicals.
Output Specification:
Output a single integer — the number of valid segments.
Demo Input:
['4 2\n2 2 2 2\n', '4 -3\n3 -6 -3 12\n']
Demo Output:
['8\n', '3\n']
Note:
Do keep in mind that *k*<sup class="upper-index">0</sup> = 1.
In the first sample, Molly can get following different affection values:
- 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; - 4: segments [1, 2], [2, 3], [3, 4]; - 6: segments [1, 3], [2, 4]; - 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of *k* = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | ```python
def solve(v, a):
mp = {}
mp[0]=1
tmp=0
ans=0
for i in v:
tmp+=i
if a==1:
if tmp-1 in mp:
ans+=mp[tmp-1]
else:
ans+=0
mp[tmp-1]=0
elif a==-1:
if tmp-1 in mp:
ans+=mp[tmp-1]
else:
ans+=0
mp[tmp-1]=0
if tmp+1 in mp:
ans+=mp[tmp+1]
else:
ans+=0
mp[tmp+1]=0
else:
cur=1
while True:
if tmp-cur in mp:
ans+=mp[tmp-cur]
else:
mp[tmp-cur]=0
cur*=a
if cur>10**15 or -cur>10**15:
break
if tmp in mp:
mp[tmp]+=1
else:
mp[tmp]=1
return ans
n,a=map(int,input().split())
v=list(map(int,input().split()))
print(solve(v,a))
``` | 0 |
|
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:
- Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
The program cannot delete the letters from the list or rearrange them.
Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already read. | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0",
"output": "11"
},
{
"input": "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1",
"output": "23"
},
{
"input": "27\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0",
"output": "25"
},
{
"input": "10\n1 0 0 0 0 1 0 0 0 1",
"output": "5"
},
{
"input": "10\n1 0 0 1 0 0 1 1 0 1",
"output": "8"
},
{
"input": "27\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",
"output": "0"
},
{
"input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1",
"output": "39"
},
{
"input": "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1",
"output": "39"
},
{
"input": "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0",
"output": "59"
},
{
"input": "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1",
"output": "99"
},
{
"input": "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1",
"output": "99"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99"
},
{
"input": "193\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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",
"output": "1"
},
{
"input": "213\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 0 0 0 0 0 0 0 0 0 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 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "5"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n0 0 0 0 1",
"output": "1"
},
{
"input": "12\n0 1 1 0 1 1 0 1 1 0 0 0",
"output": "8"
},
{
"input": "3\n1 0 0",
"output": "1"
},
{
"input": "5\n0 0 1 0 0",
"output": "1"
},
{
"input": "3\n0 1 0",
"output": "1"
},
{
"input": "6\n1 1 0 0 0 0",
"output": "2"
},
{
"input": "4\n0 1 0 0",
"output": "1"
},
{
"input": "5\n1 1 1 0 0",
"output": "3"
},
{
"input": "4\n1 0 0 0",
"output": "1"
},
{
"input": "6\n1 1 1 1 0 0",
"output": "4"
}
] | 1,614,386,373 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 307,200 | n = int(input())
L = list(map(int, input().split()))
if L.count(1) == 0:
print(0)
elif L.count(1) == 1:
print(1)
else:
begin = L.index(1)
end = -(L[::-1].index(1) + 1)
if end == -1:
end = -2
L = L[begin:end + 1]
total = len(L)
count = 0
for x in range(len(L) - 1):
if L[x] == L[x + 1] == 0:
count += 1
elif count != 0:
total -= count
count = 0
print(total)
| Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:
- Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
The program cannot delete the letters from the list or rearrange them.
Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Output Specification:
Print a single number — the minimum number of operations needed to make all the letters read.
Demo Input:
['5\n0 1 0 1 0\n', '5\n1 1 0 0 1\n', '2\n0 0\n']
Demo Output:
['3\n', '4\n', '0\n']
Note:
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already read. | ```python
n = int(input())
L = list(map(int, input().split()))
if L.count(1) == 0:
print(0)
elif L.count(1) == 1:
print(1)
else:
begin = L.index(1)
end = -(L[::-1].index(1) + 1)
if end == -1:
end = -2
L = L[begin:end + 1]
total = len(L)
count = 0
for x in range(len(L) - 1):
if L[x] == L[x + 1] == 0:
count += 1
elif count != 0:
total -= count
count = 0
print(total)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,669,113,806 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s = input()
up = []
low = []
for i in list(s):
if i.isupper():
up.append(i)
else:
low.append(i)
if len(up)>len(low):
print(s.upper())
elif len(up)<len(low):
print(s.lower())
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()
up = []
low = []
for i in list(s):
if i.isupper():
up.append(i)
else:
low.append(i)
if len(up)>len(low):
print(s.upper())
elif len(up)<len(low):
print(s.lower())
else:
print(s.lower())
``` | 3.977 |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob? | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "4"
},
{
"input": "1 6",
"output": "5"
},
{
"input": "1 7",
"output": "5"
},
{
"input": "1 8",
"output": "6"
},
{
"input": "1 9",
"output": "6"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "2 4",
"output": "2"
},
{
"input": "2 5",
"output": "3"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "4"
},
{
"input": "2 8",
"output": "4"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "2 10",
"output": "4"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "3 4",
"output": "1"
},
{
"input": "3 5",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "3"
},
{
"input": "3 8",
"output": "3"
},
{
"input": "3 9",
"output": "3"
},
{
"input": "3 10",
"output": "3"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "4 10",
"output": "3"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "1"
},
{
"input": "5 7",
"output": "1"
},
{
"input": "5 8",
"output": "2"
},
{
"input": "5 9",
"output": "2"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "6 9",
"output": "2"
},
{
"input": "6 10",
"output": "2"
},
{
"input": "7 7",
"output": "1"
},
{
"input": "7 8",
"output": "1"
},
{
"input": "7 9",
"output": "1"
},
{
"input": "7 10",
"output": "1"
},
{
"input": "8 8",
"output": "1"
},
{
"input": "8 9",
"output": "1"
},
{
"input": "8 10",
"output": "1"
},
{
"input": "9 9",
"output": "1"
},
{
"input": "9 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "1 2",
"output": "2"
}
] | 1,698,593,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | a,b=map(int,input().split())
c=0
if a==b:
print(1)
else:
for i in range(b):
a=(3*a)
b=(2*b)
c+=1
if a>b:
break
print(c) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Output Specification:
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
Demo Input:
['4 7\n', '4 9\n', '1 1\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | ```python
a,b=map(int,input().split())
c=0
if a==b:
print(1)
else:
for i in range(b):
a=(3*a)
b=(2*b)
c+=1
if a>b:
break
print(c)
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,632,755,482 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 6,758,400 | a = input()
b = input()
c = ''
for i in reversed(range(len(a))):
c += a[i]
if b == c:
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
a = input()
b = input()
c = ''
for i in reversed(range(len(a))):
c += a[i]
if b == c:
print('YES')
else:
print('NO')
``` | 3.956411 |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "52"
},
{
"input": "2\nAA",
"output": "1"
},
{
"input": "4\nqqqE",
"output": "2"
},
{
"input": "10\nrrrrroooro",
"output": "2"
},
{
"input": "15\nOCOCCCCiCOCCCOi",
"output": "3"
},
{
"input": "20\nVEVnVVnWnVEVVnEVBEWn",
"output": "5"
},
{
"input": "25\ncpcyPPjPPcPPPPcppPcPpppcP",
"output": "6"
},
{
"input": "30\nsssssAsesssssssssssssessssssss",
"output": "3"
},
{
"input": "35\ngdXdddgddddddddggggXdbgdggdgddddddb",
"output": "4"
},
{
"input": "40\nIgsggIiIggzgigIIiiIIIiIgIggIzgIiiiggggIi",
"output": "9"
},
{
"input": "45\neteeeeeteaattaeetaetteeettoetettteyeteeeotaae",
"output": "9"
},
{
"input": "50\nlUlUllUlUllllUllllUllllUlUlllUlllUlllllUUlllUUlkUl",
"output": "3"
},
{
"input": "55\nAAAAASAAAASAASAAAAAAAAAAAAASAAAAAAAAAAAAAAAASAAAAAAAAAA",
"output": "2"
},
{
"input": "60\nRRRrSRRRRRRRRRSSRRRSRRRRRRRRrRSRRRRRRRRRRRRRRSRRRRRSSRSRrRRR",
"output": "3"
},
{
"input": "65\nhhMhMhhhhhhhhhhhMhhMMMhhhhBhhhhMhhhhMhhhhhMhhhBhhhhhhhhhhBhhhhhhh",
"output": "5"
},
{
"input": "70\nwAwwwAwwwwwwwwwwwwwwAwAAwwAwwwwwwwwAwAAAwAAwwwwwwwwwAwwwwwwwwwwwwAAwww",
"output": "2"
},
{
"input": "75\niiiXXiiyiiiXyXiiyXiiXiiiiiiXXyiiiiXXiiXiiXifiXiXXiifiiiiiiXfXiyiXXiXiiiiXiX",
"output": "4"
},
{
"input": "80\nSrSrrrrrrrrrrrrrrSSSrrrrrrSrrrrSrrrrrrrrrrSSrrrrrrrrrrrSrrrSrrrrSrrrrSrrrrSSrSSr",
"output": "2"
},
{
"input": "85\nwkMMMwMMkMMMMMMMkkkkMMMMzkkMMwMMkkwMkMwkMMkMMwwMzMMMkkMwwMMMMMMkMMkMzMMMkMMkwMkMMMkMM",
"output": "6"
},
{
"input": "90\nZllZZZyZlZlllZlylllZlllZZllllllllZZllllllllllyylZZyvZvZlllZZlZllZlZlllZyllZyZlllZlllllllZl",
"output": "5"
},
{
"input": "95\nEmuBuEBmmEBBElBlElmmBEmmmEmmEuBEEmummmEmBBBBEWBBBmEEBmmummBBmmlluBBmElmEBEmBmBBmBmuLmEBBmlEBmBu",
"output": "39"
},
{
"input": "100\nfAfhfNNNhfffAfNffNANhffNffffffNfffffhNfffNfffNfffNfNNNffNfffNfhNNNffffNfNfffAffNffNffNNfhfffNhNffNNN",
"output": "4"
},
{
"input": "7\nabcbbab",
"output": "3"
},
{
"input": "65\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjkkkkkkkkkkkkkkkkkkkllllllljk",
"output": "3"
},
{
"input": "9\nbcdddbddc",
"output": "3"
},
{
"input": "71\nlqcrdopdpfagcilpcmheqhjbmnciqmeoabflrenbkrsaabaanpehdmpqcdqnljcrsplnlco",
"output": "36"
},
{
"input": "8\nabbbbbbc",
"output": "8"
}
] | 1,627,492,682 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 6,963,200 | from itertools import combinations
N = int(input())
string = input()
uniquePokemons = set(string)
if uniquePokemons == N:
print(N)
else:
left = 0
right = N-1
ans = N
while right >= left:
middle = (right + left) // 2
for i in [string[x:y] for x, y in combinations(range(len(string) + 1), r = 2) if len(string[x:y]) == middle ]:
if set(i) == uniquePokemons:
ans = min( len(i), ans)
right = middle - 1
else:
left = middle + 1
print(ans)
| Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
Output Specification:
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
Demo Input:
['3\nAaA\n', '7\nbcAAcbc\n', '6\naaBCCe\n']
Demo Output:
['2\n', '3\n', '5\n']
Note:
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | ```python
from itertools import combinations
N = int(input())
string = input()
uniquePokemons = set(string)
if uniquePokemons == N:
print(N)
else:
left = 0
right = N-1
ans = N
while right >= left:
middle = (right + left) // 2
for i in [string[x:y] for x, y in combinations(range(len(string) + 1), r = 2) if len(string[x:y]) == middle ]:
if set(i) == uniquePokemons:
ans = min( len(i), ans)
right = middle - 1
else:
left = middle + 1
print(ans)
``` | 0 |
|
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "2",
"output": "22"
},
{
"input": "3",
"output": "33"
},
{
"input": "4",
"output": "44"
},
{
"input": "5",
"output": "55"
},
{
"input": "6",
"output": "66"
},
{
"input": "7",
"output": "77"
},
{
"input": "8",
"output": "88"
},
{
"input": "9",
"output": "99"
},
{
"input": "13",
"output": "1331"
},
{
"input": "14",
"output": "1441"
},
{
"input": "15",
"output": "1551"
},
{
"input": "16",
"output": "1661"
},
{
"input": "17",
"output": "1771"
},
{
"input": "18",
"output": "1881"
},
{
"input": "19",
"output": "1991"
},
{
"input": "20",
"output": "2002"
},
{
"input": "26550",
"output": "2655005562"
},
{
"input": "16137",
"output": "1613773161"
},
{
"input": "91471",
"output": "9147117419"
},
{
"input": "41242",
"output": "4124224214"
},
{
"input": "30866",
"output": "3086666803"
},
{
"input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116",
"output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444"
},
{
"input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252",
"output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087"
},
{
"input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913",
"output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422"
},
{
"input": "123451",
"output": "123451154321"
}
] | 1,607,690,948 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 512,000 | n = input()
rev = n[::-1]
op = n + rev
print(int(op)) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Output Specification:
Print the *n*-th even-length palindrome number.
Demo Input:
['1\n', '10\n']
Demo Output:
['11\n', '1001\n']
Note:
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | ```python
n = input()
rev = n[::-1]
op = n + rev
print(int(op))
``` | 0 |
|
777 | D | Cloud of Hashtags | PROGRAMMING | 1,800 | [
"binary search",
"greedy",
"implementation",
"strings"
] | null | null | Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of hashtags being edited now.
Each of the next *n* lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500<=000. | Print the resulting hashtags in any of the optimal solutions. | [
"3\n#book\n#bigtown\n#big\n",
"3\n#book\n#cool\n#cold\n",
"4\n#car\n#cart\n#art\n#at\n",
"3\n#apple\n#apple\n#fruit\n"
] | [
"#b\n#big\n#big\n",
"#book\n#co\n#cold\n",
"#\n#\n#art\n#at\n",
"#apple\n#apple\n#fruit\n"
] | Word *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*m*</sub> of length *m* is lexicographically not greater than word *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*k*</sub> of length *k*, if one of two conditions hold:
- at first position *i*, such that *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>, the character *a*<sub class="lower-index">*i*</sub> goes earlier in the alphabet than character *b*<sub class="lower-index">*i*</sub>, i.e. *a* has smaller character than *b* in the first position where they differ; - if there is no such position *i* and *m* ≤ *k*, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two. | 2,000 | [
{
"input": "3\n#book\n#bigtown\n#big",
"output": "#b\n#big\n#big"
},
{
"input": "3\n#book\n#cool\n#cold",
"output": "#book\n#co\n#cold"
},
{
"input": "4\n#car\n#cart\n#art\n#at",
"output": "#\n#\n#art\n#at"
},
{
"input": "3\n#apple\n#apple\n#fruit",
"output": "#apple\n#apple\n#fruit"
},
{
"input": "1\n#h",
"output": "#h"
},
{
"input": "2\n#y\n#q",
"output": "#\n#q"
},
{
"input": "3\n#sima\n#simb\n#sima",
"output": "#sim\n#sim\n#sima"
},
{
"input": "1\n#lxqnqdnkpeayhxh",
"output": "#lxqnqdnkpeayhxh"
},
{
"input": "6\n#abu\n#abc\n#ac\n#bk\n#bmm\n#bb",
"output": "#ab\n#abc\n#ac\n#b\n#b\n#bb"
},
{
"input": "7\n#a\n#aab\n#abc\n#abq\n#ab\n#ac\n#z",
"output": "#a\n#aab\n#ab\n#ab\n#ab\n#ac\n#z"
},
{
"input": "15\n#a\n#a\n#b\n#c\n#e\n#i\n#k\n#m\n#o\n#r\n#u\n#v\n#w\n#w\n#e",
"output": "#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#e"
},
{
"input": "5\n#abcde\n#abcd\n#abc\n#ab\n#a",
"output": "#a\n#a\n#a\n#a\n#a"
},
{
"input": "5\n#xyz\n#yzx\n#zzxy\n#zzy\n#yz",
"output": "#\n#\n#\n#\n#yz"
},
{
"input": "15\n#a\n#b\n#c\n#c\n#f\n#h\n#i\n#j\n#l\n#l\n#q\n#q\n#u\n#z\n#z",
"output": "#a\n#b\n#c\n#c\n#f\n#h\n#i\n#j\n#l\n#l\n#q\n#q\n#u\n#z\n#z"
},
{
"input": "6\n#jgpajxhyrlbnpcfkklkfjflexcbhza\n#jgpajxhyrlbnpcfkklkfjflexcbhz\n#jgpajxhyrlbnpcfkklkfjflexcb\n#jgpajxhyrlbnpcfkklkfjflex\n#jgpajxhyrlbnpcfkklkfjf\n#jgpajxhyrlbnpcfkk",
"output": "#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk"
},
{
"input": "37\n#dut\n#du\n#du\n#dxzd\n#dxz\n#dxz\n#dyyr\n#dyy\n#dyy\n#dzuo\n#dzu\n#dzu\n#wldl\n#wld\n#wl\n#wl\n#xeuu\n#xeu\n#xe\n#xe\n#ytki\n#ytk\n#yt\n#yt\n#yvbn\n#yvb\n#yvb\n#zvip\n#zvi\n#zv\n#zv\n#zzag\n#zza\n#zza\n#zznz\n#zznz\n#zzo",
"output": "#du\n#du\n#du\n#dxz\n#dxz\n#dxz\n#dyy\n#dyy\n#dyy\n#dzu\n#dzu\n#dzu\n#wl\n#wl\n#wl\n#wl\n#xe\n#xe\n#xe\n#xe\n#yt\n#yt\n#yt\n#yt\n#yvb\n#yvb\n#yvb\n#zv\n#zv\n#zv\n#zv\n#zza\n#zza\n#zza\n#zznz\n#zznz\n#zzo"
},
{
"input": "2\n#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab\n#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
] | 1,618,119,573 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 40 | 2,000 | 19,558,400 | n = int(input())
p = [input() for _ in range(n)]
for i in range(n - 2, -1, -1):
while p[i] > p[i + 1]:
p[i] = p[i][:-1]
for el in p:
print(el) | Title: Cloud of Hashtags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of hashtags being edited now.
Each of the next *n* lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500<=000.
Output Specification:
Print the resulting hashtags in any of the optimal solutions.
Demo Input:
['3\n#book\n#bigtown\n#big\n', '3\n#book\n#cool\n#cold\n', '4\n#car\n#cart\n#art\n#at\n', '3\n#apple\n#apple\n#fruit\n']
Demo Output:
['#b\n#big\n#big\n', '#book\n#co\n#cold\n', '#\n#\n#art\n#at\n', '#apple\n#apple\n#fruit\n']
Note:
Word *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*m*</sub> of length *m* is lexicographically not greater than word *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*k*</sub> of length *k*, if one of two conditions hold:
- at first position *i*, such that *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>, the character *a*<sub class="lower-index">*i*</sub> goes earlier in the alphabet than character *b*<sub class="lower-index">*i*</sub>, i.e. *a* has smaller character than *b* in the first position where they differ; - if there is no such position *i* and *m* ≤ *k*, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two. | ```python
n = int(input())
p = [input() for _ in range(n)]
for i in range(n - 2, -1, -1):
while p[i] > p[i + 1]:
p[i] = p[i][:-1]
for el in p:
print(el)
``` | 0 |
|
898 | B | Proper Nutrition | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"number theory"
] | null | null | Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles.
In other words, you should find two non-negative integers *x* and *y* such that Vasya can buy *x* bottles of Ber-Cola and *y* Bars bars and *x*·*a*<=+<=*y*·*b*<==<=*n* or tell that it's impossible. | First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has.
Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola.
Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar. | If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly *n* burles, i.e. *x*·*a*<=+<=*y*·*b*<==<=*n*. If there are multiple answers print any of them.
Any of numbers *x* and *y* can be equal 0. | [
"7\n2\n3\n",
"100\n25\n10\n",
"15\n4\n8\n",
"9960594\n2551\n2557\n"
] | [
"YES\n2 1\n",
"YES\n0 10\n",
"NO\n",
"YES\n1951 1949\n"
] | In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly *n* burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola and buy 10 Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles. | 750 | [
{
"input": "7\n2\n3",
"output": "YES\n2 1"
},
{
"input": "100\n25\n10",
"output": "YES\n0 10"
},
{
"input": "15\n4\n8",
"output": "NO"
},
{
"input": "9960594\n2551\n2557",
"output": "YES\n1951 1949"
},
{
"input": "10000000\n1\n1",
"output": "YES\n0 10000000"
},
{
"input": "9999999\n9999\n9999",
"output": "NO"
},
{
"input": "9963629\n2591\n2593",
"output": "YES\n635 3208"
},
{
"input": "1\n7\n8",
"output": "NO"
},
{
"input": "9963630\n2591\n2593",
"output": "YES\n1931 1913"
},
{
"input": "7516066\n1601\n4793",
"output": "YES\n4027 223"
},
{
"input": "6509546\n1607\n6221",
"output": "YES\n617 887"
},
{
"input": "2756250\n8783\n29",
"output": "YES\n21 88683"
},
{
"input": "7817510\n2377\n743",
"output": "YES\n560 8730"
},
{
"input": "6087210\n1583\n1997",
"output": "YES\n1070 2200"
},
{
"input": "4\n2\n2",
"output": "YES\n0 2"
},
{
"input": "7996960\n4457\n5387",
"output": "YES\n727 883"
},
{
"input": "7988988\n4021\n3169",
"output": "YES\n1789 251"
},
{
"input": "4608528\n9059\n977",
"output": "YES\n349 1481"
},
{
"input": "8069102\n2789\n47",
"output": "YES\n3 171505"
},
{
"input": "3936174\n4783\n13",
"output": "YES\n5 300943"
},
{
"input": "10000000\n9999999\n1",
"output": "YES\n0 10000000"
},
{
"input": "10000000\n1\n9999999",
"output": "YES\n1 1"
},
{
"input": "4\n1\n3",
"output": "YES\n1 1"
},
{
"input": "4\n1\n2",
"output": "YES\n0 2"
},
{
"input": "4\n3\n1",
"output": "YES\n0 4"
},
{
"input": "4\n2\n1",
"output": "YES\n0 4"
},
{
"input": "100\n10\n20",
"output": "YES\n0 5"
},
{
"input": "101\n11\n11",
"output": "NO"
},
{
"input": "121\n11\n11",
"output": "YES\n0 11"
},
{
"input": "25\n5\n6",
"output": "YES\n5 0"
},
{
"input": "1\n1\n1",
"output": "YES\n0 1"
},
{
"input": "10000000\n2\n1",
"output": "YES\n0 10000000"
},
{
"input": "10000000\n1234523\n1",
"output": "YES\n0 10000000"
},
{
"input": "10000000\n5000000\n5000000",
"output": "YES\n0 2"
},
{
"input": "10000000\n5000001\n5000000",
"output": "YES\n0 2"
},
{
"input": "10000000\n5000000\n5000001",
"output": "YES\n2 0"
},
{
"input": "9999999\n9999999\n9999999",
"output": "YES\n0 1"
},
{
"input": "10000000\n10000000\n10000000",
"output": "YES\n0 1"
},
{
"input": "10\n1\n3",
"output": "YES\n1 3"
},
{
"input": "97374\n689\n893",
"output": "NO"
},
{
"input": "100096\n791\n524",
"output": "NO"
},
{
"input": "75916\n651\n880",
"output": "NO"
},
{
"input": "110587\n623\n806",
"output": "NO"
},
{
"input": "5600\n670\n778",
"output": "NO"
},
{
"input": "81090\n527\n614",
"output": "NO"
},
{
"input": "227718\n961\n865",
"output": "NO"
},
{
"input": "10000000\n3\n999999",
"output": "NO"
},
{
"input": "3\n4\n5",
"output": "NO"
},
{
"input": "9999999\n2\n2",
"output": "NO"
},
{
"input": "9999999\n2\n4",
"output": "NO"
},
{
"input": "9999997\n2\n5",
"output": "YES\n1 1999999"
},
{
"input": "9366189\n4326262\n8994187",
"output": "NO"
},
{
"input": "1000000\n1\n10000000",
"output": "YES\n1000000 0"
},
{
"input": "9999991\n2\n2",
"output": "NO"
},
{
"input": "10000000\n7\n7",
"output": "NO"
},
{
"input": "9999991\n2\n4",
"output": "NO"
},
{
"input": "10000000\n3\n6",
"output": "NO"
},
{
"input": "10000000\n11\n11",
"output": "NO"
},
{
"input": "4\n7\n3",
"output": "NO"
},
{
"input": "1000003\n2\n2",
"output": "NO"
},
{
"input": "1000000\n7\n7",
"output": "NO"
},
{
"input": "999999\n2\n2",
"output": "NO"
},
{
"input": "8\n13\n5",
"output": "NO"
},
{
"input": "1000003\n15\n3",
"output": "NO"
},
{
"input": "7\n7\n2",
"output": "YES\n1 0"
},
{
"input": "9999999\n2\n8",
"output": "NO"
},
{
"input": "1000000\n3\n7",
"output": "YES\n5 142855"
},
{
"input": "9999999\n1\n10000000",
"output": "YES\n9999999 0"
},
{
"input": "100\n1\n1000000",
"output": "YES\n100 0"
},
{
"input": "10000000\n9999999\n9999997",
"output": "NO"
},
{
"input": "2\n1\n3",
"output": "YES\n2 0"
},
{
"input": "3\n5\n2",
"output": "NO"
},
{
"input": "5\n2\n3",
"output": "YES\n1 1"
},
{
"input": "10000000\n7\n14",
"output": "NO"
},
{
"input": "10000000\n2\n9999999",
"output": "YES\n5000000 0"
},
{
"input": "10000000\n3\n3",
"output": "NO"
},
{
"input": "1\n3\n2",
"output": "NO"
},
{
"input": "25\n27\n2",
"output": "NO"
},
{
"input": "3\n2\n17",
"output": "NO"
},
{
"input": "999997\n4\n8",
"output": "NO"
},
{
"input": "2000000\n1\n2000001",
"output": "YES\n2000000 0"
},
{
"input": "8\n7\n3",
"output": "NO"
},
{
"input": "7005920\n5705\n28145",
"output": "NO"
},
{
"input": "2\n6\n4",
"output": "NO"
},
{
"input": "10000000\n9999999\n3",
"output": "NO"
},
{
"input": "10000000\n77\n99",
"output": "NO"
},
{
"input": "100\n8\n70",
"output": "NO"
},
{
"input": "99999\n2\n2",
"output": "NO"
},
{
"input": "5\n7\n2",
"output": "NO"
},
{
"input": "999999\n12\n14",
"output": "NO"
},
{
"input": "100\n1\n1000",
"output": "YES\n100 0"
},
{
"input": "10000000\n123\n321",
"output": "NO"
},
{
"input": "9369319\n4\n2",
"output": "NO"
},
{
"input": "9999998\n3\n3",
"output": "NO"
},
{
"input": "85\n5\n85",
"output": "YES\n0 1"
},
{
"input": "64549\n9999999\n2",
"output": "NO"
},
{
"input": "10000000\n3\n7",
"output": "YES\n1 1428571"
},
{
"input": "9999889\n2\n2",
"output": "NO"
},
{
"input": "10000000\n9999999\n123",
"output": "NO"
},
{
"input": "64549\n2\n9999999",
"output": "NO"
}
] | 1,641,759,635 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 100 | 139 | 1,228,800 | import sys
n = int(input())
a = int(input())
b = int(input())
for i in range((n // a) + 1):
if (n - (i * a)) % b == 0:
print("YES")
print(i, (n - (i * a)) // b)
sys.exit()
print("NO")
| Title: Proper Nutrition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles.
In other words, you should find two non-negative integers *x* and *y* such that Vasya can buy *x* bottles of Ber-Cola and *y* Bars bars and *x*·*a*<=+<=*y*·*b*<==<=*n* or tell that it's impossible.
Input Specification:
First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has.
Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola.
Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar.
Output Specification:
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly *n* burles, i.e. *x*·*a*<=+<=*y*·*b*<==<=*n*. If there are multiple answers print any of them.
Any of numbers *x* and *y* can be equal 0.
Demo Input:
['7\n2\n3\n', '100\n25\n10\n', '15\n4\n8\n', '9960594\n2551\n2557\n']
Demo Output:
['YES\n2 1\n', 'YES\n0 10\n', 'NO\n', 'YES\n1951 1949\n']
Note:
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly *n* burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola and buy 10 Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles. | ```python
import sys
n = int(input())
a = int(input())
b = int(input())
for i in range((n // a) + 1):
if (n - (i * a)) % b == 0:
print("YES")
print(i, (n - (i * a)) // b)
sys.exit()
print("NO")
``` | 3 |
|
922 | C | Cave Painting | PROGRAMMING | 1,600 | [
"brute force",
"number theory"
] | null | null | Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that:
- 1<=≤<=*i*<=<<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*. | The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). | Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper). | [
"4 4\n",
"5 3\n"
] | [
"No\n",
"Yes\n"
] | In the first sample remainders modulo 1 and 4 coincide. | 1,250 | [
{
"input": "4 4",
"output": "No"
},
{
"input": "5 3",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "744 18",
"output": "No"
},
{
"input": "47879 10",
"output": "Yes"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "No"
},
{
"input": "657180569218773599 42",
"output": "Yes"
},
{
"input": "442762254977842799 30",
"output": "Yes"
},
{
"input": "474158606260730555 1",
"output": "Yes"
},
{
"input": "807873101233533988 39",
"output": "No"
},
{
"input": "423 7",
"output": "No"
},
{
"input": "264306177888923090 5",
"output": "No"
},
{
"input": "998857801526481788 87",
"output": "No"
},
{
"input": "999684044704565212 28",
"output": "No"
},
{
"input": "319575605003866172 71",
"output": "No"
},
{
"input": "755804560577415016 17",
"output": "No"
},
{
"input": "72712630136142067 356370939",
"output": "No"
},
{
"input": "807264258068668062 33080422",
"output": "No"
},
{
"input": "808090496951784190 311661970",
"output": "No"
},
{
"input": "808916740129867614 180178111",
"output": "No"
},
{
"input": "1 2",
"output": "Yes"
},
{
"input": "2 1",
"output": "Yes"
},
{
"input": "57334064998850639 19",
"output": "Yes"
},
{
"input": "144353716412182199 11",
"output": "Yes"
},
{
"input": "411002215096001759 11",
"output": "Yes"
},
{
"input": "347116374613371527 3",
"output": "Yes"
},
{
"input": "518264351335130399 37",
"output": "Yes"
},
{
"input": "192435891235905239 11",
"output": "Yes"
},
{
"input": "491802505049361659 7",
"output": "Yes"
},
{
"input": "310113769227703889 3",
"output": "Yes"
},
{
"input": "876240758958364799 41",
"output": "Yes"
},
{
"input": "173284263472319999 33",
"output": "Yes"
},
{
"input": "334366426725130799 29",
"output": "Yes"
},
{
"input": "415543470272330399 26",
"output": "Yes"
},
{
"input": "631689521541558479 22",
"output": "Yes"
},
{
"input": "581859366558790319 14",
"output": "Yes"
},
{
"input": "224113913709159599 10",
"output": "Yes"
},
{
"input": "740368848764104559 21",
"output": "Yes"
},
{
"input": "895803074828822159 17",
"output": "Yes"
},
{
"input": "400349974997012039 13",
"output": "Yes"
},
{
"input": "205439024252247599 5",
"output": "Yes"
},
{
"input": "197688463911338399 39",
"output": "Yes"
},
{
"input": "283175367224349599 39",
"output": "Yes"
},
{
"input": "893208176423362799 31",
"output": "Yes"
},
{
"input": "440681012669897999 27",
"output": "Yes"
},
{
"input": "947403664618451039 19",
"output": "Yes"
},
{
"input": "232435556779345919 19",
"output": "Yes"
},
{
"input": "504428493840551279 23",
"output": "Yes"
},
{
"input": "30019549241681999 20",
"output": "Yes"
},
{
"input": "648000813924303839 16",
"output": "Yes"
},
{
"input": "763169499725761451 488954176053755860",
"output": "No"
},
{
"input": "199398459594277592 452260924647536414",
"output": "No"
},
{
"input": "635627415167826436 192195636386541160",
"output": "No"
},
{
"input": "71856370741375281 155502380685354417",
"output": "No"
},
{
"input": "731457367464667229 118809129279134971",
"output": "No"
},
{
"input": "167686318743248777 858743836723172421",
"output": "No"
},
{
"input": "603915274316797622 822050585316952974",
"output": "No"
},
{
"input": "647896534275160623 65689274138731296",
"output": "No"
},
{
"input": "648722777453244047 501918229712280140",
"output": "No"
},
{
"input": "649549020631327471 41923378183538525",
"output": "No"
},
{
"input": "650375259514443599 597748177714153637",
"output": "No"
},
{
"input": "651201506987494319 33977137582669778",
"output": "No"
},
{
"input": "652027745870610447 470206093156218622",
"output": "No"
},
{
"input": "652853989048693871 906435048729767466",
"output": "No"
},
{
"input": "653680227931809999 342664004303316311",
"output": "No"
},
{
"input": "654506475404860719 375019787446735639",
"output": "No"
},
{
"input": "655332714287976847 438493956600157103",
"output": "No"
},
{
"input": "166512305365727033 900267947832156186",
"output": "No"
},
{
"input": "167338548543810457 336496907700672326",
"output": "No"
},
{
"input": "168164787426926585 772725863274221171",
"output": "No"
},
{
"input": "523 3",
"output": "No"
},
{
"input": "39211 6",
"output": "No"
},
{
"input": "22151 9",
"output": "No"
},
{
"input": "1 3",
"output": "No"
},
{
"input": "47 5",
"output": "No"
},
{
"input": "999999998999999999 1000000000",
"output": "No"
},
{
"input": "11 6",
"output": "No"
},
{
"input": "7 4",
"output": "No"
},
{
"input": "1 10",
"output": "No"
},
{
"input": "9 5",
"output": "No"
},
{
"input": "2519 20",
"output": "No"
},
{
"input": "700001 3",
"output": "Yes"
},
{
"input": "13 7",
"output": "No"
},
{
"input": "999999 10000",
"output": "No"
},
{
"input": "1 4",
"output": "No"
},
{
"input": "232792559 30",
"output": "No"
},
{
"input": "1 5",
"output": "No"
},
{
"input": "5 4",
"output": "No"
},
{
"input": "5 8",
"output": "No"
},
{
"input": "55 4",
"output": "No"
}
] | 1,617,099,763 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 512,000 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
from __future__ import print_function # for PyPy2
from itertools import permutations as perm
# from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
n, k = gil()
if k < n:
rem = set()
for i in range(1, min(k, int(1e6))+1):
md = n%i
if md in rem:
print('No')
exit()
rem.add(md)
print('Yes')
else:
print('No') | Title: Cave Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that:
- 1<=≤<=*i*<=<<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*.
Input Specification:
The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018).
Output Specification:
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
Demo Input:
['4 4\n', '5 3\n']
Demo Output:
['No\n', 'Yes\n']
Note:
In the first sample remainders modulo 1 and 4 coincide. | ```python
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
from __future__ import print_function # for PyPy2
from itertools import permutations as perm
# from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
n, k = gil()
if k < n:
rem = set()
for i in range(1, min(k, int(1e6))+1):
md = n%i
if md in rem:
print('No')
exit()
rem.add(md)
print('Yes')
else:
print('No')
``` | 0 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,697,896,235 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 0 | n=int(input())
set=set()
for i in range(0,n):
set.add(input())
print(len(set)) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
n=int(input())
set=set()
for i in range(0,n):
set.add(input())
print(len(set))
``` | 3.969 |
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location! | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
{
"input": "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ",
"output": "contest"
},
{
"input": "10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\nPVO->DMN\nDMN->PVO",
"output": "home"
},
{
"input": "11\nIAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU",
"output": "contest"
},
{
"input": "10\nHPN\nDFI->HPN\nHPN->KAB\nHPN->DFI\nVSO->HPN\nHPN->KZX\nHPN->VSO\nKZX->HPN\nLDW->HPN\nKAB->HPN\nHPN->LDW",
"output": "home"
},
{
"input": "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE->FGH\nFGH->KQK\nFGH->QRE\nKQK->FGH\nFGH->UBK\nBRZ->FGH\nFGH->ALX\nALX->FGH\nFGH->KQK",
"output": "contest"
},
{
"input": "50\nPFH\nJFV->PFH\nBVP->PFH\nPFH->BVP\nPFH->JFV\nPFH->ETQ\nPFH->LQJ\nZTO->PFH\nPFH->BVP\nPFH->RXO\nPFH->ZTO\nHWL->PFH\nPFH->HIV\nPFH->AFP\nPFH->HWL\nOBB->PFH\nHIV->PFH\nPFH->LSR\nAFP->PFH\nLQJ->PFH\nHWL->PFH\nETQ->PFH\nPFH->HWL\nLSR->PFH\nWBR->PFH\nBNZ->PFH\nHQR->PFH\nZTO->PFH\nPFH->WBR\nPFH->BYJ\nRXO->PFH\nFHZ->PFH\nFHZ->PFH\nPFN->PFH\nPFH->GMB\nPFH->JFV\nJFV->PFH\nGNZ->PFH\nPFH->BNZ\nPFH->GNZ\nPFH->HQR\nBYJ->PFH\nGMB->PFH\nPFH->FHZ\nPFH->FHZ\nPFH->ZTO\nPFH->UGD\nBVP->PFH\nUGD->PFH\nPFH->PFN\nPFH->OBB",
"output": "home"
},
{
"input": "1\nAAK\nAAK->ABA",
"output": "contest"
},
{
"input": "1\nXYZ\nXYZ->XYR",
"output": "contest"
}
] | 1,614,368,571 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 62 | 0 | n = int(input())
home = input()
flights = []
be_in_home = 0
not_in_home = 0
for i in range(n):
airport_from, airport_to = map(str, input().split('->'))
flights.append([airport_from, airport_to])
for x in flights:
if x[1] == home:
be_in_home += 1
else:
not_in_home += 1
if be_in_home != not_in_home:
print('contest')
else:
print('home') | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location!
Input Specification:
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
Output Specification:
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
Demo Input:
['4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n', '3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n']
Demo Output:
['home\n', 'contest\n']
Note:
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | ```python
n = int(input())
home = input()
flights = []
be_in_home = 0
not_in_home = 0
for i in range(n):
airport_from, airport_to = map(str, input().split('->'))
flights.append([airport_from, airport_to])
for x in flights:
if x[1] == home:
be_in_home += 1
else:
not_in_home += 1
if be_in_home != not_in_home:
print('contest')
else:
print('home')
``` | 3 |
|
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique. | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\njfyy",
"output": "yyjf"
},
{
"input": "6\nkrdych",
"output": "hcyrkd"
},
{
"input": "60\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj",
"output": "jqprcbfgsxwgjhmkehcoiwwltuxjzokamzpalobnfespcvmoecqigyuutueu"
},
{
"input": "64\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy",
"output": "ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh"
},
{
"input": "97\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacygakhxoubibxtqkpyyhzjipylujgrc",
"output": "crgjulypijzhyypkqtxbibuoxhkagycauuqgchyaokulsbfbnsazfrkcgibxucwgwdalcelhuoqdibceswtjiabubmhdmrqnq"
},
{
"input": "100\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf",
"output": "fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi"
},
{
"input": "96\nqtbcksuvxonzbkokhqlgkrvimzqmqnrvqlihrmksldyydacbtckfphenxszcnzhfjmpeykrvshgiboivkvabhrpphgavvprz",
"output": "zrpvvaghpprhbavkviobighsvrkyepmjfhznczsxnehpfkctvrnqmqzmkokbvuctqbksxonzhqlgkrviqlihrmksldyydacb"
},
{
"input": "90\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "89\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
},
{
"input": "99\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "100\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"output": "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
},
{
"input": "60\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwnwwwwwwwwwwhwwwxwwwwwwwwwfhwwwwawwwwww"
},
{
"input": "90\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc",
"output": "cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc"
},
{
"input": "97\nfwffffffffffffffffffffffffrffffffffffffffzfffffffffffffffftfcfffffffqffffffffffffffffffffffyfffff",
"output": "fffffyffffffffffffffffffffffqfffffffcftffffffffffffffffzffffffffffffffrffffffffffffffffffffffffwf"
},
{
"input": "100\ndjjjjjjjjjjgjjjjjjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjjjjajjjjjjajjjjjjrjjjjjjjjjjjjrjjtjjjjjjjjjjjjjojjj",
"output": "jjjojjjjjjjjjjjjjtjjrjjjjjjjjjjjjrjjjjjjajjjjjjajjjjjjjjjjjjjjdjjjgjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjj"
}
] | 1,647,875,349 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
string = input()
d = []
for i in range(1, n+1):
if n % i == 0:
d.append(i)
print(d)
for i in range(len(d)):
string = string[:d[i]][::-1] + string[d[i]:]
print(string) | Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.
Input Specification:
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Output Specification:
Print a string $s$ such that the above algorithm results in $t$.
Demo Input:
['10\nrocesfedoc\n', '16\nplmaetwoxesisiht\n', '1\nz\n']
Demo Output:
['codeforces\n', 'thisisexampletwo\n', 'z\n']
Note:
The first example is described in the problem statement. | ```python
n = int(input())
string = input()
d = []
for i in range(1, n+1):
if n % i == 0:
d.append(i)
print(d)
for i in range(len(d)):
string = string[:d[i]][::-1] + string[d[i]:]
print(string)
``` | 0 |
|
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,648,147,591 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | employees = int(input())
divisibles = [*range(1,10)]
count=0
for i in divisibles:
if employees%i==0 and employees!=i:
count+=1
print(count) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | ```python
employees = int(input())
divisibles = [*range(1,10)]
count=0
for i in divisibles:
if employees%i==0 and employees!=i:
count+=1
print(count)
``` | 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,623,239,302 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 7,680,000 | def sumdigits(n):
s = 0
while(n):
s += n%10
n = n//10
return s
n = int(input())
c = 0
while(n//10):
c += 1
n = sumdigits(n)
print(c) | 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
def sumdigits(n):
s = 0
while(n):
s += n%10
n = n//10
return s
n = int(input())
c = 0
while(n//10):
c += 1
n = sumdigits(n)
print(c)
``` | 0 |
475 | B | Strongly Connected City | PROGRAMMING | 1,400 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern. | The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east. | If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". | [
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] | [
"NO\n",
"YES\n"
] | The figure above shows street directions in the second sample test case. | 1,000 | [
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>><\n^v^v",
"output": "YES"
},
{
"input": "3 8\n>><\nv^^^^^^^",
"output": "NO"
},
{
"input": "7 2\n<><<<<>\n^^",
"output": "NO"
},
{
"input": "4 5\n><<<\n^^^^v",
"output": "YES"
},
{
"input": "2 20\n><\n^v^^v^^v^^^v^vv^vv^^",
"output": "NO"
},
{
"input": "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^",
"output": "YES"
},
{
"input": "20 2\n<><<><<>><<<>><><<<<\n^^",
"output": "NO"
},
{
"input": "20 2\n><>><>><>><<<><<><><\n^v",
"output": "YES"
},
{
"input": "11 12\n><<<><><<>>\nvv^^^^vvvvv^",
"output": "NO"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "16 11\n<<<<>><><<<<<><<\nvv^v^vvvv^v",
"output": "NO"
},
{
"input": "14 7\n><<<<>>>>>>><<\nvv^^^vv",
"output": "NO"
},
{
"input": "5 14\n<<><>\nv^vv^^vv^v^^^v",
"output": "NO"
},
{
"input": "8 18\n>>>><>>>\nv^vv^v^^^^^vvv^^vv",
"output": "NO"
},
{
"input": "18 18\n<<><>><<>><>><><<<\n^^v^v^vvvv^v^vv^vv",
"output": "NO"
},
{
"input": "4 18\n<<<>\n^^^^^vv^vv^^vv^v^v",
"output": "NO"
},
{
"input": "19 18\n><><>>><<<<<>>><<<>\n^^v^^v^^v^vv^v^vvv",
"output": "NO"
},
{
"input": "14 20\n<<<><><<>><><<\nvvvvvvv^v^vvvv^^^vv^",
"output": "NO"
},
{
"input": "18 18\n><>>><<<>><><>>>><\nvv^^^^v^v^^^^v^v^^",
"output": "NO"
},
{
"input": "8 18\n<><<<>>>\n^^^^^^v^^^vv^^vvvv",
"output": "NO"
},
{
"input": "11 12\n><><><<><><\n^^v^^^^^^^^v",
"output": "YES"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "16 11\n>><<><<<<>>><><<\n^^^^vvvv^vv",
"output": "YES"
},
{
"input": "14 7\n<><><<<>>>><>>\nvv^^v^^",
"output": "YES"
},
{
"input": "5 14\n>>>><\n^v^v^^^vv^vv^v",
"output": "YES"
},
{
"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^",
"output": "YES"
},
{
"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v",
"output": "YES"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "19 18\n>>>><><<>>><<<><<<<\n^v^^^^vv^^v^^^^v^v",
"output": "YES"
},
{
"input": "14 20\n<>><<<><<>>>>>\nvv^^v^^^^v^^vv^^vvv^",
"output": "YES"
},
{
"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v",
"output": "YES"
},
{
"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^",
"output": "YES"
},
{
"input": "20 19\n<><>>>>><<<<<><<>>>>\nv^vv^^vvvvvv^vvvv^v",
"output": "NO"
},
{
"input": "20 19\n<<<><<<>><<<>><><><>\nv^v^vvv^vvv^^^vvv^^",
"output": "YES"
},
{
"input": "19 20\n<><<<><><><<<<<<<<>\n^v^^^^v^^vvvv^^^^vvv",
"output": "NO"
},
{
"input": "19 20\n>>>>>>>><>>><><<<><\n^v^v^^^vvv^^^v^^vvvv",
"output": "YES"
},
{
"input": "20 20\n<<<>>>><>><<>><<>>>>\n^vvv^^^^vv^^^^^v^^vv",
"output": "NO"
},
{
"input": "20 20\n>>><><<><<<<<<<><<><\nvv^vv^vv^^^^^vv^^^^^",
"output": "NO"
},
{
"input": "20 20\n><<><<<<<<<>>><>>><<\n^^^^^^^^vvvv^vv^vvvv",
"output": "YES"
},
{
"input": "20 20\n<>>>>>>>><>>><>><<<>\nvv^^vv^^^^v^vv^v^^^^",
"output": "YES"
},
{
"input": "20 20\n><>><<>><>>>>>>>><<>\n^^v^vv^^^vvv^v^^^vv^",
"output": "NO"
},
{
"input": "20 20\n<<<<><<>><><<<>><<><\nv^^^^vvv^^^vvvv^v^vv",
"output": "NO"
},
{
"input": "20 20\n><<<><<><>>><><<<<<<\nvv^^vvv^^v^^v^vv^vvv",
"output": "NO"
},
{
"input": "20 20\n<<>>><>>>><<<<>>><<>\nv^vv^^^^^vvv^^v^^v^v",
"output": "NO"
},
{
"input": "20 20\n><<><<><<<<<<>><><>>\nv^^^v^vv^^v^^vvvv^vv",
"output": "NO"
},
{
"input": "20 20\n<<<<<<<<><>><><>><<<\n^vvv^^^v^^^vvv^^^^^v",
"output": "NO"
},
{
"input": "20 20\n>>><<<<<>>><><><<><<\n^^^vvv^^^v^^v^^v^vvv",
"output": "YES"
},
{
"input": "20 20\n<><<<><><>><><><<<<>\n^^^vvvv^vv^v^^^^v^vv",
"output": "NO"
},
{
"input": "20 20\n>>>>>>>>>><>>><>><>>\n^vvv^^^vv^^^^^^vvv^v",
"output": "NO"
},
{
"input": "20 20\n<><>><><<<<<>><<>>><\nv^^^v^v^v^vvvv^^^vv^",
"output": "NO"
},
{
"input": "20 20\n><<<><<<><<<><>>>><<\nvvvv^^^^^vv^v^^vv^v^",
"output": "NO"
},
{
"input": "20 20\n<<><<<<<<>>>>><<<>>>\nvvvvvv^v^vvv^^^^^^^^",
"output": "YES"
},
{
"input": "20 20\n><<><<>>>>><><>><>>>\nv^^^^vvv^^^^^v^v^vv^",
"output": "NO"
},
{
"input": "20 20\n<<>>><>><<>>>><<<><<\n^^vvv^^vvvv^vv^^v^v^",
"output": "NO"
},
{
"input": "20 20\n><<>><>>>><<><>><><<\n^v^^^^^^vvvv^v^v^v^^",
"output": "NO"
},
{
"input": "20 20\n<<><<<<><><<>>><>>>>\n^^vvvvv^v^^^^^^^vvv^",
"output": "NO"
},
{
"input": "20 20\n>><<<<<<><>>>><>>><>\n^^^v^v^vv^^vv^vvv^^^",
"output": "NO"
},
{
"input": "20 20\n>>>>>>>>>>>>>>>>>>>>\nvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "2 2\n><\nv^",
"output": "NO"
},
{
"input": "2 2\n<>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\nvvv",
"output": "NO"
},
{
"input": "2 3\n<>\nv^^",
"output": "YES"
},
{
"input": "4 4\n>>><\nvvv^",
"output": "NO"
},
{
"input": "20 20\n<><><><><><><><><><>\nvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "4 4\n<>>>\nv^^^",
"output": "YES"
},
{
"input": "20 20\n<><><><><><><><><><>\nv^v^v^v^v^v^v^v^v^v^",
"output": "YES"
},
{
"input": "2 3\n<>\n^v^",
"output": "NO"
},
{
"input": "4 3\n<><>\n^vv",
"output": "NO"
},
{
"input": "3 3\n<<>\nvv^",
"output": "YES"
},
{
"input": "2 3\n><\nvv^",
"output": "NO"
},
{
"input": "7 6\n>>><>><\n^vv^vv",
"output": "YES"
},
{
"input": "2 2\n<<\nv^",
"output": "NO"
},
{
"input": "3 3\n>><\n^^^",
"output": "NO"
},
{
"input": "3 3\n<><\nv^v",
"output": "NO"
},
{
"input": "20 20\n><><><><><><><><><><\n^v^v^v^v^v^v^v^v^v^v",
"output": "YES"
},
{
"input": "4 4\n<>>>\nvvv^",
"output": "YES"
}
] | 1,608,964,339 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 233 | 307,200 | n, m = map(int, input("").split())
row_order = [ char for char in input("")]
col_order = [char for char in input("")]
class Node():
def __init__(self, id):
self.row_id, self.col_id = id
self.children = []
def add_child(self, child_node_id):
self.children.append(child_node_id)
def add_horizontal_edge(row_dir, row_id, col_id):
if row_dir == '>' and col_id < m-1:
matrix[row_id][col_id].add_child((row_id ,col_id+1))
elif row_dir == '<' and col_id > 0:
matrix[row_id][col_id].add_child((row_id, col_id-1))
def add_vertical_edge(col_dir, row_id, col_id):
if col_dir == '^' and row_id > 0:
matrix[row_id][col_id].add_child((row_id-1, col_id))
elif col_dir == 'v'and row_id < n-1:
matrix[row_id][col_id].add_child((row_id+1, col_id))
matrix = [[Node((row_id, col_id)) for col_id in range(m)] for row_id in range(n)]
for row_id in range(n):
row_dir = row_order[row_id]
for col_id in range(m):
col_dir = col_order[col_id]
add_horizontal_edge(row_dir, row_id, col_id)
add_vertical_edge(col_dir, row_id, col_id)
def explore(row_id, col_id, visited):
if visited[row_id][col_id] == 'true':
return
else:
visited[row_id][col_id] ='true'
for child_row_id, child_col_id in matrix[row_id][col_id].children:
explore(child_row_id, child_col_id, visited)
return
answer = 'YES'
def dfs(answer):
for row_id in range(n):
for col_id in range(m):
visited = [['false' for col_id in range(m)] for row_id in range(n)]
explore(row_id, col_id, visited)
for i in range(n):
for j in range(m):
if visited[i][j] == 'false':
answer = 'NO'
return answer
return answer
answer = dfs(answer)
print(answer)
| Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
Input Specification:
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
Output Specification:
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
Demo Input:
['3 3\n><>\nv^v\n', '4 6\n<><>\nv^v^v^\n']
Demo Output:
['NO\n', 'YES\n']
Note:
The figure above shows street directions in the second sample test case. | ```python
n, m = map(int, input("").split())
row_order = [ char for char in input("")]
col_order = [char for char in input("")]
class Node():
def __init__(self, id):
self.row_id, self.col_id = id
self.children = []
def add_child(self, child_node_id):
self.children.append(child_node_id)
def add_horizontal_edge(row_dir, row_id, col_id):
if row_dir == '>' and col_id < m-1:
matrix[row_id][col_id].add_child((row_id ,col_id+1))
elif row_dir == '<' and col_id > 0:
matrix[row_id][col_id].add_child((row_id, col_id-1))
def add_vertical_edge(col_dir, row_id, col_id):
if col_dir == '^' and row_id > 0:
matrix[row_id][col_id].add_child((row_id-1, col_id))
elif col_dir == 'v'and row_id < n-1:
matrix[row_id][col_id].add_child((row_id+1, col_id))
matrix = [[Node((row_id, col_id)) for col_id in range(m)] for row_id in range(n)]
for row_id in range(n):
row_dir = row_order[row_id]
for col_id in range(m):
col_dir = col_order[col_id]
add_horizontal_edge(row_dir, row_id, col_id)
add_vertical_edge(col_dir, row_id, col_id)
def explore(row_id, col_id, visited):
if visited[row_id][col_id] == 'true':
return
else:
visited[row_id][col_id] ='true'
for child_row_id, child_col_id in matrix[row_id][col_id].children:
explore(child_row_id, child_col_id, visited)
return
answer = 'YES'
def dfs(answer):
for row_id in range(n):
for col_id in range(m):
visited = [['false' for col_id in range(m)] for row_id in range(n)]
explore(row_id, col_id, visited)
for i in range(n):
for j in range(m):
if visited[i][j] == 'false':
answer = 'NO'
return answer
return answer
answer = dfs(answer)
print(answer)
``` | 3 |