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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
629 | B | Far Relative’s Problem | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.
Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive. | Print the maximum number of people that may come to Famil Door's party. | [
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
] | [
"2\n",
"4\n"
] | In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | 1,000 | [
{
"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128",
"output": "2"
},
{
"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200",
"output": "4"
},
{
"input": "1\nF 68 307",
"output": "0"
},
{
"input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244\nF 42 339\nM 253 307\nM 128 192\nF 119 328\nM 135 249\nF 303 358\nF 348 352\nF 8 364\nF 126 303\nM 226 346\nF 110 300\nF 47 303\nF 201 311\nF 287 288\nM 270 352\nM 227 351\nF 8 111\nF 39 229\nM 163 315\nF 269 335\nF 147 351\nF 96 143\nM 97 99\nM 177 295",
"output": "22"
},
{
"input": "2\nF 1 1\nM 1 1",
"output": "2"
},
{
"input": "4\nM 1 2\nM 2 3\nF 3 4\nF 4 5",
"output": "2"
},
{
"input": "1\nF 1 2",
"output": "0"
},
{
"input": "18\nF 3 4\nF 3 4\nF 3 4\nF 3 4\nF 5 6\nF 5 6\nM 3 4\nM 3 4\nM 5 6\nM 5 6\nM 5 6\nM 5 6\nF 7 8\nF 7 8\nF 7 8\nM 7 8\nM 7 8\nM 7 8",
"output": "6"
},
{
"input": "2\nM 1 1\nF 1 1",
"output": "2"
},
{
"input": "3\nM 1 1\nF 1 1\nM 1 1",
"output": "2"
}
] | 1,456,211,876 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 826 | 307,200 | n=int(input())
rows=[]
for _ in range(n):
g,s,e=input().split()
rows.append((g,int(s),int(e)))
best=0
for i in range(1,367):
m=f=0
for row in rows:
g,s,e=row
if g=='M':
m+=(1 if (s<=i and i<=e) else 0)
else:
f+=(1 if (s<=i and i<=e) else 0)
best=max(min(m,f),best)
print(best*2)
| Title: Far Relative’s Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.
Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive.
Output Specification:
Print the maximum number of people that may come to Famil Door's party.
Demo Input:
['4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n', '6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | ```python
n=int(input())
rows=[]
for _ in range(n):
g,s,e=input().split()
rows.append((g,int(s),int(e)))
best=0
for i in range(1,367):
m=f=0
for row in rows:
g,s,e=row
if g=='M':
m+=(1 if (s<=i and i<=e) else 0)
else:
f+=(1 if (s<=i and i<=e) else 0)
best=max(min(m,f),best)
print(best*2)
``` | 3 |
|
873 | D | Merge Sort | PROGRAMMING | 1,800 | [
"constructive algorithms",
"divide and conquer"
] | null | null | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+<=1]), then end the function call; 1. Let ; 1. Call *mergesort*(*a*,<=*l*,<=*mid*); 1. Call *mergesort*(*a*,<=*mid*,<=*r*); 1. Merge segments [*l*,<=*mid*) and [*mid*,<=*r*), making the segment [*l*,<=*r*) sorted in non-descending order. The merge algorithm doesn't call any other functions.
The array in this problem is 0-indexed, so to sort the whole array, you need to call *mergesort*(*a*,<=0,<=*n*).
The number of calls of function *mergesort* is very important, so Ivan has decided to calculate it while sorting the array. For example, if *a*<==<={1,<=2,<=3,<=4}, then there will be 1 call of *mergesort* — *mergesort*(0,<=4), which will check that the array is sorted and then end. If *a*<==<={2,<=1,<=3}, then the number of calls is 3: first of all, you call *mergesort*(0,<=3), which then sets *mid*<==<=1 and calls *mergesort*(0,<=1) and *mergesort*(1,<=3), which do not perform any recursive calls because segments (0,<=1) and (1,<=3) are sorted.
Ivan has implemented the program that counts the number of *mergesort* calls, but now he needs to test it. To do this, he needs to find an array *a* such that *a* is a permutation of size *n* (that is, the number of elements in *a* is *n*, and every integer number from [1,<=*n*] can be found in this array), and the number of *mergesort* calls when sorting the array is exactly *k*.
Help Ivan to find an array he wants! | The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it. | If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them. | [
"3 3\n",
"4 1\n",
"5 6\n"
] | [
"2 1 3 ",
"1 2 3 4 ",
"-1\n"
] | none | 0 | [
{
"input": "3 3",
"output": "2 1 3 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "100 100",
"output": "-1"
},
{
"input": "10000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "10000 20001",
"output": "-1"
},
{
"input": "10000 30001",
"output": "-1"
},
{
"input": "20000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "20000 20001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "20000 30001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "30000 10001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "30000 20001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "30000 30001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "40000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "40000 20001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "40000 30001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "50000 10001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "50000 20001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "50000 30001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "60000 10001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "60000 20001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "60000 30001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "70000 10001",
"output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..."
},
{
"input": "70000 20001",
"output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..."
},
{
"input": "70000 30001",
"output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..."
},
{
"input": "80000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "80000 20001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "80000 30001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "90000 10001",
"output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..."
},
{
"input": "90000 20001",
"output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..."
},
{
"input": "90000 30001",
"output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..."
},
{
"input": "100000 10001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "100000 20001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "100000 30001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "100000 199999",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "10 17",
"output": "3 1 4 6 2 8 5 9 7 10 "
}
] | 1,646,602,532 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 623 | 3,481,600 | import os
import sys
import copy
num = 0
a = None
# sys.stdin = open(os.path.join(os.path.dirname(__file__),'35.in'))
k = None
def solve():
global k,a
n, k = map(lambda x:int(x), input().split())
savek = copy.deepcopy(k)
# print(a)
a = [_+1 for _ in range(n)]
def mgsort(l, r):
global num,a,k
mid = (l+r) >> 1
if r - l == 1 or k == 1:
return
k -= 2
a[l:mid] , a[mid:r] = a[mid:r] , a[l:mid]
mgsort(l, mid)
mgsort(mid, r)
if k % 2 != 0:
mgsort(0, n)
if k == 1:
for i in a:
print(i,sep=' ',end=' ')
else:
print(-1)
solve() | Title: Merge Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+<=1]), then end the function call; 1. Let ; 1. Call *mergesort*(*a*,<=*l*,<=*mid*); 1. Call *mergesort*(*a*,<=*mid*,<=*r*); 1. Merge segments [*l*,<=*mid*) and [*mid*,<=*r*), making the segment [*l*,<=*r*) sorted in non-descending order. The merge algorithm doesn't call any other functions.
The array in this problem is 0-indexed, so to sort the whole array, you need to call *mergesort*(*a*,<=0,<=*n*).
The number of calls of function *mergesort* is very important, so Ivan has decided to calculate it while sorting the array. For example, if *a*<==<={1,<=2,<=3,<=4}, then there will be 1 call of *mergesort* — *mergesort*(0,<=4), which will check that the array is sorted and then end. If *a*<==<={2,<=1,<=3}, then the number of calls is 3: first of all, you call *mergesort*(0,<=3), which then sets *mid*<==<=1 and calls *mergesort*(0,<=1) and *mergesort*(1,<=3), which do not perform any recursive calls because segments (0,<=1) and (1,<=3) are sorted.
Ivan has implemented the program that counts the number of *mergesort* calls, but now he needs to test it. To do this, he needs to find an array *a* such that *a* is a permutation of size *n* (that is, the number of elements in *a* is *n*, and every integer number from [1,<=*n*] can be found in this array), and the number of *mergesort* calls when sorting the array is exactly *k*.
Help Ivan to find an array he wants!
Input Specification:
The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it.
Output Specification:
If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them.
Demo Input:
['3 3\n', '4 1\n', '5 6\n']
Demo Output:
['2 1 3 ', '1 2 3 4 ', '-1\n']
Note:
none | ```python
import os
import sys
import copy
num = 0
a = None
# sys.stdin = open(os.path.join(os.path.dirname(__file__),'35.in'))
k = None
def solve():
global k,a
n, k = map(lambda x:int(x), input().split())
savek = copy.deepcopy(k)
# print(a)
a = [_+1 for _ in range(n)]
def mgsort(l, r):
global num,a,k
mid = (l+r) >> 1
if r - l == 1 or k == 1:
return
k -= 2
a[l:mid] , a[mid:r] = a[mid:r] , a[l:mid]
mgsort(l, mid)
mgsort(mid, r)
if k % 2 != 0:
mgsort(0, n)
if k == 1:
for i in a:
print(i,sep=' ',end=' ')
else:
print(-1)
solve()
``` | 3 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,620,295,371 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 20,172,800 | n=int(input())
c=0
d=0
e=0
for i in range(n):
a=list(map(str,input().split()))
if(a=='A'):
c=c+1
else:
d=d+1
e=a
if(c>d):
print('A')
else:
print(e) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
n=int(input())
c=0
d=0
e=0
for i in range(n):
a=list(map(str,input().split()))
if(a=='A'):
c=c+1
else:
d=d+1
e=a
if(c>d):
print('A')
else:
print(e)
``` | 0 |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range? | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
}
] | 1,589,818,973 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 920 | 10,342,400 | from sys import stdin, stdout
MN = 200005
inp = stdin.readline().split()
n = int(inp[0])
k = int(inp[1])
q = int(inp[2])
dod = [0] * MN
pref = [0] * MN
cnt = 0
for i in range(0, n) :
inp = stdin.readline().split()
dod[int(inp[0])] += 1
dod[int(inp[1]) + 1] -= 1
for i in range(1, MN) :
cnt += dod[i]
pref[i] = pref[i - 1]
if(cnt >= k) :
pref[i] += 1
for i in range(0, q) :
inp = stdin.readline().split()
stdout.write(str(pref[int(inp[1])] - pref[int(inp[0]) - 1]) + "\n")
| Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range?
Input Specification:
The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
Output Specification:
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
Demo Input:
['3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n', '2 1 1\n1 1\n200000 200000\n90 100\n']
Demo Output:
['3\n3\n0\n4\n', '0\n']
Note:
In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | ```python
from sys import stdin, stdout
MN = 200005
inp = stdin.readline().split()
n = int(inp[0])
k = int(inp[1])
q = int(inp[2])
dod = [0] * MN
pref = [0] * MN
cnt = 0
for i in range(0, n) :
inp = stdin.readline().split()
dod[int(inp[0])] += 1
dod[int(inp[1]) + 1] -= 1
for i in range(1, MN) :
cnt += dod[i]
pref[i] = pref[i - 1]
if(cnt >= k) :
pref[i] += 1
for i in range(0, q) :
inp = stdin.readline().split()
stdout.write(str(pref[int(inp[1])] - pref[int(inp[0]) - 1]) + "\n")
``` | 3 |
|
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct. | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n2 3\n1 1\n3 2",
"output": "Happy Alex"
},
{
"input": "4\n4 1\n3 2\n2 3\n1 4",
"output": "Happy Alex"
},
{
"input": "2\n2 1\n1 2",
"output": "Happy Alex"
},
{
"input": "3\n3 2\n1 1\n2 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 1\n3 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
}
] | 1,670,948,745 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | testCases = int(input())
inputArray = []
alex = 0
for i in range(testCases):
testCase = input().split(" ")
testPrice = int(testCase[0])
testQuality = int(testCase[1])
inputArray.append([testPrice, testQuality])
inputArray.sort(key = lambda x: x[0])
for i in range(testCases):
for j in range(testCases-i-1):
if inputArray[i+j][1] < inputArray[i][1]:
alex = 1
if alex == 1:
print("Happy Alex")
else:
print("Poor Alex") | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
testCases = int(input())
inputArray = []
alex = 0
for i in range(testCases):
testCase = input().split(" ")
testPrice = int(testCase[0])
testQuality = int(testCase[1])
inputArray.append([testPrice, testQuality])
inputArray.sort(key = lambda x: x[0])
for i in range(testCases):
for j in range(testCases-i-1):
if inputArray[i+j][1] < inputArray[i][1]:
alex = 1
if alex == 1:
print("Happy Alex")
else:
print("Poor Alex")
``` | 0 |
|
490 | C | Hacking Cypher | PROGRAMMING | 1,700 | [
"brute force",
"math",
"number theory",
"strings"
] | null | null | Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by *a* as a separate number, and the second (right) part is divisible by *b* as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values *a* and *b*.
Help Polycarpus and find any suitable method to cut the public key. | The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=108). | In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by *a*, and the right part must be divisible by *b*. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes). | [
"116401024\n97 1024\n",
"284254589153928171911281811000\n1009 1000\n",
"120\n12 1\n"
] | [
"YES\n11640\n1024\n",
"YES\n2842545891539\n28171911281811000\n",
"NO\n"
] | none | 1,500 | [
{
"input": "116401024\n97 1024",
"output": "YES\n11640\n1024"
},
{
"input": "284254589153928171911281811000\n1009 1000",
"output": "YES\n2842545891539\n28171911281811000"
},
{
"input": "120\n12 1",
"output": "NO"
},
{
"input": "604\n6 4",
"output": "YES\n60\n4"
},
{
"input": "2108\n7 8",
"output": "YES\n210\n8"
},
{
"input": "7208\n10 1",
"output": "YES\n720\n8"
},
{
"input": "97502821\n25 91",
"output": "YES\n9750\n2821"
},
{
"input": "803405634\n309 313",
"output": "YES\n80340\n5634"
},
{
"input": "15203400\n38 129",
"output": "NO"
},
{
"input": "8552104774\n973 76",
"output": "NO"
},
{
"input": "2368009434\n320 106",
"output": "YES\n236800\n9434"
},
{
"input": "425392502895812\n4363 2452",
"output": "YES\n42539250\n2895812"
},
{
"input": "142222201649130\n4854 7853",
"output": "YES\n14222220\n1649130"
},
{
"input": "137871307228140\n9375 9092",
"output": "NO"
},
{
"input": "8784054131798916\n9 61794291",
"output": "YES\n87840\n54131798916"
},
{
"input": "24450015102786098\n75 55729838",
"output": "YES\n244500\n15102786098"
},
{
"input": "100890056766780885\n177 88010513",
"output": "YES\n1008900\n56766780885"
},
{
"input": "2460708054301924950\n9428 85246350",
"output": "YES\n24607080\n54301924950"
},
{
"input": "39915186055525904358\n90102 63169402",
"output": "YES\n399151860\n55525904358"
},
{
"input": "199510140021146591389\n458644 28692797",
"output": "YES\n1995101400\n21146591389"
},
{
"input": "4802711808015050898224\n8381696 51544172",
"output": "YES\n48027118080\n15050898224"
},
{
"input": "6450225349035040017740\n8872387 56607460",
"output": "YES\n64502253490\n35040017740"
},
{
"input": "4530228043401488\n71454701 8",
"output": "YES\n453022804340\n1488"
},
{
"input": "18769213650033200\n56876405 100",
"output": "YES\n187692136500\n33200"
},
{
"input": "389744672208415\n17019418 765",
"output": "YES\n38974467220\n8415"
},
{
"input": "1256363256202133560\n26228878 7460",
"output": "YES\n125636325620\n2133560"
},
{
"input": "10213094404080691512\n64639838 83359",
"output": "YES\n102130944040\n80691512"
},
{
"input": "14525757302059286788\n44151238 152801",
"output": "YES\n145257573020\n59286788"
},
{
"input": "443852406270256089240\n54194433 423288",
"output": "YES\n443852406270\n256089240"
},
{
"input": "6450225349035040017740\n8872387 56607460",
"output": "YES\n64502253490\n35040017740"
},
{
"input": "16375289070073689\n33903290 216",
"output": "NO"
},
{
"input": "3415280033041307294\n15179 79809921",
"output": "NO"
},
{
"input": "4261508098904115227\n52546339 6430",
"output": "NO"
},
{
"input": "15016\n15 16",
"output": "YES\n150\n16"
},
{
"input": "120007\n120 7",
"output": "YES\n12000\n7"
},
{
"input": "23\n2 3",
"output": "YES\n2\n3"
}
] | 1,697,263,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | import sys
input = sys.stdin.readline
# flush = sys.stdout.flush()
# from math import gcd, isqrt, ceil, log2
# from collections import defaultdict, deque, Counter
# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound
t = 1
# t = int(input())
for _ in range(t):
s = input().strip()
n, m = map(int, input().split())
ind1 = 0
a = [-1 for i in range(len(s))]
b = [-1 for i in range(len(s))]
l, r = 0, 0
for i in range(len(s)-1,0,-1):
x = len(s)-i-1
l = (l*10 + int(s[x])) % n
r = (int(s[i]) * ind1 + r) % m
ind1 = ind1*10 % m
b[i] = (r if s[i]!='0' else -1)
a[len(s)-i] = l
for i in range(len(s)):
if a[i] == 0 and b[i] == 0:
print("YES")
print(s[:i])
print(s[i:])
break
else:
print("NO") | Title: Hacking Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by *a* as a separate number, and the second (right) part is divisible by *b* as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values *a* and *b*.
Help Polycarpus and find any suitable method to cut the public key.
Input Specification:
The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=108).
Output Specification:
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by *a*, and the right part must be divisible by *b*. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Demo Input:
['116401024\n97 1024\n', '284254589153928171911281811000\n1009 1000\n', '120\n12 1\n']
Demo Output:
['YES\n11640\n1024\n', 'YES\n2842545891539\n28171911281811000\n', 'NO\n']
Note:
none | ```python
import sys
input = sys.stdin.readline
# flush = sys.stdout.flush()
# from math import gcd, isqrt, ceil, log2
# from collections import defaultdict, deque, Counter
# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound
t = 1
# t = int(input())
for _ in range(t):
s = input().strip()
n, m = map(int, input().split())
ind1 = 0
a = [-1 for i in range(len(s))]
b = [-1 for i in range(len(s))]
l, r = 0, 0
for i in range(len(s)-1,0,-1):
x = len(s)-i-1
l = (l*10 + int(s[x])) % n
r = (int(s[i]) * ind1 + r) % m
ind1 = ind1*10 % m
b[i] = (r if s[i]!='0' else -1)
a[len(s)-i] = l
for i in range(len(s)):
if a[i] == 0 and b[i] == 0:
print("YES")
print(s[:i])
print(s[i:])
break
else:
print("NO")
``` | 0 |
|
625 | C | K-special Tables | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you forget, the table *n*<=×<=*n* is called *k*-special if the following three conditions are satisfied:
- every integer from 1 to *n*2 appears in the table exactly once; - in each row numbers are situated in increasing order; - the sum of numbers in the *k*-th column is maximum possible.
Your goal is to help Alice and find at least one *k*-special table of size *n*<=×<=*n*. Both rows and columns are numbered from 1 to *n*, with rows numbered from top to bottom and columns numbered from left to right. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you are allowed to print any. | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | 1,000 | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
{
"input": "2 2",
"output": "7\n1 3\n2 4"
},
{
"input": "500 1",
"output": "62375500\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "3 1",
"output": "12\n1 2 3\n4 5 6\n7 8 9"
},
{
"input": "3 2",
"output": "18\n1 4 5\n2 6 7\n3 8 9"
},
{
"input": "3 3",
"output": "24\n1 2 7\n3 4 8\n5 6 9"
},
{
"input": "4 2",
"output": "38\n1 5 6 7\n2 8 9 10\n3 11 12 13\n4 14 15 16"
},
{
"input": "4 3",
"output": "48\n1 2 9 10\n3 4 11 12\n5 6 13 14\n7 8 15 16"
},
{
"input": "4 4",
"output": "58\n1 2 3 13\n4 5 6 14\n7 8 9 15\n10 11 12 16"
},
{
"input": "5 1",
"output": "55\n1 2 3 4 5\n6 7 8 9 10\n11 12 13 14 15\n16 17 18 19 20\n21 22 23 24 25"
},
{
"input": "5 2",
"output": "70\n1 6 7 8 9\n2 10 11 12 13\n3 14 15 16 17\n4 18 19 20 21\n5 22 23 24 25"
},
{
"input": "5 4",
"output": "100\n1 2 3 16 17\n4 5 6 18 19\n7 8 9 20 21\n10 11 12 22 23\n13 14 15 24 25"
},
{
"input": "5 5",
"output": "115\n1 2 3 4 21\n5 6 7 8 22\n9 10 11 12 23\n13 14 15 16 24\n17 18 19 20 25"
},
{
"input": "6 1",
"output": "96\n1 2 3 4 5 6\n7 8 9 10 11 12\n13 14 15 16 17 18\n19 20 21 22 23 24\n25 26 27 28 29 30\n31 32 33 34 35 36"
},
{
"input": "6 2",
"output": "117\n1 7 8 9 10 11\n2 12 13 14 15 16\n3 17 18 19 20 21\n4 22 23 24 25 26\n5 27 28 29 30 31\n6 32 33 34 35 36"
},
{
"input": "6 3",
"output": "138\n1 2 13 14 15 16\n3 4 17 18 19 20\n5 6 21 22 23 24\n7 8 25 26 27 28\n9 10 29 30 31 32\n11 12 33 34 35 36"
},
{
"input": "6 4",
"output": "159\n1 2 3 19 20 21\n4 5 6 22 23 24\n7 8 9 25 26 27\n10 11 12 28 29 30\n13 14 15 31 32 33\n16 17 18 34 35 36"
},
{
"input": "6 5",
"output": "180\n1 2 3 4 25 26\n5 6 7 8 27 28\n9 10 11 12 29 30\n13 14 15 16 31 32\n17 18 19 20 33 34\n21 22 23 24 35 36"
},
{
"input": "6 6",
"output": "201\n1 2 3 4 5 31\n6 7 8 9 10 32\n11 12 13 14 15 33\n16 17 18 19 20 34\n21 22 23 24 25 35\n26 27 28 29 30 36"
},
{
"input": "500 500",
"output": "124875250\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 ..."
},
{
"input": "500 250",
"output": "93562750\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "94 3",
"output": "419898\n1 2 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280\n3 4 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 31..."
},
{
"input": "22 4",
"output": "5863\n1 2 3 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85\n4 5 6 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104\n7 8 9 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123\n10 11 12 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142\n13 14 15 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161\n16 17 18 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180\n19 20 21 181 182 183 184 185 18..."
},
{
"input": "15 12",
"output": "2910\n1 2 3 4 5 6 7 8 9 10 11 166 167 168 169\n12 13 14 15 16 17 18 19 20 21 22 170 171 172 173\n23 24 25 26 27 28 29 30 31 32 33 174 175 176 177\n34 35 36 37 38 39 40 41 42 43 44 178 179 180 181\n45 46 47 48 49 50 51 52 53 54 55 182 183 184 185\n56 57 58 59 60 61 62 63 64 65 66 186 187 188 189\n67 68 69 70 71 72 73 74 75 76 77 190 191 192 193\n78 79 80 81 82 83 84 85 86 87 88 194 195 196 197\n89 90 91 92 93 94 95 96 97 98 99 198 199 200 201\n100 101 102 103 104 105 106 107 108 109 110 202 203 204 205\n111..."
},
{
"input": "37 35",
"output": "48581\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 1259 1260 1261\n35 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 1262 1263 1264\n69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 1265 1266 1267\n103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 1268 1269 1270\n137 ..."
},
{
"input": "87 51",
"output": "516954\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 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387\n51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 4388 4389 4390 4391 4392 ..."
},
{
"input": "15 4",
"output": "1950\n1 2 3 46 47 48 49 50 51 52 53 54 55 56 57\n4 5 6 58 59 60 61 62 63 64 65 66 67 68 69\n7 8 9 70 71 72 73 74 75 76 77 78 79 80 81\n10 11 12 82 83 84 85 86 87 88 89 90 91 92 93\n13 14 15 94 95 96 97 98 99 100 101 102 103 104 105\n16 17 18 106 107 108 109 110 111 112 113 114 115 116 117\n19 20 21 118 119 120 121 122 123 124 125 126 127 128 129\n22 23 24 130 131 132 133 134 135 136 137 138 139 140 141\n25 26 27 142 143 144 145 146 147 148 149 150 151 152 153\n28 29 30 154 155 156 157 158 159 160 161 162 1..."
},
{
"input": "183 2",
"output": "3064518\n1 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 ..."
},
{
"input": "103 6",
"output": "567942\n1 2 3 4 5 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613\n6 7 8 9 10 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 6..."
},
{
"input": "131 11",
"output": "1202056\n1 2 3 4 5 6 7 8 9 10 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1..."
},
{
"input": "193 186",
"output": "7039482\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "117 109",
"output": "1539603\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 12637 12638 12639 12640 12641 12642 12643 12644 12645\n109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139..."
},
{
"input": "116 91",
"output": "1384576\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 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466\n91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 1..."
},
{
"input": "140 79",
"output": "2132200\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 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 1..."
},
{
"input": "350 14",
"output": "22175125\n1 2 3 4 5 6 7 8 9 10 11 12 13 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4..."
},
{
"input": "374 9",
"output": "26648248\n1 2 3 4 5 6 7 8 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 ..."
},
{
"input": "265 255",
"output": "18222195\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "289 287",
"output": "24012143\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "276 11",
"output": "10856736\n1 2 3 4 5 6 7 8 9 10 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 ..."
},
{
"input": "204 7",
"output": "4349688\n1 2 3 4 5 6 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 ..."
},
{
"input": "425 15",
"output": "39560275\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 604..."
},
{
"input": "449 6",
"output": "45664198\n1 2 3 4 5 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2..."
},
{
"input": "477 19",
"output": "56204433\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8..."
},
{
"input": "448 437",
"output": "88708928\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "472 459",
"output": "103591728\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 ..."
},
{
"input": "500 494",
"output": "124123750\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 ..."
},
{
"input": "462 318",
"output": "83103405\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "486 481",
"output": "114081696\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 ..."
},
{
"input": "410 361",
"output": "64708660\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
}
] | 1,521,226,481 | 2,381 | Python 3 | OK | TESTS | 52 | 686 | 14,233,600 | R = lambda : map(int, input().split())
n,k = R()
l = 0
r = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(k-1):
l += 1
r[i][j] = l
for i in range(n):
for j in range(k-1,n):
l += 1
r[i][j] = l
s = 0
for i in range(n):
s += r[i][k-1]
print(s)
for i in range(n):
print(*r[i])
| Title: K-special Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you forget, the table *n*<=×<=*n* is called *k*-special if the following three conditions are satisfied:
- every integer from 1 to *n*2 appears in the table exactly once; - in each row numbers are situated in increasing order; - the sum of numbers in the *k*-th column is maximum possible.
Your goal is to help Alice and find at least one *k*-special table of size *n*<=×<=*n*. Both rows and columns are numbered from 1 to *n*, with rows numbered from top to bottom and columns numbered from left to right.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum.
Output Specification:
First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you are allowed to print any.
Demo Input:
['4 1\n', '5 3\n']
Demo Output:
['28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n', '85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n']
Note:
none | ```python
R = lambda : map(int, input().split())
n,k = R()
l = 0
r = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(k-1):
l += 1
r[i][j] = l
for i in range(n):
for j in range(k-1,n):
l += 1
r[i][j] = l
s = 0
for i in range(n):
s += r[i][k-1]
print(s)
for i in range(n):
print(*r[i])
``` | 3 |
|
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input": "10000 1000",
"output": "8991"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 100000000000000000",
"output": "899999999999999991"
},
{
"input": "1000000000000000000 10000000000000000",
"output": "989999999999999991"
},
{
"input": "1000000000000000000 1000000000000000",
"output": "998999999999999991"
},
{
"input": "1000000000000000000 100000000000000",
"output": "999899999999999991"
},
{
"input": "1000000000000000000 200000000000000000",
"output": "799999999999999991"
},
{
"input": "10 5",
"output": "1"
},
{
"input": "20 5",
"output": "11"
},
{
"input": "20 9",
"output": "11"
},
{
"input": "100 9",
"output": "91"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "130 118",
"output": "1"
},
{
"input": "190 181",
"output": "0"
},
{
"input": "1999 1971",
"output": "10"
},
{
"input": "100 99",
"output": "1"
},
{
"input": "6909094398 719694282",
"output": "6189400069"
},
{
"input": "260 258",
"output": "0"
},
{
"input": "35 19",
"output": "6"
},
{
"input": "100 87",
"output": "1"
},
{
"input": "91 89",
"output": "0"
},
{
"input": "109 89",
"output": "10"
},
{
"input": "109 91",
"output": "10"
},
{
"input": "20331 11580",
"output": "8732"
},
{
"input": "405487470 255750281",
"output": "149737161"
},
{
"input": "17382 12863",
"output": "4493"
},
{
"input": "19725 14457",
"output": "5246"
},
{
"input": "24848 15384",
"output": "9449"
},
{
"input": "25727 15982",
"output": "9728"
},
{
"input": "109 90",
"output": "10"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "1"
},
{
"input": "1000000000000000000 999999999999999998",
"output": "1"
},
{
"input": "1009 980",
"output": "10"
},
{
"input": "999999999999999999 999999999999999838",
"output": "0"
},
{
"input": "1000000000000000000 99999999999999800",
"output": "900000000000000061"
},
{
"input": "8785369357 3377262261",
"output": "5408107058"
},
{
"input": "110 109",
"output": "0"
},
{
"input": "999 777",
"output": "200"
},
{
"input": "327170000015578 77230000029054",
"output": "249939999986479"
},
{
"input": "12515000022229 1791000022317",
"output": "10723999999880"
},
{
"input": "9999999999999 9999999999882",
"output": "10"
},
{
"input": "213 196",
"output": "14"
},
{
"input": "92 82",
"output": "0"
},
{
"input": "148 136",
"output": "0"
},
{
"input": "8 9",
"output": "0"
},
{
"input": "309 299",
"output": "0"
},
{
"input": "9999 9963",
"output": "10"
},
{
"input": "82 81",
"output": "0"
},
{
"input": "9999999 9999936",
"output": "10"
},
{
"input": "171 155",
"output": "2"
},
{
"input": "999 972",
"output": "10"
},
{
"input": "999999999999 999999999891",
"output": "10"
},
{
"input": "9 9",
"output": "0"
},
{
"input": "6900 6885",
"output": "1"
},
{
"input": "96 57",
"output": "27"
},
{
"input": "5 4",
"output": "0"
},
{
"input": "17386 5814",
"output": "11557"
},
{
"input": "493679757404593 316259583979965",
"output": "177420173424564"
},
{
"input": "18474 9478",
"output": "8975"
},
{
"input": "270091571496186 250931112649966",
"output": "19160458846177"
},
{
"input": "565751690089037 381448507916936",
"output": "184303182172038"
},
{
"input": "19 10",
"output": "0"
}
] | 1,527,182,187 | 2,787 | Python 3 | OK | TESTS | 68 | 78 | 0 | #!/usr/bin/env python3
[n, s] = map(int, input().strip().split())
def sumdigit(x):
return sum(map(int, str(x)))
def fsum(x):
return x - sumdigit(x)
# first x in (xmin, xmax] that fsum(x) >= s
def binsearch(s, xmin, xmax):
while xmax - xmin > 1:
xmid = (xmax + xmin) // 2
if fsum(xmid) >= s:
xmax = xmid
else:
xmin = xmid
return xmax
xmin = 0
xmax = 1
while fsum(xmax) < s:
xmin = xmax
xmax *= 2
x = binsearch(s, xmin, xmax)
print (max(n - x + 1, 0))
| Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input Specification:
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Output Specification:
Print one integer — the quantity of really big numbers that are not greater than *n*.
Demo Input:
['12 1\n', '25 20\n', '10 9\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | ```python
#!/usr/bin/env python3
[n, s] = map(int, input().strip().split())
def sumdigit(x):
return sum(map(int, str(x)))
def fsum(x):
return x - sumdigit(x)
# first x in (xmin, xmax] that fsum(x) >= s
def binsearch(s, xmin, xmax):
while xmax - xmin > 1:
xmid = (xmax + xmin) // 2
if fsum(xmid) >= s:
xmax = xmid
else:
xmin = xmid
return xmax
xmin = 0
xmax = 1
while fsum(xmax) < s:
xmin = xmax
xmax *= 2
x = binsearch(s, xmin, xmax)
print (max(n - x + 1, 0))
``` | 3 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,622,917,141 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | n=int(input())
s=input()
def find_ten(s):
lst=list()
for i in s:
if i=='1':
lst.append(i)
else:
if not lst:
lst.append(i)
else:
lst.pop()
return len(lst)
print(find_ten(s)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n=int(input())
s=input()
def find_ten(s):
lst=list()
for i in s:
if i=='1':
lst.append(i)
else:
if not lst:
lst.append(i)
else:
lst.pop()
return len(lst)
print(find_ten(s))
``` | 0 |
|
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,493,383,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | list = list(map(int, input().split(" ")))
list.sort()
count=0
count1=1
index =[]
list.append(-1)
for i in range(len(list)-1):
count= list.count(list[i])
if list[i] == list[i+1]:
count1 = count1 +1
if count==1:
index.append(i)
print(count)
if len(index)==2 or len(index)== 1 :
print('Bear')
elif len(index)==0:
print('Elephant')
elif count1==3:
print('Alien')
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
list = list(map(int, input().split(" ")))
list.sort()
count=0
count1=1
index =[]
list.append(-1)
for i in range(len(list)-1):
count= list.count(list[i])
if list[i] == list[i+1]:
count1 = count1 +1
if count==1:
index.append(i)
print(count)
if len(index)==2 or len(index)== 1 :
print('Bear')
elif len(index)==0:
print('Elephant')
elif count1==3:
print('Alien')
else:
print('Alien')
``` | 0 |
|
797 | C | Minimal string | PROGRAMMING | 1,700 | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character.
Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal.
You should write a program that will help Petya win the game. | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | 0 | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
"output": "bcmrh"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb"
},
{
"input": "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg",
"output": "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee"
},
{
"input": "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr",
"output": "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn"
},
{
"input": "bcaeaae",
"output": "aaaecbe"
},
{
"input": "edcadcbcdd",
"output": "abccdcddde"
},
{
"input": "a",
"output": "a"
},
{
"input": "a",
"output": "a"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "b",
"output": "b"
},
{
"input": "a",
"output": "a"
},
{
"input": "c",
"output": "c"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "c",
"output": "c"
},
{
"input": "b",
"output": "b"
},
{
"input": "a",
"output": "a"
},
{
"input": "e",
"output": "e"
},
{
"input": "b",
"output": "b"
},
{
"input": "b",
"output": "b"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "ca",
"output": "ac"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "cb",
"output": "bc"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "da",
"output": "ad"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "cd",
"output": "cd"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aab",
"output": "aab"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "baa",
"output": "aab"
},
{
"input": "bab",
"output": "abb"
},
{
"input": "baa",
"output": "aab"
},
{
"input": "ccc",
"output": "ccc"
},
{
"input": "ddd",
"output": "ddd"
},
{
"input": "ccd",
"output": "ccd"
},
{
"input": "bca",
"output": "acb"
},
{
"input": "cde",
"output": "cde"
},
{
"input": "ece",
"output": "cee"
},
{
"input": "bdd",
"output": "bdd"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "abaa",
"output": "aaab"
},
{
"input": "abab",
"output": "aabb"
},
{
"input": "bbbb",
"output": "bbbb"
},
{
"input": "bbba",
"output": "abbb"
},
{
"input": "caba",
"output": "aabc"
},
{
"input": "ccbb",
"output": "bbcc"
},
{
"input": "abac",
"output": "aabc"
},
{
"input": "daba",
"output": "aabd"
},
{
"input": "cdbb",
"output": "bbdc"
},
{
"input": "bddd",
"output": "bddd"
},
{
"input": "dacb",
"output": "abcd"
},
{
"input": "abcc",
"output": "abcc"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "baaab",
"output": "aaabb"
},
{
"input": "aabbb",
"output": "aabbb"
},
{
"input": "aabaa",
"output": "aaaab"
},
{
"input": "abcba",
"output": "aabcb"
},
{
"input": "bacbc",
"output": "abbcc"
},
{
"input": "bacba",
"output": "aabcb"
},
{
"input": "bdbda",
"output": "adbdb"
},
{
"input": "accbb",
"output": "abbcc"
},
{
"input": "dbccc",
"output": "bcccd"
},
{
"input": "decca",
"output": "acced"
},
{
"input": "dbbdd",
"output": "bbddd"
},
{
"input": "accec",
"output": "accce"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "bbbbab",
"output": "abbbbb"
},
{
"input": "bbbbab",
"output": "abbbbb"
},
{
"input": "aaaaba",
"output": "aaaaab"
},
{
"input": "cbbbcc",
"output": "bbbccc"
},
{
"input": "aaacac",
"output": "aaaacc"
},
{
"input": "bacbbc",
"output": "abbbcc"
},
{
"input": "cacacc",
"output": "aacccc"
},
{
"input": "badbdc",
"output": "abbcdd"
},
{
"input": "ddadad",
"output": "aadddd"
},
{
"input": "ccdece",
"output": "cccede"
},
{
"input": "eecade",
"output": "acdeee"
},
{
"input": "eabdcb",
"output": "abbcde"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaabbaa",
"output": "aaaaabb"
},
{
"input": "baaabab",
"output": "aaaabbb"
},
{
"input": "bbababa",
"output": "aaabbbb"
},
{
"input": "bcccacc",
"output": "acccbcc"
},
{
"input": "cbbcccc",
"output": "bbccccc"
},
{
"input": "abacaaa",
"output": "aaaaacb"
},
{
"input": "ccdbdac",
"output": "acdbdcc"
},
{
"input": "bbacaba",
"output": "aaabcbb"
},
{
"input": "abbaccc",
"output": "aabbccc"
},
{
"input": "bdcbcab",
"output": "abcbcdb"
},
{
"input": "dabcbce",
"output": "abbccde"
},
{
"input": "abaaabe",
"output": "aaaabbe"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ababbbba",
"output": "aaabbbbb"
},
{
"input": "aaaaaaba",
"output": "aaaaaaab"
},
{
"input": "babbbaab",
"output": "aaabbbbb"
},
{
"input": "bcaccaab",
"output": "aaabcccb"
},
{
"input": "bbccaabc",
"output": "aabccbbc"
},
{
"input": "cacaaaac",
"output": "aaaaaccc"
},
{
"input": "daacbddc",
"output": "aabccddd"
},
{
"input": "cdbdcdaa",
"output": "aadcdbdc"
},
{
"input": "bccbdacd",
"output": "acdbccbd"
},
{
"input": "abbeaade",
"output": "aaadebbe"
},
{
"input": "ccabecba",
"output": "aabcebcc"
},
{
"input": "ececaead",
"output": "aadecece"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aabaaabbb",
"output": "aaaaabbbb"
},
{
"input": "abbbbbaab",
"output": "aaabbbbbb"
},
{
"input": "bbbaababb",
"output": "aaabbbbbb"
},
{
"input": "babcaaccb",
"output": "aaabcccbb"
},
{
"input": "ccbcabaac",
"output": "aaabcbccc"
},
{
"input": "caaaccccb",
"output": "aaabccccc"
},
{
"input": "abbcdbddb",
"output": "abbbbdddc"
},
{
"input": "dbcaacbbb",
"output": "aabbbccbd"
},
{
"input": "cadcbddac",
"output": "aacddbcdc"
},
{
"input": "ecebadadb",
"output": "aabddbece"
},
{
"input": "bdbeeccdd",
"output": "bbccddeed"
},
{
"input": "daaedecda",
"output": "aaadceded"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "abaaaaabbb",
"output": "aaaaaabbbb"
},
{
"input": "bbaaaabaaa",
"output": "aaaaaaabbb"
},
{
"input": "bbabbaaaaa",
"output": "aaaaaabbbb"
},
{
"input": "cbaabcaacc",
"output": "aaaacbbccc"
},
{
"input": "aaaaccccab",
"output": "aaaaabcccc"
},
{
"input": "bccaccaacc",
"output": "aaaccccbcc"
},
{
"input": "dbdccdcacd",
"output": "accdccdbdd"
},
{
"input": "caaddaaccb",
"output": "aaaabccddc"
},
{
"input": "adbbabcbdc",
"output": "aabbbbccdd"
},
{
"input": "cdeabdbbad",
"output": "aabbdbdedc"
},
{
"input": "eeddcbeeec",
"output": "bcceeeddee"
},
{
"input": "bbcebddeba",
"output": "abeddbecbb"
}
] | 1,592,215,379 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | s=input()
t=[]
u=[]
i=0
while i<len(s):
m=0
if len(t)!=0:
a=t[-1]
for c in range(i,len(s)):
if s[c]<a:
m=c
a=s[m]
if m==0:
u.append(t.pop())
t.append(s[i])
i+=1
else:
for c in range(i,m+1):
t.append(s[c])
while len(t)!=0 :
u.append(t.pop())
i=m+1
else:
t.append(s[i])
i+=1
while(len(t)!=0):
u.append(t.pop())
print(('').join(u))
| Title: Minimal string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character.
Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal.
You should write a program that will help Petya win the game.
Input Specification:
First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters.
Output Specification:
Print resulting string *u*.
Demo Input:
['cab\n', 'acdb\n']
Demo Output:
['abc\n', 'abdc\n']
Note:
none | ```python
s=input()
t=[]
u=[]
i=0
while i<len(s):
m=0
if len(t)!=0:
a=t[-1]
for c in range(i,len(s)):
if s[c]<a:
m=c
a=s[m]
if m==0:
u.append(t.pop())
t.append(s[i])
i+=1
else:
for c in range(i,m+1):
t.append(s[c])
while len(t)!=0 :
u.append(t.pop())
i=m+1
else:
t.append(s[i])
i+=1
while(len(t)!=0):
u.append(t.pop())
print(('').join(u))
``` | 0 |
|
722 | B | Verse Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.
Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.
The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*.
You are given the text and the verse pattern. Check, if the given text matches the given verse pattern. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters. | If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"3\n2 2 3\nintel\ncode\nch allenge\n",
"4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | 500 | [
{
"input": "3\n2 2 3\nintel\ncode\nch allenge",
"output": "YES"
},
{
"input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz",
"output": "NO"
},
{
"input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles",
"output": "YES"
},
{
"input": "5\n2 2 1 1 1\nfdbie\naaj\ni\ni n\nshi",
"output": "YES"
},
{
"input": "5\n2 11 10 7 9\nhy of\nyur pjyacbatdoylojayu\nemd ibweioiimyxya\nyocpyivudobua\nuiraueect impxqhzpty e",
"output": "NO"
},
{
"input": "5\n6 9 7 3 10\nabtbdaa\nom auhz ub iaravozegs\ncieulibsdhj ufki\nadu pnpurt\nh naony i jaysjsjxpwuuc",
"output": "NO"
},
{
"input": "2\n26 35\ngouojxaoobw iu bkaadyo degnjkubeabt kbap thwki dyebailrhnoh ooa\npiaeaebaocptyswuc wezesazipu osebhaonouygasjrciyiqaejtqsioubiuakg umynbsvw xpfqdwxo",
"output": "NO"
},
{
"input": "5\n1 0 0 1 1\ngqex\nw\nh\nzsvu\nqcqd",
"output": "NO"
},
{
"input": "5\n0 0 0 0 0\njtv\nl\nqg\ntp\nfgd",
"output": "YES"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0\nj t fr\nn\nnhcgx\np\nmb hmhtz\ndbjc\ncwdxj\nn j whkbt\nzk m cwh\nqr n",
"output": "YES"
},
{
"input": "5\n4 5 1 0 0\noa\nqfohq\ni l\naik\nx",
"output": "NO"
},
{
"input": "10\n2 9 0 3 2 4 1 2 4 2\nxtwl oy\nafgeju fi\nr hy\nddsowagw\nxoredo f\nwufnxy k uh\nod\nlejrinw\nsueecohfjl\nedufg",
"output": "NO"
},
{
"input": "10\n1 1 0 0 0 4 0 4 0 0\na bn\nhnwss f\nd s bn\nbdzxzgsxq\nghh v\neimblv i er\nca kn k\nzm ffc zcb\nn\nz hkhvfkwhg",
"output": "NO"
},
{
"input": "5\n0 10 6 6 0\nfgthrxst\nsohnweymewnnmbobj\nj\nfwwt acdtfvkpv khbxokn\nhndovkkgfhnhqod",
"output": "NO"
},
{
"input": "5\n3 2 2 4 2\ni yu\niu\noa\naiio\nuo",
"output": "YES"
},
{
"input": "5\n11 12 11 4 6\nuuuayoiaoiy\nuaiee iai eieu\nooayaayeuee\noii o\noea uuo",
"output": "YES"
},
{
"input": "3\n2 3 2\nintel\ncode\nch allenge",
"output": "NO"
},
{
"input": "2\n1 2\ncode\na",
"output": "NO"
},
{
"input": "2\n1 1\nbababa\nbababa",
"output": "NO"
},
{
"input": "1\n1\naa",
"output": "NO"
},
{
"input": "1\n1\naaa",
"output": "NO"
},
{
"input": "2\n2 3\naee\nae",
"output": "NO"
}
] | 1,667,492,249 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n = int(input())
l = list(map(int,input().split()))
flag = 1
for i in range(n):
s = input()
res = 0
for c in s:
if c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' or c == 'y':
res += 1
if res < l[i]:
flag = 0
print('YES' if flag else 'NO') | Title: Verse Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.
Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.
The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*.
You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.
Output Specification:
If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
Demo Input:
['3\n2 2 3\nintel\ncode\nch allenge\n', '4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n', '4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | ```python
n = int(input())
l = list(map(int,input().split()))
flag = 1
for i in range(n):
s = input()
res = 0
for c in s:
if c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' or c == 'y':
res += 1
if res < l[i]:
flag = 0
print('YES' if flag else 'NO')
``` | 0 |
|
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 1,698,665,270 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 0 | input()
ls = list(map(int,input().split()))
mx = max(ls)
x = 0
for i in ls:
x+=mx-i
print(x) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
Output Specification:
In the only line print the integer *S* — the minimum number of burles which are had to spend.
Demo Input:
['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n']
Demo Output:
['10', '1', '4', '0']
Note:
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | ```python
input()
ls = list(map(int,input().split()))
mx = max(ls)
x = 0
for i in ls:
x+=mx-i
print(x)
``` | 3 |
|
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++",
"output": "4"
},
{
"input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++",
"output": "-10"
},
{
"input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X",
"output": "-14"
},
{
"input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X",
"output": "3"
},
{
"input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X",
"output": "-5"
},
{
"input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X",
"output": "1"
},
{
"input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--",
"output": "1"
},
{
"input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++",
"output": "-3"
},
{
"input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X",
"output": "1"
},
{
"input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++",
"output": "8"
},
{
"input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++",
"output": "-1"
},
{
"input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--",
"output": "-5"
},
{
"input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--",
"output": "1"
},
{
"input": "1\nX--",
"output": "-1"
}
] | 1,697,548,583 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
x=0
for i in range(n):
my_input=str(input())
if '++x' in my_input.lower() or 'x++' in my_input.lower():
x+=1
elif '--x' in my_input.lower() or '--x' in my_input.lower():
x-=1
print(x)
| Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Output Specification:
Print a single integer — the final value of *x*.
Demo Input:
['1\n++X\n', '2\nX++\n--X\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
n=int(input())
x=0
for i in range(n):
my_input=str(input())
if '++x' in my_input.lower() or 'x++' in my_input.lower():
x+=1
elif '--x' in my_input.lower() or '--x' in my_input.lower():
x-=1
print(x)
``` | 0 |
|
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,696,839,014 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | # LUOGU_RID: 128406973
print(15*'ROYGBIV'[:int(input())]) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
# LUOGU_RID: 128406973
print(15*'ROYGBIV'[:int(input())])
``` | 0 |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.
So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).
For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even).
Print the total money grandma should have at the end of the day to check if some buyers cheated her. | The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.
It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day. | Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"output": "1"
},
{
"input": "5 6\nhalf\nhalf\nhalfplus\nhalf\nhalfplus",
"output": "114"
},
{
"input": "10 2\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus",
"output": "1703"
},
{
"input": "20 6\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalfplus",
"output": "6056877"
},
{
"input": "30 68\nhalf\nhalf\nhalf\nhalfplus\nhalfplus\nhalf\nhalf\nhalf\nhalf\nhalf\nhalf\nhalf\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus",
"output": "59847312584"
},
{
"input": "40 562\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "486750560068982"
}
] | 1,456,848,769 | 4,369 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | x=input().split()
y=list()
a=0
w=0
for i in range(int(x[0])):
z=input()
y.append(z)
if z=='halfplus':
a+=1
if i==0:
w=1
half=int(x[1])/2
if a==(i+1):
print(int(int(x[1])*((2**int(x[0]))-1)-(int(x[0])*half)))
elif w==1:
print(int(int(x[1])*(2**(int(x[0])-1)+1)-(int(x[0])-1)*half))
else :
print(int(int(x[1])*((2**(int(x[0])-1)))-(int(x[0])-1)*half)) | Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.
So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).
For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even).
Print the total money grandma should have at the end of the day to check if some buyers cheated her.
Input Specification:
The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.
It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.
Output Specification:
Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['2 10\nhalf\nhalfplus\n', '3 10\nhalfplus\nhalfplus\nhalfplus\n']
Demo Output:
['15\n', '55\n']
Note:
In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | ```python
x=input().split()
y=list()
a=0
w=0
for i in range(int(x[0])):
z=input()
y.append(z)
if z=='halfplus':
a+=1
if i==0:
w=1
half=int(x[1])/2
if a==(i+1):
print(int(int(x[1])*((2**int(x[0]))-1)-(int(x[0])*half)))
elif w==1:
print(int(int(x[1])*(2**(int(x[0])-1)+1)-(int(x[0])-1)*half))
else :
print(int(int(x[1])*((2**(int(x[0])-1)))-(int(x[0])-1)*half))
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,693,500,407 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | t=input()
s='hello'
j=0
for i in range(len(t)):
if t[i]==s[j]:
j+=1
if j==5:
print('YES')
break
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
t=input()
s='hello'
j=0
for i in range(len(t)):
if t[i]==s[j]:
j+=1
if j==5:
print('YES')
break
else:
print('NO')
``` | 3.969 |
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,646,112,280 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s = input()
t = input()
out = ''
lis = list(s)
for id in reversed(lis):
out = out +id
if t == out:
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
s = input()
t = input()
out = ''
lis = list(s)
for id in reversed(lis):
out = out +id
if t == out:
print("YES")
else:
print("NO")
``` | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation:
A swap operation is the following sequence of actions:
- choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*.
What maximum value of function *m*(*a*) can Sereja get if he is allowed to perform at most *k* swap operations? | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200; 1<=≤<=*k*<=≤<=10). The next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=1000<=≤<=*a*[*i*]<=≤<=1000). | In a single line print the maximum value of *m*(*a*) that Sereja can get if he is allowed to perform at most *k* swap operations. | [
"10 2\n10 -1 2 2 2 2 2 2 -1 10\n",
"5 10\n-1 -1 -1 -1 -1\n"
] | [
"32\n",
"-1\n"
] | none | 0 | [
{
"input": "10 2\n10 -1 2 2 2 2 2 2 -1 10",
"output": "32"
},
{
"input": "5 10\n-1 -1 -1 -1 -1",
"output": "-1"
},
{
"input": "18 1\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466",
"output": "5016"
},
{
"input": "29 6\n-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7",
"output": "6299"
},
{
"input": "9 9\n-767 148 -323 -818 41 -228 615 885 -260",
"output": "1689"
},
{
"input": "35 5\n151 -160 -292 -31 -131 174 359 42 438 413 164 91 118 393 76 435 371 -76 145 605 292 578 623 405 664 330 455 329 66 168 179 -76 996 163 531",
"output": "9754"
},
{
"input": "47 10\n-175 246 -903 681 748 -338 333 0 666 245 370 402 -38 682 144 658 -10 313 295 351 -95 149 111 -210 645 -173 -276 690 593 697 259 698 421 584 -229 445 -215 -203 49 642 386 649 469 4 340 484 279",
"output": "14728"
},
{
"input": "11 7\n877 -188 10 -175 217 -254 841 380 552 -607 228",
"output": "3105"
},
{
"input": "38 1\n173 587 -788 163 83 -768 461 -527 350 3 -898 634 -217 -528 317 -238 545 93 -964 283 -798 -596 77 222 -370 -209 61 846 -831 -419 -366 -509 -356 -649 916 -391 981 -596",
"output": "2743"
},
{
"input": "6 9\n-669 45 -220 544 106 680",
"output": "1375"
},
{
"input": "32 9\n-650 -208 506 812 -540 -275 -272 -236 -96 197 425 475 81 570 281 633 449 396 401 -362 -379 667 717 875 658 114 294 100 286 112 -928 -373",
"output": "9049"
},
{
"input": "36 5\n-286 762 -5 -230 -483 -140 -143 -82 -127 449 435 85 -262 567 454 -163 942 -679 -609 854 -533 717 -101 92 -767 795 -804 -953 -754 -251 -100 884 809 -358 469 -112",
"output": "8222"
},
{
"input": "24 5\n-751 889 721 -900 903 -900 -693 895 828 314 836 -493 549 -74 264 662 229 517 -223 367 141 -99 -390 283",
"output": "8398"
},
{
"input": "82 8\n-483 465 435 -789 80 -412 672 512 -755 981 784 -281 -634 -270 806 887 -495 -46 -244 609 42 -821 100 -40 -299 -6 560 941 523 758 -730 -930 91 -138 -299 0 533 -208 -416 869 967 -871 573 165 -279 298 934 -236 70 800 550 433 139 147 139 -212 137 -933 -863 876 -622 193 -121 -944 983 -592 -40 -712 891 985 16 580 -845 -903 -986 952 -95 -613 -2 -45 -86 -206",
"output": "18704"
},
{
"input": "116 10\n477 -765 -756 376 -48 -75 768 -658 263 -207 362 -535 96 -960 630 -686 609 -830 889 57 -239 346 -298 -18 -107 853 -607 -443 -517 371 657 105 479 498 -47 432 503 -917 -656 610 -466 216 -747 -587 -163 -174 493 -882 853 -582 -774 -477 -386 610 -58 557 968 196 69 610 -38 366 -79 574 170 317 332 189 158 -194 136 -151 500 309 624 316 543 472 132 -15 -78 166 360 -71 12 247 678 263 573 -198 1 101 155 -65 597 -93 60 3 -496 985 -586 -761 -532 506 578 -13 569 845 -341 870 -900 891 724 408 229 -210",
"output": "24624"
},
{
"input": "110 4\n-813 -73 334 667 602 -155 432 -133 689 397 461 499 630 40 69 299 697 449 -130 210 -146 415 292 123 12 -105 444 338 509 497 142 688 603 107 -108 160 211 -215 219 -144 637 -173 615 -210 521 545 377 -6 -187 354 647 309 139 309 155 -242 546 -231 -267 405 411 -271 -149 264 -169 -447 -749 -218 273 -798 -135 839 54 -764 279 -578 -641 -152 -881 241 174 31 525 621 -855 656 482 -197 -402 995 785 338 -733 293 606 294 -645 262 909 325 -246 -952 408 646 2 -567 -484 661 -390 -488",
"output": "20286"
},
{
"input": "94 2\n432 255 304 757 -438 52 461 55 837 -564 304 713 -968 -539 -593 835 -824 -532 38 -880 -772 480 -755 -387 -830 286 -38 -202 -273 423 272 471 -224 306 490 532 -210 -245 -20 680 -236 404 -5 -188 387 582 -30 -800 276 -811 240 -4 214 -708 200 -785 -466 61 16 -742 647 -371 -851 -295 -552 480 38 924 403 704 -705 -972 677 569 450 446 816 396 -179 281 -564 -27 -272 -640 809 29 28 -209 -925 997 -268 133 265 161",
"output": "7839"
},
{
"input": "78 8\n-230 -757 673 -284 381 -324 -96 975 249 971 -355 186 -526 804 147 -553 655 263 -247 775 108 -246 -107 25 -786 -372 -24 -619 265 -192 269 392 210 449 335 -207 371 562 307 141 668 78 13 251 623 -238 60 543 618 201 73 -35 -663 620 485 444 330 362 -33 484 685 257 542 375 -952 48 -604 -288 -19 -718 -798 946 -533 -666 -686 -278 368 -294",
"output": "17941"
},
{
"input": "1 10\n-1",
"output": "-1"
},
{
"input": "1 1\n-1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n1",
"output": "1"
},
{
"input": "10 1\n-1 1 1 1 1 1 1 1 1 1",
"output": "9"
}
] | 1,399,059,947 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 904 | 204,800 | R = lambda:map(int, input().split())
n, k = R()
a = list(R())
def f(l, r):
x = sorted(a[:l] + a[r + 1:], reverse=True)
y = sorted(a[l:r + 1])
return sum(y + [max(0, x[i] - y[i]) for i in range(min(k, len(x), len(y)))])
print(max(f(l, r) for l in range(n) for r in range(l, n))) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation:
A swap operation is the following sequence of actions:
- choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*.
What maximum value of function *m*(*a*) can Sereja get if he is allowed to perform at most *k* swap operations?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200; 1<=≤<=*k*<=≤<=10). The next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=1000<=≤<=*a*[*i*]<=≤<=1000).
Output Specification:
In a single line print the maximum value of *m*(*a*) that Sereja can get if he is allowed to perform at most *k* swap operations.
Demo Input:
['10 2\n10 -1 2 2 2 2 2 2 -1 10\n', '5 10\n-1 -1 -1 -1 -1\n']
Demo Output:
['32\n', '-1\n']
Note:
none | ```python
R = lambda:map(int, input().split())
n, k = R()
a = list(R())
def f(l, r):
x = sorted(a[:l] + a[r + 1:], reverse=True)
y = sorted(a[l:r + 1])
return sum(y + [max(0, x[i] - y[i]) for i in range(min(k, len(x), len(y)))])
print(max(f(l, r) for l in range(n) for r in range(l, n)))
``` | 3 |
|
923 | B | Producing Snow | PROGRAMMING | 1,600 | [
"binary search",
"data structures"
] | null | null | Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days.
The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*.
The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*T**i*<=≤<=109), where *T**i* is the temperature on the day *i*. | Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. | [
"3\n10 10 5\n5 7 2\n",
"5\n30 25 20 15 10\n9 10 12 4 13\n"
] | [
"5 12 4\n",
"9 20 35 11 25\n"
] | In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | 1,000 | [
{
"input": "3\n10 10 5\n5 7 2",
"output": "5 12 4"
},
{
"input": "5\n30 25 20 15 10\n9 10 12 4 13",
"output": "9 20 35 11 25"
},
{
"input": "4\n0 0 0 0\n1 2 3 4",
"output": "0 0 0 0"
},
{
"input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2",
"output": "10 0 9 27 27 30 28 17 12 4"
},
{
"input": "10\n20 35 4 0 6 29 4 9 17 10\n0 9 4 7 5 1 4 3 9 4",
"output": "0 18 12 14 10 3 12 9 26 12"
},
{
"input": "1\n4\n5",
"output": "4"
},
{
"input": "1\n5\n4",
"output": "4"
},
{
"input": "1\n5\n5",
"output": "5"
},
{
"input": "2\n9 3\n8 2",
"output": "8 3"
},
{
"input": "2\n9 3\n4 4",
"output": "4 7"
},
{
"input": "2\n9 3\n10 2",
"output": "9 2"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1"
}
] | 1,690,485,786 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | print("_RANDOM_GUESS_1690485786.362685")# 1690485786.362707 | Title: Producing Snow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input Specification:
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days.
The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*.
The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*T**i*<=≤<=109), where *T**i* is the temperature on the day *i*.
Output Specification:
Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*.
Demo Input:
['3\n10 10 5\n5 7 2\n', '5\n30 25 20 15 10\n9 10 12 4 13\n']
Demo Output:
['5 12 4\n', '9 20 35 11 25\n']
Note:
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | ```python
print("_RANDOM_GUESS_1690485786.362685")# 1690485786.362707
``` | 0 |
|
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well. | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))",
"output": "28 1"
},
{
"input": ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))",
"output": "68 1"
},
{
"input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((",
"output": "80 1"
},
{
"input": "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()))(()()()))))(()()))())))))((())())()))((",
"output": "92 1"
}
] | 1,587,561,942 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | # -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 08:48:43 2020
@author: XaK
"""
string = input()
par_ab = 0
par_cer = 0
pare_reg = 0
cadena_sub = 0
reg_bol = False
for i in string:
if(par_ab>0 and i ==")"):
pare_reg+=1
par_ab-=1
if(i=="("):
par_ab+=1
reg_bol = True
if(reg_bol==True and par_ab == 0 and par_cer == 0):
cadena_sub+=1
reg_bol = False
if(pare_reg !=0):
print(pare_reg,cadena_sub)
else:
print("0 1")
| Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
Input Specification:
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Output Specification:
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
Demo Input:
[')((())))(()())\n', '))(\n']
Demo Output:
['6 2\n', '0 1\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 08:48:43 2020
@author: XaK
"""
string = input()
par_ab = 0
par_cer = 0
pare_reg = 0
cadena_sub = 0
reg_bol = False
for i in string:
if(par_ab>0 and i ==")"):
pare_reg+=1
par_ab-=1
if(i=="("):
par_ab+=1
reg_bol = True
if(reg_bol==True and par_ab == 0 and par_cer == 0):
cadena_sub+=1
reg_bol = False
if(pare_reg !=0):
print(pare_reg,cadena_sub)
else:
print("0 1")
``` | 0 |
257 | B | Playing Cubes | PROGRAMMING | 1,300 | [
"games",
"greedy",
"implementation"
] | null | null | Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pairs of neighbouring cubes of the same color as possible. Vasya's task is to get as many pairs of neighbouring cubes of different colors as possible.
The number of Petya's points in the game is the number of pairs of neighboring cubes of the same color in the line, the number of Vasya's points in the game is the number of neighbouring cubes of the different color in the line. Your task is to calculate the score at the end of the game (Petya's and Vasya's points, correspondingly), if both boys are playing optimally well. To "play optimally well" first of all means to maximize the number of one's points, and second — to minimize the number of the opponent's points. | The only line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of red and blue cubes, correspondingly. | On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well. | [
"3 1\n",
"2 4\n"
] | [
"2 1\n",
"3 2\n"
] | In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cube during his first move, then, provided that both boys play optimally well, Petya would get 1 point and Vasya would get 2 points. | 500 | [
{
"input": "3 1",
"output": "2 1"
},
{
"input": "2 4",
"output": "3 2"
},
{
"input": "1 1",
"output": "0 1"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "4 4",
"output": "3 4"
},
{
"input": "10 7",
"output": "9 7"
},
{
"input": "5 13",
"output": "12 5"
},
{
"input": "7 11",
"output": "10 7"
},
{
"input": "1 2",
"output": "1 1"
},
{
"input": "10 10",
"output": "9 10"
},
{
"input": "50 30",
"output": "49 30"
},
{
"input": "80 120",
"output": "119 80"
},
{
"input": "304 122",
"output": "303 122"
},
{
"input": "500 800",
"output": "799 500"
},
{
"input": "900 1000",
"output": "999 900"
},
{
"input": "1 1000",
"output": "999 1"
},
{
"input": "997 9",
"output": "996 9"
},
{
"input": "341 678",
"output": "677 341"
},
{
"input": "784 913",
"output": "912 784"
},
{
"input": "57 888",
"output": "887 57"
},
{
"input": "100000 100000",
"output": "99999 100000"
},
{
"input": "10000 100000",
"output": "99999 10000"
},
{
"input": "9999 99999",
"output": "99998 9999"
},
{
"input": "12 100000",
"output": "99999 12"
},
{
"input": "9999 31411",
"output": "31410 9999"
},
{
"input": "12930 98391",
"output": "98390 12930"
},
{
"input": "98813 893",
"output": "98812 893"
},
{
"input": "99801 38179",
"output": "99800 38179"
},
{
"input": "831 69318",
"output": "69317 831"
},
{
"input": "99999 99997",
"output": "99998 99997"
},
{
"input": "74 99",
"output": "98 74"
},
{
"input": "159 259",
"output": "258 159"
},
{
"input": "245 317",
"output": "316 245"
},
{
"input": "947 883",
"output": "946 883"
},
{
"input": "7131 3165",
"output": "7130 3165"
},
{
"input": "11536 12192",
"output": "12191 11536"
},
{
"input": "25938 40897",
"output": "40896 25938"
},
{
"input": "81314 31958",
"output": "81313 31958"
},
{
"input": "294 83621",
"output": "83620 294"
},
{
"input": "64896 18105",
"output": "64895 18105"
}
] | 1,577,772,464 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | red, blue = [int(x) for x in input().split()]
def red_first():
n, m, score = red - 1, blue, 0
diff = min(n // 2, m // 2) * 2
n -= diff
m -= diff
score += diff
if m == 0:
score += n
elif m == 1:
score += max(n - 1, 0)
elif n == 0:
score += m - 1
else:
score += 1 + max(m - 3, 0)
return score
def blue_first():
n, m, score = red, blue - 1, 0
diff = min(n // 2, m // 2) * 2
n -= diff
m -= diff
score += diff
if n == 0:
score += m
elif n == 1:
score += max(m - 1, 0)
elif m == 0:
score += n - 1
else:
score += 1 + max(n - 3, 0)
return score
res = max(red_first(), blue_first())
print(res, red + blue - 1) | Title: Playing Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pairs of neighbouring cubes of the same color as possible. Vasya's task is to get as many pairs of neighbouring cubes of different colors as possible.
The number of Petya's points in the game is the number of pairs of neighboring cubes of the same color in the line, the number of Vasya's points in the game is the number of neighbouring cubes of the different color in the line. Your task is to calculate the score at the end of the game (Petya's and Vasya's points, correspondingly), if both boys are playing optimally well. To "play optimally well" first of all means to maximize the number of one's points, and second — to minimize the number of the opponent's points.
Input Specification:
The only line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of red and blue cubes, correspondingly.
Output Specification:
On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.
Demo Input:
['3 1\n', '2 4\n']
Demo Output:
['2 1\n', '3 2\n']
Note:
In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cube during his first move, then, provided that both boys play optimally well, Petya would get 1 point and Vasya would get 2 points. | ```python
red, blue = [int(x) for x in input().split()]
def red_first():
n, m, score = red - 1, blue, 0
diff = min(n // 2, m // 2) * 2
n -= diff
m -= diff
score += diff
if m == 0:
score += n
elif m == 1:
score += max(n - 1, 0)
elif n == 0:
score += m - 1
else:
score += 1 + max(m - 3, 0)
return score
def blue_first():
n, m, score = red, blue - 1, 0
diff = min(n // 2, m // 2) * 2
n -= diff
m -= diff
score += diff
if n == 0:
score += m
elif n == 1:
score += max(m - 1, 0)
elif m == 0:
score += n - 1
else:
score += 1 + max(n - 3, 0)
return score
res = max(red_first(), blue_first())
print(res, red + blue - 1)
``` | 0 |
|
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10. | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n??????????",
"output": "0.205078125000"
},
{
"input": "+--+++--+-\n??????????",
"output": "0.246093750000"
},
{
"input": "+\n+",
"output": "1.000000000000"
},
{
"input": "-\n?",
"output": "0.500000000000"
},
{
"input": "+\n-",
"output": "0.000000000000"
},
{
"input": "-\n-",
"output": "1.000000000000"
},
{
"input": "-\n+",
"output": "0.000000000000"
},
{
"input": "+\n?",
"output": "0.500000000000"
},
{
"input": "++++++++++\n++++++++++",
"output": "1.000000000000"
},
{
"input": "++++++++++\n++++-+++++",
"output": "0.000000000000"
},
{
"input": "----------\n++++++++++",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++??++++",
"output": "0.250000000000"
},
{
"input": "----------\n+++?++++-+",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++++++?+",
"output": "0.500000000000"
},
{
"input": "--++++--+\n?-+?-??+-",
"output": "0.250000000000"
},
{
"input": "----------\n??????????",
"output": "0.000976562500"
},
{
"input": "+--++\n+--+-",
"output": "0.000000000000"
},
{
"input": "-----++---\n????????+?",
"output": "0.017578125000"
},
{
"input": "------+--+\n??????????",
"output": "0.043945312500"
},
{
"input": "---++--\n???????",
"output": "0.164062500000"
},
{
"input": "-----++\n???????",
"output": "0.164062500000"
},
{
"input": "+---+--\n???????",
"output": "0.164062500000"
},
{
"input": "---+-+\n??????",
"output": "0.234375000000"
},
{
"input": "+++-+\n---++",
"output": "0.000000000000"
},
{
"input": "++-+--+\n?-?+??+",
"output": "0.375000000000"
},
{
"input": "----+++--\n-+?+++?--",
"output": "0.000000000000"
},
{
"input": "+-----\n+?----",
"output": "0.500000000000"
}
] | 1,652,473,481 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 31 | 0 | #!/usr/bin/env python3
#-*- coding: utf-8 -*-
# author: Neto, Jocelino
# Dreamoon is standing at the position 0 on a number line.
# Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone
# and Dreamoon follows them.
#
# Each command is one of the following two types:
#
# 1. Go 1 unit towards the positive direction, denoted as '+'
# 1. Go 1 unit towards the negative direction, denoted as '-'
#
# But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of
# the commands can't be recognized and Dreamoon knows that some of them might
# even be wrong though successfully recognized. Dreamoon decides to follow every
# recognized command and toss a fair coin to decide those unrecognized ones
# (that means, he moves to the 1 unit to the negative or positive direction
# with the same probability 0.5).
#
# You are given an original list of commands sent by Drazil and list received
# by Dreamoon. What is the probability that Dreamoon ends in the position
# originally supposed to be final by Drazil's commands?
#
def calculate(analysed, unknow, diff):
power = 2 ** unknow
if len(analysed) == unknow:
counter_analysed = analysed.count("+") - analysed.count("-")
A = 1 if counter_analysed == diff else 0
return A/power
return calculate(analysed+"-", unknow, diff) + calculate(analysed+"+", unknow, diff)
if __name__ == '__main__':
str1_input = input()[:10]
str2_input = input()[:10]
counter_input = str1_input.count("+") - str1_input.count("-")
counter_output = str2_input.count("+") - str2_input.count("-")
est = str2_input.count("?")
solution = calculate("", est, (counter_input - counter_output))
print(solution) | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
Input Specification:
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
Output Specification:
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
Demo Input:
['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n']
Demo Output:
['1.000000000000\n', '0.500000000000\n', '0.000000000000\n']
Note:
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | ```python
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
# author: Neto, Jocelino
# Dreamoon is standing at the position 0 on a number line.
# Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone
# and Dreamoon follows them.
#
# Each command is one of the following two types:
#
# 1. Go 1 unit towards the positive direction, denoted as '+'
# 1. Go 1 unit towards the negative direction, denoted as '-'
#
# But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of
# the commands can't be recognized and Dreamoon knows that some of them might
# even be wrong though successfully recognized. Dreamoon decides to follow every
# recognized command and toss a fair coin to decide those unrecognized ones
# (that means, he moves to the 1 unit to the negative or positive direction
# with the same probability 0.5).
#
# You are given an original list of commands sent by Drazil and list received
# by Dreamoon. What is the probability that Dreamoon ends in the position
# originally supposed to be final by Drazil's commands?
#
def calculate(analysed, unknow, diff):
power = 2 ** unknow
if len(analysed) == unknow:
counter_analysed = analysed.count("+") - analysed.count("-")
A = 1 if counter_analysed == diff else 0
return A/power
return calculate(analysed+"-", unknow, diff) + calculate(analysed+"+", unknow, diff)
if __name__ == '__main__':
str1_input = input()[:10]
str2_input = input()[:10]
counter_input = str1_input.count("+") - str1_input.count("-")
counter_output = str2_input.count("+") - str2_input.count("-")
est = str2_input.count("?")
solution = calculate("", est, (counter_input - counter_output))
print(solution)
``` | 3 |
|
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight. | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has. | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input": "7 2\n2 4 6 7 8 9 10\n10 8 4 8 4 5 9",
"output": "10 18 22 26 22 23 27 "
},
{
"input": "11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000 2000000000 3000000000 4000000000 5000000000 6000000000 7000000000 8000000000 9000000000 10000000000 11000000000 "
},
{
"input": "2 0\n2 3\n3 3",
"output": "3 3 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 4 5 6 7",
"output": "3 6 9 13 15 18 22 "
},
{
"input": "3 0\n3 2 1\n1 2 3",
"output": "1 2 3 "
},
{
"input": "5 3\n4 5 7 9 11\n10 10 10 10 10",
"output": "10 20 30 40 40 "
},
{
"input": "4 0\n4 5 9 7\n1 2 11 33",
"output": "1 2 11 33 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 8 8 8 8",
"output": "3 6 9 17 22 27 32 "
},
{
"input": "3 0\n1 2 3\n5 5 5",
"output": "5 5 5 "
},
{
"input": "4 2\n4 5 9 7\n2 2 11 33",
"output": "2 4 46 37 "
},
{
"input": "6 3\n1 2 3 4 5 6\n1 1 1 1 1 1",
"output": "1 2 3 4 4 4 "
},
{
"input": "10 5\n1 2 3 4 5 6 7 8 9 10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 2 3 4 5 6 6 6 6 6 "
},
{
"input": "3 2\n1 2 3\n1 1 1",
"output": "1 2 3 "
},
{
"input": "3 0\n1 2 3\n10 20 30",
"output": "10 20 30 "
},
{
"input": "4 0\n4 5 9 7\n1 2 3 4",
"output": "1 2 3 4 "
},
{
"input": "5 4\n1 2 3 4 5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "4 3\n1 2 3 4\n5 5 5 5",
"output": "5 10 15 20 "
},
{
"input": "5 3\n1 2 3 4 5\n7 7 7 7 7",
"output": "7 14 21 28 28 "
}
] | 1,684,749,048 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 43,724,800 | import math
a = input().split()
k = int(a[1])
powers = input().split()
powers = [int(x) for x in powers]
coins = input().split()
coins = [int(x) for x in coins]
arr = []
for i in range(len(powers)):
arr.append([coins[i], powers[i], i])
arr.sort()
ans = [0] * len(powers)
l = len(powers)
for i in range(len(arr)):
amount = k
knight = arr[i]
rob = knight[0]
for j in range(l-1, -1, -1):
if j == i:
continue
if amount<=0:
break
if arr[j][1] < knight[1]:
rob += arr[j][0]
amount -= 1
else:
continue
ans[knight[2]] = rob
a = ""
for num in ans:
a += str(num) + " "
print(a)
#! [[4, 22], [5, 2], [7, 33], [9, 11]]
| Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight.
Input Specification:
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has.
Output Specification:
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
Demo Input:
['4 2\n4 5 9 7\n1 2 11 33\n', '5 1\n1 2 3 4 5\n1 2 3 4 5\n', '1 0\n2\n3\n']
Demo Output:
['1 3 46 36 ', '1 3 5 7 9 ', '3 ']
Note:
Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | ```python
import math
a = input().split()
k = int(a[1])
powers = input().split()
powers = [int(x) for x in powers]
coins = input().split()
coins = [int(x) for x in coins]
arr = []
for i in range(len(powers)):
arr.append([coins[i], powers[i], i])
arr.sort()
ans = [0] * len(powers)
l = len(powers)
for i in range(len(arr)):
amount = k
knight = arr[i]
rob = knight[0]
for j in range(l-1, -1, -1):
if j == i:
continue
if amount<=0:
break
if arr[j][1] < knight[1]:
rob += arr[j][0]
amount -= 1
else:
continue
ans[knight[2]] = rob
a = ""
for num in ans:
a += str(num) + " "
print(a)
#! [[4, 22], [5, 2], [7, 33], [9, 11]]
``` | 0 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,695,548,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a=int(input())
c=[]
d=0
for i in range(a):
b=str(input())
c.append(b)
c.append(2)
for i in range(a):
if c[i+1]==c[i]:
d+=1
else:
pass
print(d)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
a=int(input())
c=[]
d=0
for i in range(a):
b=str(input())
c.append(b)
c.append(2)
for i in range(a):
if c[i+1]==c[i]:
d+=1
else:
pass
print(d)
``` | 0 |
|
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,691,162,603 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def watermelon(n: int):
if n % 2 == 0 and n > 2:
return True
else:
return False
| 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 watermelon(n: int):
if n % 2 == 0 and n > 2:
return True
else:
return False
``` | 0 |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,694,650,185 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 12,800,000 | n = int(input())
a = list(map(int, input().split()))
conteo = 1
maximo = 1
for i in range(1, n):
if a[i] > a[i - 1]:
conteo += 1
else:
if conteo > maximo:
maximo = conteo
conteo = 1
if conteo > maximo:
maximo = conteo
print(maximo)
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
conteo = 1
maximo = 1
for i in range(1, n):
if a[i] > a[i - 1]:
conteo += 1
else:
if conteo > maximo:
maximo = conteo
conteo = 1
if conteo > maximo:
maximo = conteo
print(maximo)
``` | 3 |
|
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,635,077,606 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 17,715,200 | a=int(input())
print(2**a) | 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
a=int(input())
print(2**a)
``` | 0 |
|
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=<<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=<<=*n*.
Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение.
За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы.
Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком. | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания. | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома.
Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах. | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},
{
"input": "2 100000\n0 100000",
"output": "1"
},
{
"input": "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 61805 61861 63005 64013 68848 71182 71497 72715 73008 75616 76042 76614 80690 83089 85033 86408 92392 92763 93833 95085 95815 97152 99379",
"output": "8"
},
{
"input": "5 7\n6219 6222 6229 6231 6236",
"output": "3"
},
{
"input": "10 448\n78449 78573 78599 78742 78748 78759 78853 79091 79298 79324",
"output": "3"
},
{
"input": "20 19191\n11272 12386 14108 24663 24932 26547 29656 44677 45436 45654 48562 62367 71049 71238 78182 84042 88736 92026 96836 99343",
"output": "6"
},
{
"input": "2 100000\n1 100000",
"output": "1"
},
{
"input": "2 99999\n0 100000",
"output": "-1"
},
{
"input": "2 2\n1 3",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
}
] | 1,520,008,562 | 3,662 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 62 | 5,632,000 | import sys
n, k = map(int, input().split())
L = [int(el) for el in input().split()]
kol = 0
p = L[0]
j = 1
while p < L[n - 1]:
p += k
for i in range(j, len(L)):
if p >= L[i]:
kol += 1
j = i + 1
break
else:
print(-1)
sys.exit()
print(kol)
| Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=<<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=<<=*n*.
Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение.
За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы.
Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком.
Input Specification:
В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания.
Output Specification:
Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката.
Demo Input:
['4 4\n3 6 8 10\n', '2 9\n10 20\n', '12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома.
Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах. | ```python
import sys
n, k = map(int, input().split())
L = [int(el) for el in input().split()]
kol = 0
p = L[0]
j = 1
while p < L[n - 1]:
p += k
for i in range(j, len(L)):
if p >= L[i]:
kol += 1
j = i + 1
break
else:
print(-1)
sys.exit()
print(kol)
``` | 0 |
|
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand on the beach, so you brought *n* packs of sand with you. Let height *h**i* of the sand pillar on some spot *i* be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with *H* sand packs to the left of the first spot and you should prevent sand from going over it.
Finally you ended up with the following conditions to building the castle:
- *h*1<=≤<=*H*: no sand from the leftmost spot should go over the fence; - For any |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen; - : you want to spend all the sand you brought with you.
As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible.
Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold. | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are occupied in them.
And here are some invalid ones:
- *n* = 5, *H* = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...] - *n* = 6, *H* = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...] | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 1000000000000000000",
"output": "1"
},
{
"input": "1000000000000000000 1",
"output": "1999999999"
},
{
"input": "1036191544337895 45523434",
"output": "45523434"
},
{
"input": "1036191544337896 45523434",
"output": "45523435"
},
{
"input": "1036191544337895 45523433",
"output": "45523435"
},
{
"input": "1036191544337895 1",
"output": "64379858"
},
{
"input": "1036191544337895 1000000000000000000",
"output": "45523434"
},
{
"input": "30 3",
"output": "9"
},
{
"input": "30 4",
"output": "8"
},
{
"input": "6 100",
"output": "3"
},
{
"input": "7 100",
"output": "4"
},
{
"input": "1000000000000000000 99999999999",
"output": "1414213562"
},
{
"input": "999999997351043581 1000000000000000000",
"output": "1414213561"
},
{
"input": "911343366122896086 1416605974",
"output": "1350069158"
},
{
"input": "828974163639871882 2010864527",
"output": "1287613423"
},
{
"input": "696616491401388220 958775125",
"output": "1191798158"
},
{
"input": "999999999000000000 1",
"output": "1999999998"
},
{
"input": "961245465290770608 1687994843",
"output": "1386539192"
},
{
"input": "692106376966414549 974053139",
"output": "1186035874"
},
{
"input": "12 1",
"output": "6"
},
{
"input": "806680349368385877 1068656310",
"output": "1278847474"
}
] | 1,631,540,274 | 4,374 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 61 | 20,172,800 | import sys
input = sys.stdin.readline
def binary_search(c1, c2):
m = (c1 + c2 + 1) // 2
while abs(c1 - c2) > 1:
m = (c1 + c2 + 1) // 2
if ok(m):
c2 = m
else:
c1 = m
m = max(1, m - 5)
while not ok(m):
m += 1
return m
def f(x):
return x * (x + 1) // 2
def ok(m):
if m <= h:
return True if f(m) >= n else False
else:
x = (m - h) // 2 + h
y = 2 * f(x) - f(h - 1) - (m % 2 ^ 1) ^ (h % 2) * x
return True if y >= n else False
n, h = map(int, input().split())
ans = binary_search(1, n + 5)
print(ans) | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand on the beach, so you brought *n* packs of sand with you. Let height *h**i* of the sand pillar on some spot *i* be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with *H* sand packs to the left of the first spot and you should prevent sand from going over it.
Finally you ended up with the following conditions to building the castle:
- *h*1<=≤<=*H*: no sand from the leftmost spot should go over the fence; - For any |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen; - : you want to spend all the sand you brought with you.
As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible.
Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold.
Input Specification:
The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively.
Output Specification:
Print the minimum number of spots you can occupy so the all the castle building conditions hold.
Demo Input:
['5 2\n', '6 8\n']
Demo Output:
['3\n', '3\n']
Note:
Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are occupied in them.
And here are some invalid ones:
- *n* = 5, *H* = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...] - *n* = 6, *H* = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...] | ```python
import sys
input = sys.stdin.readline
def binary_search(c1, c2):
m = (c1 + c2 + 1) // 2
while abs(c1 - c2) > 1:
m = (c1 + c2 + 1) // 2
if ok(m):
c2 = m
else:
c1 = m
m = max(1, m - 5)
while not ok(m):
m += 1
return m
def f(x):
return x * (x + 1) // 2
def ok(m):
if m <= h:
return True if f(m) >= n else False
else:
x = (m - h) // 2 + h
y = 2 * f(x) - f(h - 1) - (m % 2 ^ 1) ^ (h % 2) * x
return True if y >= n else False
n, h = map(int, input().split())
ans = binary_search(1, n + 5)
print(ans)
``` | 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,672,423,005 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a=int(input())
for i in range(a):
x=int(input())
if len(x)>10:
print(x[0],end="")
print(len(x[1:len(x)-1]),end="")
print(x[len(x)-1])
else:
print(x) | 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
a=int(input())
for i in range(a):
x=int(input())
if len(x)>10:
print(x[0],end="")
print(len(x[1:len(x)-1]),end="")
print(x[len(x)-1])
else:
print(x)
``` | -1 |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,658,263,826 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | n = int(input())
nums = list(map(int,input().split(' ')))
nums.append(nums[0])
difs = []
for numA, numB in zip(nums,nums[1:]):
difs.append(abs(numB-numA))
vmin = difs.index(min(difs))
#print(difs)
if vmin == len(nums)-2:
print(1, len(nums)-1)
else:
print(vmin+1, vmin+2)
| Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n = int(input())
nums = list(map(int,input().split(' ')))
nums.append(nums[0])
difs = []
for numA, numB in zip(nums,nums[1:]):
difs.append(abs(numB-numA))
vmin = difs.index(min(difs))
#print(difs)
if vmin == len(nums)-2:
print(1, len(nums)-1)
else:
print(vmin+1, vmin+2)
``` | 3.977 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,588,826,915 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 6,656,000 | n=input()
ans=''
i=0
# for i in range(len(n)):
while i<len(n):
# print(i)
if n[i] == '.':
ans+='0'
i+=1
else:
# if i+1<n:
if n[i] =='-':
if n[i+1] == '.':
ans+='1'
else:
ans+='2'
i+=2
print(ans) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
n=input()
ans=''
i=0
# for i in range(len(n)):
while i<len(n):
# print(i)
if n[i] == '.':
ans+='0'
i+=1
else:
# if i+1<n:
if n[i] =='-':
if n[i+1] == '.':
ans+='1'
else:
ans+='2'
i+=2
print(ans)
``` | 3.933602 |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4",
"output": "-1"
},
{
"input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4",
"output": "-1"
},
{
"input": "1\n2 4",
"output": "0"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "2\n1 1\n3 3",
"output": "0"
},
{
"input": "2\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n1 1\n1 2",
"output": "-1"
},
{
"input": "5\n1 2\n6 6\n1 1\n3 3\n6 1",
"output": "1"
},
{
"input": "5\n5 4\n2 6\n6 2\n1 4\n6 2",
"output": "0"
},
{
"input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1",
"output": "0"
},
{
"input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5",
"output": "-1"
},
{
"input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1",
"output": "1"
},
{
"input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4",
"output": "-1"
},
{
"input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2",
"output": "0"
},
{
"input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5",
"output": "-1"
},
{
"input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4",
"output": "-1"
},
{
"input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4",
"output": "-1"
},
{
"input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6",
"output": "1"
},
{
"input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5",
"output": "1"
},
{
"input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3",
"output": "1"
},
{
"input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5",
"output": "1"
},
{
"input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5",
"output": "-1"
},
{
"input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6",
"output": "-1"
},
{
"input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1",
"output": "-1"
},
{
"input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6",
"output": "-1"
},
{
"input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4",
"output": "1"
},
{
"input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6",
"output": "-1"
},
{
"input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2",
"output": "0"
},
{
"input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3",
"output": "-1"
},
{
"input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3",
"output": "-1"
},
{
"input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4",
"output": "-1"
},
{
"input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5",
"output": "1"
},
{
"input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1",
"output": "1"
},
{
"input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5",
"output": "-1"
},
{
"input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2",
"output": "0"
},
{
"input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1",
"output": "0"
},
{
"input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2",
"output": "1"
},
{
"input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2",
"output": "0"
},
{
"input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2",
"output": "-1"
},
{
"input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5",
"output": "0"
},
{
"input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1",
"output": "-1"
},
{
"input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5",
"output": "-1"
},
{
"input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3",
"output": "-1"
},
{
"input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5",
"output": "0"
},
{
"input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4",
"output": "-1"
},
{
"input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2",
"output": "-1"
},
{
"input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2",
"output": "1"
},
{
"input": "1\n2 2",
"output": "0"
},
{
"input": "3\n2 4\n6 6\n3 3",
"output": "-1"
},
{
"input": "2\n3 6\n4 1",
"output": "1"
},
{
"input": "3\n1 1\n1 1\n3 3",
"output": "-1"
},
{
"input": "3\n2 3\n1 1\n2 3",
"output": "1"
},
{
"input": "3\n2 2\n2 1\n1 2",
"output": "1"
},
{
"input": "3\n1 1\n1 1\n1 1",
"output": "-1"
}
] | 1,577,898,990 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 248 | 512,000 | n = int(input())
pc = []
upper = 0
lower = 0
time = 0
for i in range(n):
a = list(map(int, input().split()))
pc.append(a)
for i in range(len(pc)):
upper = 0
lower = 0
for j in pc:
upper += j[0]
lower += j[1]
if upper % 2 == 0 and lower % 2 == 0:
break
else:
pc[i][1], pc[i][0] = pc[i][0], pc[i][1]
time += 1
if upper % 2 == 0 and lower % 2 == 0:
if time >= 1:
print(1)
else:
print(0)
else:
print(-1) | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Output Specification:
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
Demo Input:
['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | ```python
n = int(input())
pc = []
upper = 0
lower = 0
time = 0
for i in range(n):
a = list(map(int, input().split()))
pc.append(a)
for i in range(len(pc)):
upper = 0
lower = 0
for j in pc:
upper += j[0]
lower += j[1]
if upper % 2 == 0 and lower % 2 == 0:
break
else:
pc[i][1], pc[i][0] = pc[i][0], pc[i][1]
time += 1
if upper % 2 == 0 and lower % 2 == 0:
if time >= 1:
print(1)
else:
print(0)
else:
print(-1)
``` | 3 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,584,446,577 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 310 | 1,228,800 | import collections
from fractions import Fraction
n = input().split()
n = list(map(int, n))
A = 6 - max(collections.Counter(n).keys())+1
B = 6
print(Fraction(A,B)) | 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
import collections
from fractions import Fraction
n = input().split()
n = list(map(int, n))
A = 6 - max(collections.Counter(n).keys())+1
B = 6
print(Fraction(A,B))
``` | 0 |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,692,286,466 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 124 | 0 | n=input()
w=[word for word in n.split("WUB") if word]
o=" ".join(w)
print(o) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
n=input()
w=[word for word in n.split("WUB") if word]
o=" ".join(w)
print(o)
``` | 3 |
|
103 | B | Cthulhu | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | B. Cthulhu | 2 | 256 | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops. | The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself. | Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is. | [
"6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n",
"6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n"
] | [
"FHTAGN!",
"NO"
] | Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one vertex is selected to be the root. | 1,000 | [
{
"input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4",
"output": "FHTAGN!"
},
{
"input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2",
"output": "NO"
},
{
"input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8",
"output": "FHTAGN!"
},
{
"input": "5 4\n1 5\n1 3\n1 4\n3 2",
"output": "NO"
},
{
"input": "12 12\n4 12\n4 7\n4 9\n7 2\n5 12\n2 1\n5 9\n8 6\n10 12\n2 5\n10 9\n12 3",
"output": "NO"
},
{
"input": "12 15\n3 2\n11 12\n1 9\n2 1\n1 8\n9 6\n11 5\n9 5\n9 10\n11 3\n7 11\n5 6\n11 10\n4 6\n4 2",
"output": "NO"
},
{
"input": "12 10\n1 11\n3 6\n5 7\n4 7\n6 8\n11 7\n3 12\n11 12\n7 9\n12 2",
"output": "NO"
},
{
"input": "1 0",
"output": "NO"
},
{
"input": "2 1\n1 2",
"output": "NO"
},
{
"input": "3 1\n1 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "FHTAGN!"
},
{
"input": "4 4\n1 2\n3 4\n4 1\n2 4",
"output": "FHTAGN!"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "NO"
},
{
"input": "2 0",
"output": "NO"
},
{
"input": "3 0",
"output": "NO"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "100 1\n11 23",
"output": "NO"
},
{
"input": "10 10\n5 7\n8 1\n10 3\n6 4\n10 6\n5 3\n5 6\n2 6\n4 3\n2 10",
"output": "NO"
},
{
"input": "20 20\n9 10\n4 19\n9 20\n12 20\n1 15\n2 12\n19 10\n19 15\n4 10\n4 8\n8 9\n20 8\n6 2\n2 15\n7 19\n20 4\n3 16\n1 20\n9 1\n20 10",
"output": "NO"
},
{
"input": "30 30\n17 6\n16 29\n16 13\n16 20\n29 26\n17 5\n27 28\n24 16\n7 18\n24 10\n1 27\n12 17\n27 30\n6 1\n3 30\n5 19\n18 13\n16 2\n30 1\n5 8\n14 16\n26 18\n7 19\n5 6\n23 14\n6 8\n23 8\n18 8\n18 3\n5 21",
"output": "NO"
},
{
"input": "100 66\n41 14\n19 13\n70 43\n79 62\n9 62\n71 40\n53 86\n80 4\n34 33\n72 68\n40 96\n84 59\n36 77\n55 50\n40 3\n79 81\n3 43\n33 47\n22 98\n33 90\n56 49\n69 28\n73 30\n65 22\n98 20\n9 52\n54 20\n32 70\n51 80\n63 12\n21 48\n35 17\n48 87\n25 43\n65 80\n42 3\n86 35\n95 98\n43 59\n51 46\n66 37\n88 34\n32 47\n24 42\n21 44\n92 59\n81 6\n100 82\n85 6\n58 25\n66 6\n14 32\n59 85\n3 98\n44 4\n85 51\n69 41\n80 70\n81 24\n75 71\n93 9\n82 55\n70 46\n66 32\n77 58\n11 46",
"output": "NO"
},
{
"input": "4 4\n1 2\n4 3\n2 3\n3 1",
"output": "FHTAGN!"
},
{
"input": "5 5\n2 3\n2 4\n5 4\n4 1\n1 2",
"output": "FHTAGN!"
},
{
"input": "10 10\n1 10\n5 9\n6 2\n8 9\n9 1\n5 4\n2 8\n1 3\n6 3\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n2 3\n3 1",
"output": "NO"
},
{
"input": "6 5\n1 2\n2 3\n3 1\n1 4\n1 5",
"output": "NO"
}
] | 1,607,789,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 218 | 307,200 | def dfs(visited,adj,ind,parent):
if(visited[ind]==1): return [-1,-1]
visited[ind]=1
for i in adj[ind]:
if(visited[i]==0):
parent[i]=ind
x=dfs(visited,adj,i,parent)
if(x[0]!=-1): return x
elif(visited[i]==1 and i!=parent[ind]):
return [i,ind]
return [-1,-1]
def dfsx(visited,adj,ind,parent,part):
if(visited[ind]==1): return 0
visited[ind]=1
for i in adj[ind]:
if(part[i]==1): continue
if(visited[i]==0):
parent[i]=ind
x=dfs(visited,adj,i,parent)
if(x!=0): return 1
elif(visited[i]==1 and i!=parent[ind] and part[i]==0):
return 1
return 0
n,m=[int(i) for i in input().split()]
l=[]
adj=[[] for i in range(n)]
part_cycle=[0 for i in range(n)]
for i in range(m):
a,b=[int(x) for x in input().split()]
adj[a-1].append(b-1)
adj[b-1].append(a-1)
parent=[-1 for i in range(n)]
visited=[0 for i in range(n)]
x=dfs(visited,adj,0,parent)
if(x[0]==-1):
print("NO")
else:
part_cycle[x[0]]=1; part_cycle[x[1]]= 1;
cycle=[]
ind=x[1]
cycle.append(x[0])
while(ind!=x[0]):
cycle.append(ind)
part_cycle[ind]=1; part_cycle[parent[ind]]=1;
ind=parent[ind]
flag=0
for i in cycle:
x=dfsx(visited, adj, i, parent,part_cycle)
if(x==1):
print("NO")
flag=1
break
if(flag==0):
print("FHTAGN!") | Title: Cthulhu
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops.
Input Specification:
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Output Specification:
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
Demo Input:
['6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n', '6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n']
Demo Output:
['FHTAGN!', 'NO']
Note:
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one vertex is selected to be the root. | ```python
def dfs(visited,adj,ind,parent):
if(visited[ind]==1): return [-1,-1]
visited[ind]=1
for i in adj[ind]:
if(visited[i]==0):
parent[i]=ind
x=dfs(visited,adj,i,parent)
if(x[0]!=-1): return x
elif(visited[i]==1 and i!=parent[ind]):
return [i,ind]
return [-1,-1]
def dfsx(visited,adj,ind,parent,part):
if(visited[ind]==1): return 0
visited[ind]=1
for i in adj[ind]:
if(part[i]==1): continue
if(visited[i]==0):
parent[i]=ind
x=dfs(visited,adj,i,parent)
if(x!=0): return 1
elif(visited[i]==1 and i!=parent[ind] and part[i]==0):
return 1
return 0
n,m=[int(i) for i in input().split()]
l=[]
adj=[[] for i in range(n)]
part_cycle=[0 for i in range(n)]
for i in range(m):
a,b=[int(x) for x in input().split()]
adj[a-1].append(b-1)
adj[b-1].append(a-1)
parent=[-1 for i in range(n)]
visited=[0 for i in range(n)]
x=dfs(visited,adj,0,parent)
if(x[0]==-1):
print("NO")
else:
part_cycle[x[0]]=1; part_cycle[x[1]]= 1;
cycle=[]
ind=x[1]
cycle.append(x[0])
while(ind!=x[0]):
cycle.append(ind)
part_cycle[ind]=1; part_cycle[parent[ind]]=1;
ind=parent[ind]
flag=0
for i in cycle:
x=dfsx(visited, adj, i, parent,part_cycle)
if(x==1):
print("NO")
flag=1
break
if(flag==0):
print("FHTAGN!")
``` | 0 |
260 | B | Ancient Prophesy | PROGRAMMING | 1,600 | [
"brute force",
"implementation",
"strings"
] | null | null | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").
The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.
A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.
Notice, that any year between 2013 and 2015 is not a leap year. | The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters. | In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique. | [
"777-444---21-12-2013-12-2013-12-2013---444-777\n"
] | [
"13-12-2013"
] | none | 1,000 | [
{
"input": "777-444---21-12-2013-12-2013-12-2013---444-777",
"output": "13-12-2013"
},
{
"input": "30-12-201429-15-208830-12-2014",
"output": "30-12-2014"
},
{
"input": "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013",
"output": "14-08-2013"
},
{
"input": "15-11-201413-02-20147-86-25-298813-02-201413-02-201434615-11-201415-11-201415-11-201415-11-2014",
"output": "15-11-2014"
},
{
"input": "19-07-201419-07-201424-06-201719-07-201419-07-201413-10-201419-07-201468-01-201619-07-20142",
"output": "19-07-2014"
},
{
"input": "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08-20159533-45-00-1212",
"output": "01-04-2014"
},
{
"input": "23-11-201413-07-201412-06-2015124-03-20140-19-201323-11-201424-03-2014537523-11-20143575015-10-2014",
"output": "23-11-2014"
},
{
"input": "15-04-201413-08-201589-09-201013-08-20130-74-28-201620-8497-14-1063713-08-2013813-02-201513-08-2013",
"output": "13-08-2013"
},
{
"input": "13-05-201412-11-2013-12-11-201314-12-201329-05-201306-24-188814-07-201312-11-201312-04-2010",
"output": "12-11-2013"
},
{
"input": "14-01-201402-04-201514-01-201485-26-1443948-14-278314-01-2014615259-09-178413-06-201314-05-2014",
"output": "14-01-2014"
},
{
"input": "31-12-201331-11-201331-11-2013",
"output": "31-12-2013"
},
{
"input": "01-01-2014",
"output": "01-01-2014"
},
{
"input": "32-13-2100-32-13-2100-32-13-2100-12-12-2013",
"output": "12-12-2013"
},
{
"input": "15-1--201315-1--201301-01-2013",
"output": "01-01-2013"
},
{
"input": "00-12-2014-00-12-2014-00-12-2014-12-12-2014",
"output": "12-12-2014"
},
{
"input": "120110201311-10-20151201102013",
"output": "11-10-2015"
},
{
"input": "31-08-2013---31-08-2013---03-03-2013",
"output": "31-08-2013"
},
{
"input": "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013",
"output": "12-12-2013"
},
{
"input": "21-12-201221-12-201221-12-201221-12-201213-12-2013",
"output": "13-12-2013"
},
{
"input": "29-02-2013-02-2013-29-02-2013",
"output": "13-02-2013"
},
{
"input": "20-12-2012----20-12-2012-----01-01-2013",
"output": "01-01-2013"
},
{
"input": "01-2-02013---01-2-02013----13-02-2014",
"output": "13-02-2014"
},
{
"input": "11111111111111111111---21-12-2013",
"output": "21-12-2013"
},
{
"input": "29-02-2014--29-02-2014--28-02-2014",
"output": "28-02-2014"
},
{
"input": "29-02-201329-02-201321-12-2013",
"output": "21-12-2013"
},
{
"input": "01--01--2013-12-2013-01--01--2013",
"output": "13-12-2013"
},
{
"input": "10-10-2023-10-10-2023-10-10-2013",
"output": "10-10-2013"
}
] | 1,642,917,140 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 140 | 102,400 | s = input()
ch = dict()
for i in range(len(s)-10):
date = s[i:i+3]
month = s[i+3:i+6]
year = s[i+6:i+10]
if('-' in year):
continue
elif(2013 > int(year) or int(year) > 2015):
continue
elif(month[-1] != '-' or month[0]=='-' or month[1] == '-'):
continue
elif(1 > int(month[:-1]) or int(month[:-1])>12):
continue
elif(date[-1] != '-' or date[0] == '-' or date[1] == '-'):
continue
else:
month = int(month[:-1])
date = int(date[:-1])
if(month in [1,3,5,7,8,10,12] and (date<1 or date>31)):
continue
elif(month in [4,6,9,11] and (date<1 or date>30)):
continue
elif(month == 2 and (date<1 or date>28)):
continue
if(s[i:i+10] in ch.keys()):
ch[s[i:i+10]] += 1
else:
ch[s[i:i+10]] = 1
maxi = 0
ans = ''
for i in ch:
if(ch[i] > maxi):
maxi = ch[i]
ans = i
print(ans)
| Title: Ancient Prophesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").
The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.
A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.
Notice, that any year between 2013 and 2015 is not a leap year.
Input Specification:
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
Output Specification:
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
Demo Input:
['777-444---21-12-2013-12-2013-12-2013---444-777\n']
Demo Output:
['13-12-2013']
Note:
none | ```python
s = input()
ch = dict()
for i in range(len(s)-10):
date = s[i:i+3]
month = s[i+3:i+6]
year = s[i+6:i+10]
if('-' in year):
continue
elif(2013 > int(year) or int(year) > 2015):
continue
elif(month[-1] != '-' or month[0]=='-' or month[1] == '-'):
continue
elif(1 > int(month[:-1]) or int(month[:-1])>12):
continue
elif(date[-1] != '-' or date[0] == '-' or date[1] == '-'):
continue
else:
month = int(month[:-1])
date = int(date[:-1])
if(month in [1,3,5,7,8,10,12] and (date<1 or date>31)):
continue
elif(month in [4,6,9,11] and (date<1 or date>30)):
continue
elif(month == 2 and (date<1 or date>28)):
continue
if(s[i:i+10] in ch.keys()):
ch[s[i:i+10]] += 1
else:
ch[s[i:i+10]] = 1
maxi = 0
ans = ''
for i in ch:
if(ch[i] > maxi):
maxi = ch[i]
ans = i
print(ans)
``` | 0 |
|
612 | A | The Text Splitting | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them. | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | 0 | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"output": "1\n1"
},
{
"input": "10 8 1\nuTl9w4lcdo",
"output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no"
},
{
"input": "20 6 4\nfmFRpk2NrzSvnQC9gB61",
"output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61"
},
{
"input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6",
"output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6"
},
{
"input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde",
"output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde"
},
{
"input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu",
"output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu"
},
{
"input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj",
"output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj"
},
{
"input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY",
"output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY"
},
{
"input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc",
"output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc"
},
{
"input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE",
"output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE"
},
{
"input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB",
"output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB"
},
{
"input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ",
"output": "-1"
},
{
"input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn",
"output": "-1"
},
{
"input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT",
"output": "-1"
},
{
"input": "10 3 1\nXQ2vXLPShy",
"output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny"
},
{
"input": "4 2 3\naaaa",
"output": "2\naa\naa"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb"
},
{
"input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 2 3\nhavanahavan",
"output": "4\nha\nvan\naha\nvan"
},
{
"input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa"
},
{
"input": "17 3 5\ngopstopmipodoshli",
"output": "5\ngop\nsto\npmi\npod\noshli"
},
{
"input": "5 4 3\nfoyku",
"output": "-1"
},
{
"input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"output": "-1"
},
{
"input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit",
"output": "-1"
},
{
"input": "11 2 3\nqibwnnvqqgo",
"output": "4\nqi\nbwn\nnvq\nqgo"
},
{
"input": "4 4 3\nhhhh",
"output": "1\nhhhh"
},
{
"input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh"
},
{
"input": "10 5 9\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "10 5 9\naaaaaaaaaa",
"output": "2\naaaaa\naaaaa"
},
{
"input": "11 3 2\nmlmqpohwtsf",
"output": "5\nmlm\nqp\noh\nwt\nsf"
},
{
"input": "3 3 2\nzyx",
"output": "1\nzyx"
},
{
"input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "4 2 3\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "3 2 3\nejt",
"output": "1\nejt"
},
{
"input": "5 2 4\nzyxwv",
"output": "-1"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na"
},
{
"input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa"
},
{
"input": "3 2 2\nzyx",
"output": "-1"
},
{
"input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "-1"
},
{
"input": "26 8 9\nabcabcabcabcabcabcabcabcab",
"output": "3\nabcabcab\ncabcabcab\ncabcabcab"
},
{
"input": "6 3 5\naaaaaa",
"output": "2\naaa\naaa"
},
{
"input": "3 2 3\nzyx",
"output": "1\nzyx"
},
{
"input": "5 5 2\naaaaa",
"output": "1\naaaaa"
},
{
"input": "4 3 2\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "5 4 3\nzyxwv",
"output": "-1"
},
{
"input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab"
},
{
"input": "3 2 2\naaa",
"output": "-1"
},
{
"input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj",
"output": "-1"
},
{
"input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
"output": "-1"
},
{
"input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab"
},
{
"input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca",
"output": "-1"
},
{
"input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb",
"output": "-1"
},
{
"input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy",
"output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy"
},
{
"input": "16 3 7\naaaaaaaaaaaaaaaa",
"output": "4\naaa\naaa\naaa\naaaaaaa"
},
{
"input": "11 10 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 8 8\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 7 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab"
},
{
"input": "11 3 2\naaaaaaaaaaa",
"output": "5\naaa\naa\naa\naa\naa"
},
{
"input": "14 9 4\nabcdefghijklmn",
"output": "-1"
},
{
"input": "9 9 5\n123456789",
"output": "1\n123456789"
},
{
"input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw",
"output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw"
},
{
"input": "17 16 3\ndxyhgtsxtuyljmclj",
"output": "-1"
},
{
"input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd",
"output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd"
},
{
"input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor",
"output": "-1"
},
{
"input": "7 5 3\nzyxwvut",
"output": "-1"
},
{
"input": "17 16 4\nctvfhkiakagcilrdw",
"output": "-1"
}
] | 1,451,171,105 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 204,800 | n,p,q = map(int,input().split())
strValue = input()
#strValue="Hello"
fl=[]
if (n%p)==0:
x=n//p;
fl = ([strValue[a:a+p] for a in range(0, x*p,p) ])
elif (n%q)==0:
x=n//q;
fl= ([strValue[a:a+q] for a in range(0, x*q,q) ])
elif ((n%p)%q)==0:
x=n//p
fl.append([strValue[a:a+p] for a in range(0, x*p,p) ])
strValue = strValue[(x*p):]
y=((n-(x*p))//q)
fl.append ([strValue[a:a+q] for a in range(0, y*q,q) ])
x=x+y
elif ((n%q)%p)==0:
x=n//q
fl.append ([strValue[a:a+q] for a in range(0, x*q,q) ])
strValue = strValue[(x*q):]
y=((n-(x*q))//p)
fl.append([strValue[a:a+p] for a in range(0, y*p,p) ])
x=x+y
else:
x=-1
print(x)
if x>-1:
for a in fl:
print( "".join(a)) | Title: The Text Splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test).
Input Specification:
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
Output Specification:
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them.
Demo Input:
['5 2 3\nHello\n', '10 9 5\nCodeforces\n', '6 4 5\nPrivet\n', '8 1 1\nabacabac\n']
Demo Output:
['2\nHe\nllo\n', '2\nCodef\norces\n', '-1\n', '8\na\nb\na\nc\na\nb\na\nc\n']
Note:
none | ```python
n,p,q = map(int,input().split())
strValue = input()
#strValue="Hello"
fl=[]
if (n%p)==0:
x=n//p;
fl = ([strValue[a:a+p] for a in range(0, x*p,p) ])
elif (n%q)==0:
x=n//q;
fl= ([strValue[a:a+q] for a in range(0, x*q,q) ])
elif ((n%p)%q)==0:
x=n//p
fl.append([strValue[a:a+p] for a in range(0, x*p,p) ])
strValue = strValue[(x*p):]
y=((n-(x*p))//q)
fl.append ([strValue[a:a+q] for a in range(0, y*q,q) ])
x=x+y
elif ((n%q)%p)==0:
x=n//q
fl.append ([strValue[a:a+q] for a in range(0, x*q,q) ])
strValue = strValue[(x*q):]
y=((n-(x*q))//p)
fl.append([strValue[a:a+p] for a in range(0, y*p,p) ])
x=x+y
else:
x=-1
print(x)
if x>-1:
for a in fl:
print( "".join(a))
``` | 0 |
|
976 | C | Nested Segments | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"sortings"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. | Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | [
"5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"3\n1 5\n2 6\n6 20\n"
] | [
"2 1\n",
"-1 -1\n"
] | In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | 0 | [
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9",
"output": "2 1"
},
{
"input": "3\n1 5\n2 6\n6 20",
"output": "-1 -1"
},
{
"input": "1\n1 1000000000",
"output": "-1 -1"
},
{
"input": "2\n1 1000000000\n1 1000000000",
"output": "2 1"
},
{
"input": "2\n1 1000000000\n500000000 500000000",
"output": "2 1"
},
{
"input": "2\n1 10\n2 10",
"output": "2 1"
},
{
"input": "2\n10 20\n10 11",
"output": "2 1"
},
{
"input": "3\n1 10\n10 20\n9 11",
"output": "-1 -1"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "3 2"
},
{
"input": "4\n1 10\n2 11\n3 10000000\n3 100000000",
"output": "3 4"
},
{
"input": "2\n3 7\n3 9",
"output": "1 2"
},
{
"input": "3\n1 2\n2 3\n1 2",
"output": "3 1"
},
{
"input": "3\n5 6\n4 7\n3 8",
"output": "2 3"
},
{
"input": "3\n2 9\n1 7\n2 8",
"output": "3 1"
},
{
"input": "2\n1 4\n1 5",
"output": "1 2"
},
{
"input": "3\n1 2\n1 3\n4 4",
"output": "1 2"
},
{
"input": "3\n1 2\n1 3\n67 1234567",
"output": "1 2"
},
{
"input": "2\n1 1\n1 1",
"output": "2 1"
},
{
"input": "3\n1 5\n4 7\n3 9",
"output": "2 3"
},
{
"input": "2\n1 1\n1 10",
"output": "1 2"
},
{
"input": "2\n1 2\n1 3",
"output": "1 2"
},
{
"input": "2\n1 10\n1 11",
"output": "1 2"
},
{
"input": "2\n1 1\n1 2",
"output": "1 2"
},
{
"input": "2\n2 3\n2 4",
"output": "1 2"
},
{
"input": "2\n1 3\n3 3",
"output": "2 1"
},
{
"input": "3\n1 10\n11 13\n12 12",
"output": "3 2"
},
{
"input": "2\n2 10\n1 10",
"output": "1 2"
},
{
"input": "3\n1 3\n4 5\n4 4",
"output": "3 2"
},
{
"input": "5\n1 1\n2 6\n3 5\n10 15\n20 25",
"output": "3 2"
},
{
"input": "3\n1 1000\n1001 1007\n1002 1007",
"output": "3 2"
},
{
"input": "3\n1 3\n2 5\n3 4",
"output": "3 2"
},
{
"input": "3\n1 10\n2 11\n3 11",
"output": "3 2"
},
{
"input": "2\n2000000 999999999\n1000000 1000000000",
"output": "1 2"
},
{
"input": "3\n2 10\n11 12\n4 5",
"output": "3 1"
},
{
"input": "2\n1 10\n1 19",
"output": "1 2"
},
{
"input": "4\n1 3\n100 102\n108 110\n1 3",
"output": "4 1"
},
{
"input": "3\n1 3\n5 9\n5 6",
"output": "3 2"
},
{
"input": "3\n1 3\n3 4\n3 5",
"output": "2 3"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "2 3"
},
{
"input": "4\n2 3\n1 4\n100 200\n1000 2000",
"output": "1 2"
},
{
"input": "3\n1 1\n2 100\n3 99",
"output": "3 2"
},
{
"input": "3\n1 2\n1 3\n12 1234",
"output": "1 2"
},
{
"input": "3\n1 4\n2 6\n3 5",
"output": "3 2"
},
{
"input": "3\n1 10\n2 12\n1 9",
"output": "3 1"
},
{
"input": "2\n1 3\n1 5",
"output": "1 2"
},
{
"input": "3\n1 2\n2 5\n2 3",
"output": "3 2"
},
{
"input": "4\n1 3\n1 4\n5 10\n11 13",
"output": "1 2"
},
{
"input": "4\n7 15\n6 9\n9 10\n10 11",
"output": "3 1"
},
{
"input": "4\n2 3\n100 200\n1000 2000\n1 4",
"output": "1 4"
},
{
"input": "3\n10 20\n5 9\n11 19",
"output": "3 1"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10",
"output": "6 7"
},
{
"input": "2\n1 4\n1 7",
"output": "1 2"
},
{
"input": "3\n1 11\n2 12\n2 13",
"output": "2 3"
},
{
"input": "2\n1 4\n1 8",
"output": "1 2"
},
{
"input": "2\n2 5\n1 5",
"output": "1 2"
},
{
"input": "2\n2 9\n1 10",
"output": "1 2"
},
{
"input": "3\n2 4\n2 4\n1 3",
"output": "2 1"
},
{
"input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60",
"output": "3 4"
},
{
"input": "2\n1 3\n1 7",
"output": "1 2"
},
{
"input": "5\n4 6\n7 60\n80 90\n4 5\n8 80",
"output": "4 1"
},
{
"input": "2\n1 3\n1 4",
"output": "1 2"
},
{
"input": "3\n2 9\n1 7\n2 9",
"output": "3 1"
},
{
"input": "2\n1 4\n1 6",
"output": "1 2"
},
{
"input": "3\n4 4\n2 3\n4 5",
"output": "1 3"
},
{
"input": "2\n1 5\n1 7",
"output": "1 2"
},
{
"input": "2\n1 2\n1 4",
"output": "1 2"
},
{
"input": "4\n1 1\n2 2\n5 10\n2 4",
"output": "2 4"
},
{
"input": "3\n11 12\n11 15\n43 45",
"output": "1 2"
},
{
"input": "3\n2 3\n2 4\n2 5",
"output": "2 3"
},
{
"input": "2\n2 3\n2 5",
"output": "1 2"
},
{
"input": "3\n1 3\n1 4\n1 5",
"output": "2 3"
},
{
"input": "3\n1 1\n1 2\n1 3",
"output": "2 3"
},
{
"input": "2\n2 3\n1 3",
"output": "1 2"
},
{
"input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109",
"output": "11 5"
},
{
"input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11",
"output": "1 8"
},
{
"input": "4\n1 10\n12 15\n1 3\n17 18",
"output": "3 1"
},
{
"input": "3\n1 5\n1 10\n1 20",
"output": "2 3"
},
{
"input": "3\n1 1000\n1001 1003\n1 1",
"output": "3 1"
},
{
"input": "3\n1 10\n2 11\n2 11",
"output": "3 2"
},
{
"input": "2\n1 1\n1 3",
"output": "1 2"
},
{
"input": "2\n1 5\n1 6",
"output": "1 2"
},
{
"input": "3\n1 5\n3 6\n1 4",
"output": "3 1"
},
{
"input": "4\n2 8\n1 3\n2 9\n1 2",
"output": "4 2"
},
{
"input": "3\n3 6\n1 3\n3 9",
"output": "1 3"
},
{
"input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111",
"output": "1 5"
},
{
"input": "4\n1 2\n4 4\n3 3\n2 3",
"output": "3 4"
},
{
"input": "4\n1 1\n4 5\n7 9\n1 1",
"output": "4 1"
},
{
"input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281",
"output": "2 6"
},
{
"input": "2\n10 13\n10 14",
"output": "1 2"
},
{
"input": "5\n2 4\n3 6\n4 5\n222 333\n111 444",
"output": "3 2"
},
{
"input": "3\n1 2\n4 5\n1 1",
"output": "3 1"
},
{
"input": "2\n2 100\n1 100",
"output": "1 2"
},
{
"input": "3\n1 10\n9 20\n3 5",
"output": "3 1"
},
{
"input": "2\n1 9\n1 10",
"output": "1 2"
},
{
"input": "3\n1 2\n1 4\n1 6",
"output": "2 3"
}
] | 1,525,147,953 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 65,843,200 | #Failed
def divconq(seq):
if(len(seq) <= 1):
return False
eraser = seq[len(seq)//2]
skip_index = len(seq)//2
if divconq(seq[:skip_index]) or divconq(seq[skip_index+1:]):
return True
else:
for i in range(skip_index):
if(seq[i][1] >= eraser[1]):
print(eraser[2],seq[i][2])
return True
for i in range(skip_index+1,len(seq)):
if(seq[i][1] <= eraser[1]):
print(seq[i][2],eraser[2])
return True
n = int(input())
seq = []
for i in range(n):
seq.append(list(map(int,input().split())))
seq[i].append(i+1)
seq = sorted(seq,key = lambda x : (x[0],-x[1]))
if not divconq(seq):
print(-1,-1)
| Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
Output Specification:
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Demo Input:
['5\n1 10\n2 9\n3 9\n2 3\n2 9\n', '3\n1 5\n2 6\n6 20\n']
Demo Output:
['2 1\n', '-1 -1\n']
Note:
In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | ```python
#Failed
def divconq(seq):
if(len(seq) <= 1):
return False
eraser = seq[len(seq)//2]
skip_index = len(seq)//2
if divconq(seq[:skip_index]) or divconq(seq[skip_index+1:]):
return True
else:
for i in range(skip_index):
if(seq[i][1] >= eraser[1]):
print(eraser[2],seq[i][2])
return True
for i in range(skip_index+1,len(seq)):
if(seq[i][1] <= eraser[1]):
print(seq[i][2],eraser[2])
return True
n = int(input())
seq = []
for i in range(n):
seq.append(list(map(int,input().split())))
seq[i].append(i+1)
seq = sorted(seq,key = lambda x : (x[0],-x[1]))
if not divconq(seq):
print(-1,-1)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 0 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 1,440,871,629 | 5,829 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | n = int(input())
arr = list(map(int,input().split()))
primes = [2,3]
def gcd(a,b):
if(b == 0):
return a
return gcd(b,a%b)
def lcm(a,b):
return (a//gcd(a,b))*b
def num(x):
for i in range(2):
while(x%primes[i] == 0):
x//=primes[i]
return x == 1
lcm1 = arr[0]
for i in range(1,n):
lcm1 = lcm(lcm1,arr[i])
count = 1
for i in range(n):
mult = lcm1//arr[i]
if(not num(mult)):
count = 0
print("No")
break
if(count): print("Yes")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input Specification:
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Output Specification:
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Demo Input:
['4\n75 150 75 50\n', '3\n100 150 250\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | ```python
n = int(input())
arr = list(map(int,input().split()))
primes = [2,3]
def gcd(a,b):
if(b == 0):
return a
return gcd(b,a%b)
def lcm(a,b):
return (a//gcd(a,b))*b
def num(x):
for i in range(2):
while(x%primes[i] == 0):
x//=primes[i]
return x == 1
lcm1 = arr[0]
for i in range(1,n):
lcm1 = lcm(lcm1,arr[i])
count = 1
for i in range(n):
mult = lcm1//arr[i]
if(not num(mult)):
count = 0
print("No")
break
if(count): print("Yes")
``` | -1 |
|
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200",
"output": "YES"
},
{
"input": "2\n100 200",
"output": "NO"
},
{
"input": "2\n200 100",
"output": "NO"
},
{
"input": "3\n100 100 100",
"output": "NO"
},
{
"input": "3\n200 200 200",
"output": "NO"
},
{
"input": "3\n200 100 200",
"output": "NO"
},
{
"input": "4\n100 100 100 100",
"output": "YES"
},
{
"input": "4\n200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\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",
"output": "NO"
},
{
"input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "YES"
},
{
"input": "99\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 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 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": "NO"
},
{
"input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100",
"output": "YES"
},
{
"input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100",
"output": "NO"
},
{
"input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200",
"output": "YES"
},
{
"input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200",
"output": "YES"
},
{
"input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100",
"output": "YES"
},
{
"input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200",
"output": "YES"
},
{
"input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100",
"output": "YES"
},
{
"input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100",
"output": "YES"
},
{
"input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100",
"output": "NO"
},
{
"input": "5\n200 200 200 200 200",
"output": "NO"
},
{
"input": "9\n100 100 100 200 100 100 200 100 200",
"output": "YES"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "7\n200 200 200 100 200 200 200",
"output": "NO"
},
{
"input": "4\n100 100 200 200",
"output": "YES"
},
{
"input": "6\n100 100 100 200 200 200",
"output": "NO"
},
{
"input": "4\n200 100 100 200",
"output": "YES"
},
{
"input": "5\n100 100 100 100 200",
"output": "YES"
}
] | 1,686,034,052 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | def solve():
n=int(input())
w=list(map(int, input().split()))
cnt=0
s=sum(w)
for val in w:
if(val==100):
cnt+=1
for i in range(0,cnt+1):
t=i*100
for j in range(0,n-cnt+1):
t+=j*200
if(t==s-t):
print("YES")
return
print("NO")
solve()
| Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
Output Specification:
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Demo Input:
['3\n100 200 100\n', '4\n100 100 100 200\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | ```python
def solve():
n=int(input())
w=list(map(int, input().split()))
cnt=0
s=sum(w)
for val in w:
if(val==100):
cnt+=1
for i in range(0,cnt+1):
t=i*100
for j in range(0,n-cnt+1):
t+=j*200
if(t==s-t):
print("YES")
return
print("NO")
solve()
``` | 0 |
|
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,508,847,859 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,529,600 | n = int(input())
a = []
b = []
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
if n > 1:
res = min(a[0], a[1])
print((min(a[1], a[2]))*(n-2))
else:
print(0) | 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 = int(input())
a = []
b = []
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
if n > 1:
res = min(a[0], a[1])
print((min(a[1], a[2]))*(n-2))
else:
print(0)
``` | 0 |
|
494 | A | Treasure | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. | The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. | If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them. | [
"(((#)((#)\n",
"()((#((#(#()\n",
"#\n",
"(#)\n"
] | [
"1\n2\n",
"2\n2\n1",
"-1\n",
"-1\n"
] | |*s*| denotes the length of the string *s*. | 500 | [
{
"input": "(((#)((#)",
"output": "1\n2"
},
{
"input": "()((#((#(#()",
"output": "1\n1\n3"
},
{
"input": "#",
"output": "-1"
},
{
"input": "(#)",
"output": "-1"
},
{
"input": "(((((#(#(#(#()",
"output": "1\n1\n1\n5"
},
{
"input": "#))))",
"output": "-1"
},
{
"input": "((#(()#(##",
"output": "1\n1\n1\n1"
},
{
"input": "##((((((()",
"output": "-1"
},
{
"input": "(((((((((((((((((((###################",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": ")((##((###",
"output": "-1"
},
{
"input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((",
"output": "-1"
},
{
"input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(",
"output": "-1"
},
{
"input": "((#(",
"output": "-1"
},
{
"input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#",
"output": "-1"
},
{
"input": "(())((((#)",
"output": "3"
},
{
"input": "(#(",
"output": "-1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "(((()#(#)(",
"output": "-1"
},
{
"input": "#((#",
"output": "-1"
},
{
"input": "(#((((()",
"output": "-1"
},
{
"input": "(#((",
"output": "-1"
},
{
"input": ")(((())#",
"output": "-1"
}
] | 1,658,992,629 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 13 | 93 | 6,144,000 | s = input().strip()
def solve(s):
l = 0
r = 0
c = 0
remain = 0
res = []
for i in range(len(s)):
if s[i] == '(':
l += 1
elif s[i] == ')':
r += 1
if r > l:
print(-1)
return
else:
r += 1
res.append(1)
if l < r:
print(-1)
return
res[-1] += l - r
for i in range(len(res)):
print(res[i])
solve(s) | Title: Treasure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
Input Specification:
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
Output Specification:
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them.
Demo Input:
['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n']
Demo Output:
['1\n2\n', '2\n2\n1', '-1\n', '-1\n']
Note:
|*s*| denotes the length of the string *s*. | ```python
s = input().strip()
def solve(s):
l = 0
r = 0
c = 0
remain = 0
res = []
for i in range(len(s)):
if s[i] == '(':
l += 1
elif s[i] == ')':
r += 1
if r > l:
print(-1)
return
else:
r += 1
res.append(1)
if l < r:
print(-1)
return
res[-1] += l - r
for i in range(len(res)):
print(res[i])
solve(s)
``` | 0 |
|
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 539 896 668 36 896",
"output": "YES"
},
{
"input": "7\n674 712 674 674 674 674 674",
"output": "NO"
},
{
"input": "8\n742 742 742 742 742 289 742 742",
"output": "NO"
},
{
"input": "9\n730 351 806 806 806 630 85 757 967",
"output": "YES"
},
{
"input": "10\n324 539 83 440 834 640 440 440 440 440",
"output": "YES"
},
{
"input": "7\n925 830 925 98 987 162 356",
"output": "YES"
},
{
"input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808",
"output": "YES"
},
{
"input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94",
"output": "YES"
},
{
"input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402",
"output": "NO"
},
{
"input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187",
"output": "YES"
},
{
"input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103",
"output": "YES"
},
{
"input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925",
"output": "NO"
},
{
"input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353",
"output": "YES"
},
{
"input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285",
"output": "NO"
},
{
"input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99",
"output": "YES"
},
{
"input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26",
"output": "YES"
},
{
"input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516",
"output": "YES"
},
{
"input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314",
"output": "NO"
},
{
"input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800",
"output": "NO"
},
{
"input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317",
"output": "NO"
},
{
"input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784",
"output": "YES"
},
{
"input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474",
"output": "YES"
},
{
"input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499",
"output": "NO"
},
{
"input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816",
"output": "NO"
},
{
"input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "12\n2 2 4 4 4 4 6 6 6 6 6 6",
"output": "YES"
}
] | 1,592,730,409 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 204,800 |
if __name__=="__main__":
n=int(input())
li=list(map(int,inpuit().split(" ")))
if(n==1):
print("YES")
if(n==2):
if(li[0]==li[1]):
print("NO")
else:
print("YES")
else:
z=0
para="true"
for i in range(0,n-1):
if(li[i]==li[i+1]):
z+=1
if(z==2):
para="false"
break
else:
z=0
temp=li[i+1]
li[i+1]=li[i]
li[i]=temp
if(para=="true"):
print("YES")
else:
print("NO")
| Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
Output Specification:
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
Demo Input:
['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | ```python
if __name__=="__main__":
n=int(input())
li=list(map(int,inpuit().split(" ")))
if(n==1):
print("YES")
if(n==2):
if(li[0]==li[1]):
print("NO")
else:
print("YES")
else:
z=0
para="true"
for i in range(0,n-1):
if(li[i]==li[i+1]):
z+=1
if(z==2):
para="false"
break
else:
z=0
temp=li[i+1]
li[i+1]=li[i]
li[i]=temp
if(para=="true"):
print("YES")
else:
print("NO")
``` | -1 |
|
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR",
"output": "67"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU",
"output": "99"
},
{
"input": "3\nRUR",
"output": "2"
},
{
"input": "1\nR",
"output": "1"
},
{
"input": "5\nRURUU",
"output": "3"
},
{
"input": "1\nU",
"output": "1"
},
{
"input": "2\nUR",
"output": "1"
},
{
"input": "23\nUUUUUUUUUUUUUUUUUUUUUUU",
"output": "23"
}
] | 1,677,953,072 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
moves = input()
# Replace all occurrences of "RU" or "UR" with "D"
moves = moves.replace("RU", "D")
moves = moves.replace("UR", "D")
# Print the length of the modified sequence
print(len(moves) | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Output Specification:
Print the minimum possible length of the sequence of moves after all replacements are done.
Demo Input:
['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n']
Demo Output:
['3\n', '13\n']
Note:
In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | ```python
n = int(input())
moves = input()
# Replace all occurrences of "RU" or "UR" with "D"
moves = moves.replace("RU", "D")
moves = moves.replace("UR", "D")
# Print the length of the modified sequence
print(len(moves)
``` | -1 |
|
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha? | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"
},
{
"input": "1000000000",
"output": "666666667"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "666666666"
},
{
"input": "999999998",
"output": "666666665"
},
{
"input": "999999997",
"output": "666666665"
},
{
"input": "999999996",
"output": "666666664"
},
{
"input": "999999995",
"output": "666666663"
},
{
"input": "999999994",
"output": "666666663"
},
{
"input": "999999993",
"output": "666666662"
},
{
"input": "999999992",
"output": "666666661"
},
{
"input": "999999991",
"output": "666666661"
},
{
"input": "1000",
"output": "667"
},
{
"input": "10000",
"output": "6667"
},
{
"input": "100000",
"output": "66667"
},
{
"input": "1000000",
"output": "666667"
},
{
"input": "10000000",
"output": "6666667"
},
{
"input": "100000000",
"output": "66666667"
},
{
"input": "7",
"output": "5"
}
] | 1,639,544,133 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 109 | 0 | n = int(input())
chislo_par = n // 3
podarkov = chislo_par * 2
n = n - chislo_par * 3
if n == 1 or n == 2:
podarkov = podarkov + 1
print(podarkov) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Output Specification:
Print the maximum possible number of times Artem can give presents to Masha.
Demo Input:
['1\n', '2\n', '3\n', '4\n']
Demo Output:
['1\n', '1\n', '2\n', '3\n']
Note:
In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | ```python
n = int(input())
chislo_par = n // 3
podarkov = chislo_par * 2
n = n - chislo_par * 3
if n == 1 or n == 2:
podarkov = podarkov + 1
print(podarkov)
``` | 3 |
|
547 | A | Mike and Frog | PROGRAMMING | 2,200 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is *h*1 and height of Abol is *h*2. Each second, Mike waters Abol and Xaniar.
So, if height of Xaniar is *h*1 and height of Abol is *h*2, after one second height of Xaniar will become and height of Abol will become where *x*1,<=*y*1,<=*x*2 and *y*2 are some integer numbers and denotes the remainder of *a* modulo *b*.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is *a*1 and height of Abol is *a*2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen. | The first line of input contains integer *m* (2<=≤<=*m*<=≤<=106).
The second line of input contains integers *h*1 and *a*1 (0<=≤<=*h*1,<=*a*1<=<<=*m*).
The third line of input contains integers *x*1 and *y*1 (0<=≤<=*x*1,<=*y*1<=<<=*m*).
The fourth line of input contains integers *h*2 and *a*2 (0<=≤<=*h*2,<=*a*2<=<<=*m*).
The fifth line of input contains integers *x*2 and *y*2 (0<=≤<=*x*2,<=*y*2<=<<=*m*).
It is guaranteed that *h*1<=≠<=*a*1 and *h*2<=≠<=*a*2. | Print the minimum number of seconds until Xaniar reaches height *a*1 and Abol reaches height *a*2 or print -1 otherwise. | [
"5\n4 2\n1 1\n0 1\n2 3\n",
"1023\n1 2\n1 0\n1 2\n1 1\n"
] | [
"3\n",
"-1\n"
] | In the first sample, heights sequences are following:
Xaniar: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/85da629b05969e7a8a6636d995b8fe7a0494e8f4.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Abol: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea95da14490864ae8b8bfcd4a8b7c02ad3a666b3.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 750 | [
{
"input": "5\n4 2\n1 1\n0 1\n2 3",
"output": "3"
},
{
"input": "1023\n1 2\n1 0\n1 2\n1 1",
"output": "-1"
},
{
"input": "1023\n1 2\n1 2\n1 2\n1 2",
"output": "512"
},
{
"input": "2\n0 1\n1 0\n1 0\n0 1",
"output": "-1"
},
{
"input": "17\n15 12\n15 12\n12 14\n1 11",
"output": "-1"
},
{
"input": "29\n4 0\n1 1\n25 20\n16 0",
"output": "170"
},
{
"input": "91\n9 64\n75 32\n60 81\n35 46",
"output": "5"
},
{
"input": "91\n38 74\n66 10\n40 76\n17 13",
"output": "-1"
},
{
"input": "100\n11 20\n99 31\n60 44\n45 64",
"output": "3"
},
{
"input": "9999\n4879 6224\n63 7313\n4279 6583\n438 1627",
"output": "4"
},
{
"input": "10000\n8681 4319\n9740 5980\n24 137\n462 7971",
"output": "-1"
},
{
"input": "100000\n76036 94415\n34870 43365\n56647 26095\n88580 30995",
"output": "5"
},
{
"input": "100000\n90861 77058\n96282 30306\n45940 25601\n17117 48287",
"output": "-1"
},
{
"input": "1000000\n220036 846131\n698020 485511\n656298 242999\n766802 905433",
"output": "5297"
},
{
"input": "1000000\n536586 435396\n748740 34356\n135075 790803\n547356 534911",
"output": "9958"
},
{
"input": "1000000\n661647 690400\n864868 326304\n581148 452012\n327910 197092",
"output": "1021"
},
{
"input": "1000000\n233404 949288\n893747 751429\n692094 57207\n674400 583468",
"output": "-1"
},
{
"input": "1000000\n358465 242431\n977171 267570\n170871 616951\n711850 180241",
"output": "-1"
},
{
"input": "1000000\n707719 502871\n60595 816414\n649648 143990\n525107 66615",
"output": "-1"
},
{
"input": "999983\n192005 690428\n971158 641039\n974183 1882\n127579 312317",
"output": "470479"
},
{
"input": "999983\n420528 808305\n387096 497121\n596163 353326\n47177 758204",
"output": "548500"
},
{
"input": "999983\n651224 992349\n803017 393514\n258455 402487\n888310 244420",
"output": "126531"
},
{
"input": "999983\n151890 906425\n851007 9094\n696594 968184\n867017 157783",
"output": "-1"
},
{
"input": "999983\n380412 325756\n266945 907644\n318575 83081\n786616 603671",
"output": "-1"
},
{
"input": "999983\n570797 704759\n723177 763726\n978676 238272\n708387 89886",
"output": "-1"
},
{
"input": "999983\n408725 408721\n1 1\n378562 294895\n984270 0",
"output": "499981500166"
},
{
"input": "999983\n639420 639416\n1 1\n507684 954997\n466316 0",
"output": "499981500166"
},
{
"input": "999983\n867942 867939\n1 1\n963840 536667\n899441 0",
"output": "999964000320"
},
{
"input": "999961\n664221 931770\n530542 936292\n885122 515424\n868560 472225",
"output": "-1"
},
{
"input": "999961\n744938 661980\n845908 76370\n237399 381935\n418010 938769",
"output": "203332"
},
{
"input": "999961\n89288 89284\n1 1\n764559 727291\n999322 0",
"output": "999920001595"
},
{
"input": "1000000\n661703 661699\n1 1\n425192 823944\n854093 0",
"output": "-1"
},
{
"input": "100019\n98811 98807\n1 1\n91322 14787\n72253 0",
"output": "10003600319"
},
{
"input": "524288\n199980 199978\n1 1\n236260 325076\n81773 0",
"output": "-1"
},
{
"input": "524288\n47283 489031\n305624 183135\n141146 335913\n519614 150715",
"output": "19"
},
{
"input": "524288\n83398 33987\n158854 211502\n36433 18758\n218812 517001",
"output": "-1"
},
{
"input": "912488\n681639 518634\n168348 212018\n255428 4970\n31726 664998",
"output": "34838"
},
{
"input": "129081\n128454 36771\n116353 2940\n95311 22200\n579 118683",
"output": "68409"
},
{
"input": "129081\n45717 106320\n121816 69841\n5161 4872\n102076 100020",
"output": "-1"
},
{
"input": "4\n1 2\n1 1\n0 1\n2 0",
"output": "-1"
},
{
"input": "3\n1 0\n1 1\n1 2\n2 0",
"output": "5"
},
{
"input": "3\n0 2\n1 0\n2 0\n2 1",
"output": "-1"
},
{
"input": "2\n0 1\n0 1\n0 1\n0 1",
"output": "1"
},
{
"input": "2\n0 1\n1 0\n0 1\n1 0",
"output": "-1"
},
{
"input": "2\n0 1\n1 1\n0 1\n1 1",
"output": "1"
},
{
"input": "2\n0 1\n1 1\n0 1\n1 0",
"output": "-1"
},
{
"input": "2\n0 1\n1 0\n0 1\n1 1",
"output": "-1"
},
{
"input": "1000000\n1 0\n1 1\n1 0\n1 1",
"output": "999999"
},
{
"input": "1000000\n2 1\n1 1\n2 0\n1 2",
"output": "999999"
},
{
"input": "6\n1 2\n3 5\n0 2\n4 2",
"output": "1"
},
{
"input": "545\n26 40\n477 97\n454 394\n15 264",
"output": "90"
},
{
"input": "3\n1 0\n0 1\n0 2\n1 0",
"output": "-1"
},
{
"input": "1376\n1227 1349\n313 193\n1113 361\n1314 23",
"output": "338"
},
{
"input": "1376\n1322 1320\n1 1\n776 495\n38 0",
"output": "-1"
},
{
"input": "1376\n152 405\n1083 1328\n76 856\n49 629",
"output": "-1"
},
{
"input": "1392\n1060 796\n512 242\n1386 1346\n1310 1199",
"output": "-1"
},
{
"input": "100000\n5827 41281\n41285 70821\n99199 42807\n65667 94952",
"output": "13770"
},
{
"input": "100000\n51157 27741\n40564 90740\n45270 52367\n31585 92150",
"output": "-1"
},
{
"input": "100000\n70525 70522\n1 1\n89465 30265\n33279 0",
"output": "-1"
},
{
"input": "10\n1 6\n7 9\n1 4\n4 0",
"output": "1"
},
{
"input": "10\n9 6\n0 8\n3 0\n2 7",
"output": "-1"
},
{
"input": "10\n4 2\n1 1\n7 3\n9 0",
"output": "-1"
},
{
"input": "6\n5 1\n1 1\n3 1\n3 0",
"output": "-1"
},
{
"input": "999983\n3 1\n1 1\n8 1\n2 0",
"output": "499981500168"
},
{
"input": "18\n3 9\n3 0\n1 3\n3 0",
"output": "1"
},
{
"input": "18\n1 3\n3 0\n3 9\n3 0",
"output": "1"
},
{
"input": "16\n1 0\n2 0\n1 2\n2 0",
"output": "-1"
},
{
"input": "16\n8 0\n2 0\n1 4\n2 0",
"output": "2"
},
{
"input": "999983\n2 1\n2 0\n1 0\n1 1",
"output": "499982500152"
},
{
"input": "324\n2 54\n3 0\n27 108\n2 0",
"output": "-1"
},
{
"input": "999993\n499997 1\n2 3\n1 4\n1 1",
"output": "39325724721"
},
{
"input": "999983\n1 37827\n1 1\n2 192083\n3 0",
"output": "404303164556"
},
{
"input": "41222\n30759 26408\n31332 39118\n5026 25812\n1 9030",
"output": "58900566"
},
{
"input": "100007\n2 1\n2 0\n3 1\n1 1",
"output": "434330399"
},
{
"input": "8\n0 4\n4 4\n1 4\n2 0",
"output": "2"
}
] | 1,432,666,481 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 50 | 545 | 24,678,400 | import fractions
def read_data():
m = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
return m, h1, a1, x1, y1, h2, a2, x2, y2
def solve(m, h1, a1, x1, y1, h2, a2, x2, y2):
t = 0
h1s = [-1] * m
h2s = [-1] * m
h1s[h1] = 0
h2s[h2] = 0
t1 = -1
t2 = -1
while h1 != a1 or h2 != a2:
t += 1
h1 = (x1 * h1 + y1) % m
h2 = (x2 * h2 + y2) % m
if h1s[h1] >= 0:
t1 = h1s[h1]
s1 = t - t1
if t2 >= 0:
break
else:
h1s[h1] = t
if h2s[h2] >= 0:
t2 = h2s[h2]
s2 = t - t2
if t1 >= 0:
break
else:
h2s[h2] = t
if h1 == a1 and h2 == a2:
return t
return retrieve(a1, a2, t1, s1, t2, s2, h1s, h2s)
def retrieve(a1, a2, t1, s1, t2, s2, h1s, h2s):
u1 = h1s[a1]
u2 = h2s[a2]
if u1 == -1 or u2 == -1:
return -1
if u1 < t1:
if guess(h2s, u1, t2, s2, a2):
return u1
else:
return -1
if u2 < t2:
if guess(h1s, u2, t1, s1, a1):
return u2
else:
return -1
return find_time(u1, s1, u2, s2)
def guess(hs, u, t, s, a):
if u <= t:
return hs[u] == a
tt = t + (u - t) % s
return hs[a] == tt
def find_time(u1, s1, u2, s2):
g = fractions.gcd(s1, s2)
if abs(u1 - u2) % g:
return -1
k1, k2 = extended_euclid(s1, s2, u2-u1, g)
b = s2 // g
return (k1 % b) * s1 + u1
def egcd(a, b):
x, lastx = 0, 1
y, lasty = 1, 0
while b:
q = a // b
a, b = b, a % b
x, lastx = lastx - q * x, x
y, lasty = lasty - q * y, y
return lastx, lasty
def extended_euclid(a, b, c, g):
x, y = egcd(a, b)
return (c // g) * x, (x // g) * y
param = read_data()
print(solve(*param)) | Title: Mike and Frog
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is *h*1 and height of Abol is *h*2. Each second, Mike waters Abol and Xaniar.
So, if height of Xaniar is *h*1 and height of Abol is *h*2, after one second height of Xaniar will become and height of Abol will become where *x*1,<=*y*1,<=*x*2 and *y*2 are some integer numbers and denotes the remainder of *a* modulo *b*.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is *a*1 and height of Abol is *a*2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input Specification:
The first line of input contains integer *m* (2<=≤<=*m*<=≤<=106).
The second line of input contains integers *h*1 and *a*1 (0<=≤<=*h*1,<=*a*1<=<<=*m*).
The third line of input contains integers *x*1 and *y*1 (0<=≤<=*x*1,<=*y*1<=<<=*m*).
The fourth line of input contains integers *h*2 and *a*2 (0<=≤<=*h*2,<=*a*2<=<<=*m*).
The fifth line of input contains integers *x*2 and *y*2 (0<=≤<=*x*2,<=*y*2<=<<=*m*).
It is guaranteed that *h*1<=≠<=*a*1 and *h*2<=≠<=*a*2.
Output Specification:
Print the minimum number of seconds until Xaniar reaches height *a*1 and Abol reaches height *a*2 or print -1 otherwise.
Demo Input:
['5\n4 2\n1 1\n0 1\n2 3\n', '1023\n1 2\n1 0\n1 2\n1 1\n']
Demo Output:
['3\n', '-1\n']
Note:
In the first sample, heights sequences are following:
Xaniar: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/85da629b05969e7a8a6636d995b8fe7a0494e8f4.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Abol: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea95da14490864ae8b8bfcd4a8b7c02ad3a666b3.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import fractions
def read_data():
m = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
return m, h1, a1, x1, y1, h2, a2, x2, y2
def solve(m, h1, a1, x1, y1, h2, a2, x2, y2):
t = 0
h1s = [-1] * m
h2s = [-1] * m
h1s[h1] = 0
h2s[h2] = 0
t1 = -1
t2 = -1
while h1 != a1 or h2 != a2:
t += 1
h1 = (x1 * h1 + y1) % m
h2 = (x2 * h2 + y2) % m
if h1s[h1] >= 0:
t1 = h1s[h1]
s1 = t - t1
if t2 >= 0:
break
else:
h1s[h1] = t
if h2s[h2] >= 0:
t2 = h2s[h2]
s2 = t - t2
if t1 >= 0:
break
else:
h2s[h2] = t
if h1 == a1 and h2 == a2:
return t
return retrieve(a1, a2, t1, s1, t2, s2, h1s, h2s)
def retrieve(a1, a2, t1, s1, t2, s2, h1s, h2s):
u1 = h1s[a1]
u2 = h2s[a2]
if u1 == -1 or u2 == -1:
return -1
if u1 < t1:
if guess(h2s, u1, t2, s2, a2):
return u1
else:
return -1
if u2 < t2:
if guess(h1s, u2, t1, s1, a1):
return u2
else:
return -1
return find_time(u1, s1, u2, s2)
def guess(hs, u, t, s, a):
if u <= t:
return hs[u] == a
tt = t + (u - t) % s
return hs[a] == tt
def find_time(u1, s1, u2, s2):
g = fractions.gcd(s1, s2)
if abs(u1 - u2) % g:
return -1
k1, k2 = extended_euclid(s1, s2, u2-u1, g)
b = s2 // g
return (k1 % b) * s1 + u1
def egcd(a, b):
x, lastx = 0, 1
y, lasty = 1, 0
while b:
q = a // b
a, b = b, a % b
x, lastx = lastx - q * x, x
y, lasty = lasty - q * y, y
return lastx, lasty
def extended_euclid(a, b, c, g):
x, y = egcd(a, b)
return (c // g) * x, (x // g) * y
param = read_data()
print(solve(*param))
``` | 0 |
|
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct. | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155",
"output": "NO"
},
{
"input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968",
"output": "NO"
},
{
"input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290",
"output": "NO"
},
{
"input": "1\na 2400 2401",
"output": "YES"
},
{
"input": "1\nfucker 4000 4000",
"output": "NO"
},
{
"input": "1\nJora 2400 2401",
"output": "YES"
},
{
"input": "1\nACA 2400 2420",
"output": "YES"
},
{
"input": "1\nAca 2400 2420",
"output": "YES"
},
{
"input": "1\nSub_d 2401 2402",
"output": "YES"
},
{
"input": "2\nHack 2400 2401\nDum 1243 555",
"output": "YES"
},
{
"input": "1\nXXX 2400 2500",
"output": "YES"
},
{
"input": "1\nfucker 2400 2401",
"output": "YES"
},
{
"input": "1\nX 2400 2500",
"output": "YES"
},
{
"input": "1\nvineet 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2500",
"output": "YES"
},
{
"input": "1\naaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nhoge 2400 2401",
"output": "YES"
},
{
"input": "1\nInfinity 2400 2468",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2401",
"output": "YES"
},
{
"input": "1\nFuck 2400 2401",
"output": "YES"
},
{
"input": "1\nfuck 2400 2401",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "YES"
},
{
"input": "1\nalex 2400 2401",
"output": "YES"
},
{
"input": "1\nA 2400 2401",
"output": "YES"
},
{
"input": "1\na 2400 2455",
"output": "YES"
},
{
"input": "1\nlol 2400 2401",
"output": "YES"
},
{
"input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214",
"output": "YES"
},
{
"input": "1\naaaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2500",
"output": "YES"
},
{
"input": "1\nds 2400 2410",
"output": "YES"
},
{
"input": "1\nas 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2401",
"output": "YES"
},
{
"input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537",
"output": "YES"
},
{
"input": "1\ncaonima 2400 2401",
"output": "YES"
},
{
"input": "1\narr 2400 2500",
"output": "YES"
},
{
"input": "1\nx 2400 2401",
"output": "YES"
},
{
"input": "1\narrr 2400 2500",
"output": "YES"
},
{
"input": "1\nabc 2400 2405",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2537",
"output": "YES"
},
{
"input": "1\nHELLO 2400 2401",
"output": "YES"
},
{
"input": "1\neatmore 2400 2500",
"output": "YES"
},
{
"input": "1\nb 2400 2401",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nApplejack 2400 2410",
"output": "YES"
},
{
"input": "1\nabacaba 2400 2451",
"output": "YES"
},
{
"input": "1\nrekt_n00b 2500 2600",
"output": "YES"
}
] | 1,592,845,344 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 124 | 0 | t=int(input())
d=0
for i in range(t):
a,b,c=input().split()
x=int(b)
y=int(c)
if(x>=2400 and y-x>0):
d+=1
if(d>=1):
print("YES")
else:
print("NO")
#3
#Burunduk1 2526 2537
#BudAlNik 2084 2214
#subscriber 2833 2749
#3
#Applejack 2400 2400
#Fluttershy 2390 2431
#Pinkie_Pie -2500 -2450
| Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
Output Specification:
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
Demo Input:
['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | ```python
t=int(input())
d=0
for i in range(t):
a,b,c=input().split()
x=int(b)
y=int(c)
if(x>=2400 and y-x>0):
d+=1
if(d>=1):
print("YES")
else:
print("NO")
#3
#Burunduk1 2526 2537
#BudAlNik 2084 2214
#subscriber 2833 2749
#3
#Applejack 2400 2400
#Fluttershy 2390 2431
#Pinkie_Pie -2500 -2450
``` | 3 |
|
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).
Your task is to find out if a given integer is a triangular number. | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "12",
"output": "NO"
},
{
"input": "10",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "9",
"output": "NO"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "YES"
},
{
"input": "16",
"output": "NO"
},
{
"input": "20",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "22",
"output": "NO"
},
{
"input": "121",
"output": "NO"
},
{
"input": "135",
"output": "NO"
},
{
"input": "136",
"output": "YES"
},
{
"input": "137",
"output": "NO"
},
{
"input": "152",
"output": "NO"
},
{
"input": "153",
"output": "YES"
},
{
"input": "154",
"output": "NO"
},
{
"input": "171",
"output": "YES"
},
{
"input": "189",
"output": "NO"
},
{
"input": "190",
"output": "YES"
},
{
"input": "191",
"output": "NO"
},
{
"input": "210",
"output": "YES"
},
{
"input": "211",
"output": "NO"
},
{
"input": "231",
"output": "YES"
},
{
"input": "232",
"output": "NO"
},
{
"input": "252",
"output": "NO"
},
{
"input": "253",
"output": "YES"
},
{
"input": "254",
"output": "NO"
},
{
"input": "275",
"output": "NO"
},
{
"input": "276",
"output": "YES"
},
{
"input": "277",
"output": "NO"
},
{
"input": "299",
"output": "NO"
},
{
"input": "300",
"output": "YES"
},
{
"input": "301",
"output": "NO"
},
{
"input": "324",
"output": "NO"
},
{
"input": "325",
"output": "YES"
},
{
"input": "326",
"output": "NO"
},
{
"input": "350",
"output": "NO"
},
{
"input": "351",
"output": "YES"
},
{
"input": "352",
"output": "NO"
},
{
"input": "377",
"output": "NO"
},
{
"input": "378",
"output": "YES"
},
{
"input": "406",
"output": "YES"
},
{
"input": "434",
"output": "NO"
},
{
"input": "435",
"output": "YES"
},
{
"input": "464",
"output": "NO"
},
{
"input": "465",
"output": "YES"
},
{
"input": "495",
"output": "NO"
},
{
"input": "496",
"output": "YES"
},
{
"input": "497",
"output": "NO"
},
{
"input": "331",
"output": "NO"
},
{
"input": "413",
"output": "NO"
},
{
"input": "177",
"output": "NO"
},
{
"input": "122",
"output": "NO"
},
{
"input": "478",
"output": "NO"
},
{
"input": "188",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "474",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "48",
"output": "NO"
},
{
"input": "498",
"output": "NO"
},
{
"input": "499",
"output": "NO"
},
{
"input": "500",
"output": "NO"
}
] | 1,614,184,034 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 |
n = int(input())
if (n*(n+1))//2 + ((n-1)*n)//2 == n ** 2:
print('YES')
else:
print('NO') | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).
Your task is to find out if a given integer is a triangular number.
Input Specification:
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
Output Specification:
If the given integer is a triangular number output YES, otherwise output NO.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
n = int(input())
if (n*(n+1))//2 + ((n-1)*n)//2 == n ** 2:
print('YES')
else:
print('NO')
``` | 0 |
908 | C | New Year and Curling | PROGRAMMING | 1,500 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one by one in order from 1 to *n*.
When she slides the *i*-th disk, she will place its center at the point (*x**i*,<=10100). She will then push it so the disk’s *y* coordinate continuously decreases, and *x* coordinate stays constant. The disk stops once it touches the line *y*<==<=0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.
Compute the *y*-coordinates of centers of all the disks after all disks have been pushed. | The first line will contain two integers *n* and *r* (1<=≤<=*n*,<=*r*<=≤<=1<=000), the number of disks, and the radius of the disks, respectively.
The next line will contain *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=1<=000) — the *x*-coordinates of the disks. | Print a single line with *n* numbers. The *i*-th number denotes the *y*-coordinate of the center of the *i*-th disk. The output will be accepted if it has absolute or relative error at most 10<=-<=6.
Namely, let's assume that your answer for a particular value of a coordinate is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if for all coordinates. | [
"6 2\n5 5 6 8 3 12\n"
] | [
"2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\n"
] | The final positions of the disks will look as follows:
In particular, note the position of the last disk. | 1,000 | [
{
"input": "6 2\n5 5 6 8 3 12",
"output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "5 300\n939 465 129 611 532",
"output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391"
},
{
"input": "5 1\n416 387 336 116 81",
"output": "1 1 1 1 1"
},
{
"input": "3 10\n1 100 1000",
"output": "10 10 10"
},
{
"input": "2 1\n2 20",
"output": "1 1"
},
{
"input": "3 2\n10 10 100",
"output": "2 6.0 2"
}
] | 1,672,588,958 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 639 | 0 | n,r=list(map(int, input().split()))
a=list(map(int, input().split()))
r_2=(2*r)**2
c=[]
for i in range(n):
if i==0:
c.append(r)
else:
x2=a[i]
k=[]
for j in range(i):
x1=a[j]
y1=c[j]
if abs(x2-x1)<=2*r:
k.append((r_2-(x2-x1)**2)**0.5+y1)
if len(k)==0:
c.append(r)
else:
c.append(max(k))
print(*c) | Title: New Year and Curling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one by one in order from 1 to *n*.
When she slides the *i*-th disk, she will place its center at the point (*x**i*,<=10100). She will then push it so the disk’s *y* coordinate continuously decreases, and *x* coordinate stays constant. The disk stops once it touches the line *y*<==<=0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.
Compute the *y*-coordinates of centers of all the disks after all disks have been pushed.
Input Specification:
The first line will contain two integers *n* and *r* (1<=≤<=*n*,<=*r*<=≤<=1<=000), the number of disks, and the radius of the disks, respectively.
The next line will contain *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=1<=000) — the *x*-coordinates of the disks.
Output Specification:
Print a single line with *n* numbers. The *i*-th number denotes the *y*-coordinate of the center of the *i*-th disk. The output will be accepted if it has absolute or relative error at most 10<=-<=6.
Namely, let's assume that your answer for a particular value of a coordinate is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if for all coordinates.
Demo Input:
['6 2\n5 5 6 8 3 12\n']
Demo Output:
['2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\n']
Note:
The final positions of the disks will look as follows:
In particular, note the position of the last disk. | ```python
n,r=list(map(int, input().split()))
a=list(map(int, input().split()))
r_2=(2*r)**2
c=[]
for i in range(n):
if i==0:
c.append(r)
else:
x2=a[i]
k=[]
for j in range(i):
x1=a[j]
y1=c[j]
if abs(x2-x1)<=2*r:
k.append((r_2-(x2-x1)**2)**0.5+y1)
if len(k)==0:
c.append(r)
else:
c.append(max(k))
print(*c)
``` | 3 |
|
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*. | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order. | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"output": "100"
},
{
"input": "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 3569 3578 3615 3641 3673 3892 4142 4418 4515 4766 4846 4916 5225 5269 5352 5460 5472 5635 5732 5886 5941 5976 5984 6104 6113 6402 6409 6460 6550 6563 6925 7006 7289 7401 7441 7451 7709 7731 7742 7750 7752 7827 8101 8154 8376 8379 8432 8534 8578 8630 8706 8814 8882 8972 9041 9053 9109 9173 9473 9524 9547 9775 9791 9983",
"output": "9983"
},
{
"input": "10 9\n7 29 35 38 41 47 54 56 73 74",
"output": "74"
},
{
"input": "1 2342\n12345",
"output": "12345"
},
{
"input": "10 5\n15 15 20 28 38 44 46 52 69 94",
"output": "109"
},
{
"input": "10 9\n6 10 10 32 36 38 69 80 82 93",
"output": "93"
},
{
"input": "10 10\n4 19 22 24 25 43 49 56 78 88",
"output": "88"
},
{
"input": "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 5683 5738 5767 5806 5973 6051 6134 6254 6266 6279 6314 6342 6599 6676 6747 6777 6827 6842 7057 7097 7259 7340 7378 7405 7510 7520 7698 7796 8148 8351 8507 8601 8805 8814 8826 8978 9116 9140 9174 9338 9394 9403 9407 9423 9429 9519 9764 9784 9838 9946",
"output": "9946"
},
{
"input": "100 74\n10 211 323 458 490 592 979 981 1143 1376 1443 1499 1539 1612 1657 1874 2001 2064 2123 2274 2346 2471 2522 2589 2879 2918 2933 2952 3160 3164 3167 3270 3382 3404 3501 3522 3616 3802 3868 3985 4007 4036 4101 4580 4687 4713 4714 4817 4955 5257 5280 5343 5428 5461 5566 5633 5727 5874 5925 6233 6309 6389 6500 6701 6731 6847 6916 7088 7088 7278 7296 7328 7564 7611 7646 7887 7887 8065 8075 8160 8300 8304 8316 8355 8404 8587 8758 8794 8890 9038 9163 9235 9243 9339 9410 9587 9868 9916 9923 9986",
"output": "9986"
},
{
"input": "100 61\n82 167 233 425 432 456 494 507 562 681 683 921 1218 1323 1395 1531 1586 1591 1675 1766 1802 1842 2116 2625 2697 2735 2739 3337 3349 3395 3406 3596 3610 3721 4059 4078 4305 4330 4357 4379 4558 4648 4651 4784 4819 4920 5049 5312 5361 5418 5440 5463 5547 5594 5821 5951 5972 6141 6193 6230 6797 6842 6853 6854 7017 7026 7145 7322 7391 7460 7599 7697 7756 7768 7872 7889 8094 8215 8408 8440 8462 8714 8756 8760 8881 9063 9111 9184 9281 9373 9406 9417 9430 9511 9563 9634 9660 9788 9883 9927",
"output": "9927"
},
{
"input": "100 84\n53 139 150 233 423 570 786 861 995 1017 1072 1196 1276 1331 1680 1692 1739 1748 1826 2067 2280 2324 2368 2389 2607 2633 2760 2782 2855 2996 3030 3093 3513 3536 3557 3594 3692 3707 3823 3832 4009 4047 4088 4095 4408 4537 4565 4601 4784 4878 4935 5029 5252 5322 5389 5407 5511 5567 5857 6182 6186 6198 6280 6290 6353 6454 6458 6567 6843 7166 7216 7257 7261 7375 7378 7539 7542 7762 7771 7797 7980 8363 8606 8612 8663 8801 8808 8823 8918 8975 8997 9240 9245 9259 9356 9755 9759 9760 9927 9970",
"output": "9970"
},
{
"input": "100 50\n130 248 312 312 334 589 702 916 921 1034 1047 1346 1445 1500 1585 1744 1951 2123 2273 2362 2400 2455 2496 2530 2532 2944 3074 3093 3094 3134 3698 3967 4047 4102 4109 4260 4355 4466 4617 4701 4852 4892 4915 4917 4936 4981 4999 5106 5152 5203 5214 5282 5412 5486 5525 5648 5897 5933 5969 6251 6400 6421 6422 6558 6805 6832 6908 6924 6943 6980 7092 7206 7374 7417 7479 7546 7672 7756 7973 8020 8028 8079 8084 8085 8137 8153 8178 8239 8639 8667 8829 9263 9333 9370 9420 9579 9723 9784 9841 9993",
"output": "11103"
},
{
"input": "100 50\n156 182 208 409 496 515 659 761 772 794 827 912 1003 1236 1305 1388 1412 1422 1428 1465 1613 2160 2411 2440 2495 2684 2724 2925 3033 3035 3155 3260 3378 3442 3483 3921 4031 4037 4091 4113 4119 4254 4257 4442 4559 4614 4687 4839 4896 5054 5246 5316 5346 5859 5928 5981 6148 6250 6422 6433 6448 6471 6473 6485 6503 6779 6812 7050 7064 7074 7141 7378 7424 7511 7574 7651 7808 7858 8286 8291 8446 8536 8599 8628 8636 8768 8900 8981 9042 9055 9114 9146 9186 9411 9480 9590 9681 9749 9757 9983",
"output": "10676"
},
{
"input": "100 50\n145 195 228 411 577 606 629 775 1040 1040 1058 1187 1307 1514 1784 1867 1891 2042 2042 2236 2549 2555 2560 2617 2766 2807 2829 2917 3070 3072 3078 3095 3138 3147 3149 3196 3285 3287 3309 3435 3531 3560 3563 3769 3830 3967 4081 4158 4315 4387 4590 4632 4897 4914 5128 5190 5224 5302 5402 5416 5420 5467 5517 5653 5820 5862 5941 6053 6082 6275 6292 6316 6490 6530 6619 6632 6895 7071 7234 7323 7334 7412 7626 7743 8098 8098 8136 8158 8264 8616 8701 8718 8770 8803 8809 8983 9422 9530 9811 9866",
"output": "10011"
},
{
"input": "100 50\n56 298 387 456 518 532 589 792 870 1041 1055 1122 1141 1166 1310 1329 1523 1548 1626 1730 1780 1833 1850 1911 2006 2157 2303 2377 2403 2442 2450 2522 2573 2822 2994 3200 3238 3252 3280 3311 3345 3422 3429 3506 3526 3617 3686 3791 4134 4467 4525 4614 4633 4792 5017 5220 5243 5338 5445 5536 5639 5675 5763 5875 6129 6220 6228 6287 6385 6616 6789 6822 6940 6959 6985 7297 7304 7391 7443 7580 7824 7884 7981 8055 8063 8223 8280 8322 8346 8473 8688 8986 9087 9323 9477 9489 9518 9621 9699 9804",
"output": "10009"
},
{
"input": "100 49990\n221 257 543 613 818 855 884 1195 1233 1293 1327 1474 1567 1568 1728 1789 1809 1957 1994 2198 2217 2289 2298 2360 2441 2454 2517 2519 2597 2652 2909 2958 2970 3271 3310 3409 3450 3646 3950 3965 4016 4116 4134 4159 4462 4624 4631 4783 4804 5031 5276 5538 5729 5845 5880 5894 5959 5961 6028 6105 6184 6335 6370 6523 6532 6677 6762 6868 6998 7066 7245 7360 7490 7492 7645 7677 7786 7804 8038 8131 8207 8400 8507 8556 8575 8599 8673 8676 8712 8816 9123 9158 9216 9369 9628 9707 9768 9800 9876 9934",
"output": "9934"
},
{
"input": "1 50000\n2",
"output": "2"
},
{
"input": "1 40000\n23456",
"output": "23456"
},
{
"input": "1 2\n10",
"output": "10"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n2 3",
"output": "3"
},
{
"input": "4 2\n1 2 8 9",
"output": "10"
}
] | 1,666,778,067 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 7,270,400 | n, k = map(int, input().split())
values = list(map(int, input().split()))
start ,end = 0, len(values) - 1
res = 0
while start <= end:
length = (end - start) + 1
if (length % k) or length == k:
res = max(res, values[end])
else:
res = max(res, values[start] + values[end])
start += 1
end -= 1
k -= 1
print(res)
| Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*.
Input Specification:
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order.
Output Specification:
Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*.
Demo Input:
['2 1\n2 5\n', '4 3\n2 3 5 9\n', '3 2\n3 5 7\n']
Demo Output:
['7\n', '9\n', '8\n']
Note:
In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | ```python
n, k = map(int, input().split())
values = list(map(int, input().split()))
start ,end = 0, len(values) - 1
res = 0
while start <= end:
length = (end - start) + 1
if (length % k) or length == k:
res = max(res, values[end])
else:
res = max(res, values[start] + values[end])
start += 1
end -= 1
k -= 1
print(res)
``` | 3 |
|
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability! | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
"output": "35"
},
{
"input": "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3 2 1 3 3 2 2 1 3 1 3 1 2 2 1 2 3 2",
"output": "0"
},
{
"input": "50\n5 5 5 5 4 2 2 3 2 2 4 1 5 5 1 2 4 2 4 2 5 2 2 2 2 3 2 4 2 5 5 4 3 1 2 3 3 5 4 2 2 5 2 4 5 5 4 4 1 5 5 3 2 2 5 1 3 3 2 4 4 5 1 2 3 4 4 1 3 3 3 5 1 2 4 4 4 4 2 5 2 5 3 2 4 5 5 2 1 1 2 4 5 3 2 1 2 4 4 4",
"output": "1"
},
{
"input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319 382 651 594 411 845 746 18 232 6 289 889 81 174 175 805 1000 799 950 475 713 951 685 729 925 262 447 139 217 788 514 658 572 784 185 112 636 10 251 621 218 210 89 597 553 430 532 264 11 160 476",
"output": "368"
},
{
"input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393 955 540 896 241 362 146 74 680 734 767 851 337 751 860 542 735 444 793 340 259 495 903 743 961 964 966 87 275 22 776 368 701 835 732 810 735 267 988 352 647 924 183 1 924 217 944 322 252 758 597",
"output": "393"
},
{
"input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52 69 591 181 573 258 381 665 301 589 379 362 146 790 842 765 100 229 916 938 97 340 793 758 177 736 396 247 562 571 92 923 861 165 748 345 703 431 930 101 761 862 595 505 393 126 846 431 103 596 21",
"output": "387"
},
{
"input": "50\n721 631 587 746 692 406 583 90 388 16 161 948 921 70 387 426 39 398 517 724 879 377 906 502 359 950 798 408 846 718 911 845 57 886 9 668 537 632 344 762 19 193 658 447 870 173 98 156 592 519 183 539 274 393 962 615 551 626 148 183 769 763 829 120 796 761 14 744 537 231 696 284 581 688 611 826 703 145 224 600 965 613 791 275 984 375 402 281 851 580 992 8 816 454 35 532 347 250 242 637",
"output": "376"
},
{
"input": "50\n849 475 37 120 754 183 758 374 543 198 896 691 11 607 198 343 761 660 239 669 628 259 223 182 216 158 20 565 454 884 137 923 156 22 310 77 267 707 582 169 120 308 439 309 59 152 206 696 210 177 296 887 559 22 154 553 142 247 491 692 473 572 461 206 532 319 503 164 328 365 541 366 300 392 486 257 863 432 877 404 520 69 418 99 519 239 374 927 601 103 226 316 423 219 240 26 455 101 184 61",
"output": "351"
},
{
"input": "3\n1 2 10 11 100 100",
"output": "1"
},
{
"input": "17\n814 744 145 886 751 1000 272 914 270 529 467 164 410 369 123 424 991 12 702 582 561 858 746 950 598 393 606 498 648 686 455 873 728 858",
"output": "318"
},
{
"input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 990 714 662 572 467 949 799 648 581 545 828 508 636",
"output": "355"
},
{
"input": "2\n55 5 25 51",
"output": "4"
},
{
"input": "25\n89 50 640 463 858 301 522 241 923 378 892 822 550 17 42 66 706 779 657 840 273 222 444 459 94 925 437 159 182 727 92 851 742 215 653 891 782 533 29 128 133 883 317 475 165 994 802 434 744 973",
"output": "348"
},
{
"input": "4\n35 48 71 44 78 79 57 48",
"output": "10"
},
{
"input": "3\n58 89 73 15 5 47",
"output": "21"
},
{
"input": "2\n1 20 99 100",
"output": "1"
}
] | 1,617,648,277 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | N = int(input(""))
ws = input("").split()
ws = [int(x) for x in ws]
ws.sort()
dif = []
for i in range(len(ws) - 1):
dif.append(ws[i + 1] - ws[i])
dif.sort()
ans = 0
for i in range(len(dif) - 2):
ans += dif[i]
print(ans)
| Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability!
Input Specification:
The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Output Specification:
Print minimum possible total instability.
Demo Input:
['2\n1 2 3 4\n', '4\n1 3 4 6 3 4 100 200\n']
Demo Output:
['1\n', '5\n']
Note:
none | ```python
N = int(input(""))
ws = input("").split()
ws = [int(x) for x in ws]
ws.sort()
dif = []
for i in range(len(ws) - 1):
dif.append(ws[i + 1] - ws[i])
dif.sort()
ans = 0
for i in range(len(dif) - 2):
ans += dif[i]
print(ans)
``` | 0 |
|
416 | C | Booking System | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"greedy",
"implementation"
] | null | null | Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i* and *p**i* — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.
We know that for each request, all *c**i* people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.
Unfortunately, there only are *k* tables in the restaurant. For each table, we know *r**i* — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.
Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.
The next line contains integer *k* (1<=≤<=*k*<=≤<=1000) — the number of tables in the restaurant. The last line contains *k* space-separated integers: *r*1,<=*r*2,<=...,<=*r**k* (1<=≤<=*r**i*<=≤<=1000) — the maximum number of people that can sit at each table. | In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.
If there are multiple optimal answers, print any of them. | [
"3\n10 50\n2 100\n5 30\n3\n4 6 9\n"
] | [
"2 130\n2 1\n3 2\n"
] | none | 1,500 | [
{
"input": "3\n10 50\n2 100\n5 30\n3\n4 6 9",
"output": "2 130\n2 1\n3 2"
},
{
"input": "1\n1 1\n1\n1",
"output": "1 1\n1 1"
},
{
"input": "1\n2 1\n1\n1",
"output": "0 0"
},
{
"input": "2\n10 10\n5 5\n1\n5",
"output": "1 5\n2 1"
},
{
"input": "2\n10 10\n5 5\n1\n10",
"output": "1 10\n1 1"
},
{
"input": "2\n2 100\n10 10\n1\n10",
"output": "1 100\n1 1"
},
{
"input": "2\n10 100\n5 90\n2\n15 20",
"output": "2 190\n1 1\n2 2"
},
{
"input": "3\n10 10\n3 5\n5 8\n3\n3 4 10",
"output": "2 15\n1 3\n2 1"
},
{
"input": "10\n739 307\n523 658\n700 143\n373 577\n120 433\n353 833\n665 516\n988 101\n817 604\n800 551\n10\n431 425 227 147 153 170 954 757 222 759",
"output": "6 3621\n6 2\n2 8\n9 7\n4 1\n7 10\n5 4"
},
{
"input": "9\n216 860\n299 720\n688 831\n555 733\n863 873\n594 923\n583 839\n738 824\n57 327\n10\n492 578 452 808 492 163 670 31 267 627",
"output": "7 5233\n6 10\n1 9\n7 7\n3 4\n4 2\n2 3\n9 6"
},
{
"input": "3\n694 606\n76 973\n676 110\n5\n592 737 313 903 13",
"output": "3 1689\n2 3\n1 2\n3 4"
},
{
"input": "7\n172 864\n853 523\n368 989\n920 452\n351 456\n269 104\n313 677\n9\n165 47 259 51 693 941 471 871 206",
"output": "5 3509\n3 7\n1 9\n7 5\n2 8\n5 6"
},
{
"input": "1\n545 609\n4\n584 822 973 652",
"output": "1 609\n1 1"
},
{
"input": "9\n23 163\n895 838\n344 444\n284 763\n942 39\n431 92\n147 515\n59 505\n940 999\n8\n382 497 297 125 624 212 851 859",
"output": "6 2482\n4 3\n7 6\n8 4\n3 1\n1 2\n6 5"
},
{
"input": "3\n500 613\n671 899\n628 131\n10\n622 467 479 982 886 968 326 64 228 321",
"output": "3 1643\n2 5\n1 1\n3 6"
},
{
"input": "7\n682 870\n640 857\n616 306\n649 777\n725 215\n402 977\n981 353\n1\n846",
"output": "1 977\n6 1"
},
{
"input": "1\n160 616\n5\n406 713 290 308 741",
"output": "1 616\n1 3"
},
{
"input": "6\n397 946\n871 126\n800 290\n505 429\n239 43\n320 292\n9\n387 925 9 440 395 320 58 707 994",
"output": "6 2126\n1 4\n4 8\n6 6\n3 2\n2 9\n5 1"
},
{
"input": "1\n3 20\n4\n3 2 1 4",
"output": "1 20\n1 1"
},
{
"input": "2\n2 100\n1 1000\n1\n2",
"output": "1 1000\n2 1"
}
] | 1,613,044,543 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | """
Created on Sat 11st feb 2021
@author: Rohit
"""
import math
arr= []
cap= []
w = int(input())
for _ in range(w):
o,p = map(int, input().split())
arr += [[p, o, _ + 1]]
h = int(input())
cap = list(map(int, input().split()))
capArr=[]
for _ in range(h):
capArr += [[cap[_], _ +1, -1]]
arr.sort(reverse = True)
capArr. sort()
ans=[]
#print(arr)
sum= 0
for itr in arr:
tar = itr[1]
for qr in capArr:
if qr[2] == -1 and qr[0] - tar > 0:
qr[2] = itr[2]
sum += itr[0]
ans += [qr]
break
print(len(ans), sum)
for itr in ans:
print(itr[2], itr[1])
| Title: Booking System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i* and *p**i* — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.
We know that for each request, all *c**i* people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.
Unfortunately, there only are *k* tables in the restaurant. For each table, we know *r**i* — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.
Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.
The next line contains integer *k* (1<=≤<=*k*<=≤<=1000) — the number of tables in the restaurant. The last line contains *k* space-separated integers: *r*1,<=*r*2,<=...,<=*r**k* (1<=≤<=*r**i*<=≤<=1000) — the maximum number of people that can sit at each table.
Output Specification:
In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.
If there are multiple optimal answers, print any of them.
Demo Input:
['3\n10 50\n2 100\n5 30\n3\n4 6 9\n']
Demo Output:
['2 130\n2 1\n3 2\n']
Note:
none | ```python
"""
Created on Sat 11st feb 2021
@author: Rohit
"""
import math
arr= []
cap= []
w = int(input())
for _ in range(w):
o,p = map(int, input().split())
arr += [[p, o, _ + 1]]
h = int(input())
cap = list(map(int, input().split()))
capArr=[]
for _ in range(h):
capArr += [[cap[_], _ +1, -1]]
arr.sort(reverse = True)
capArr. sort()
ans=[]
#print(arr)
sum= 0
for itr in arr:
tar = itr[1]
for qr in capArr:
if qr[2] == -1 and qr[0] - tar > 0:
qr[2] = itr[2]
sum += itr[0]
ans += [qr]
break
print(len(ans), sum)
for itr in ans:
print(itr[2], itr[1])
``` | 0 |
|
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation.
Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.
Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has. | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "0 0",
"output": "infinity"
},
{
"input": "121 0",
"output": "3"
},
{
"input": "772930485 686893955",
"output": "0"
},
{
"input": "257424 24",
"output": "127"
},
{
"input": "295138437 589952171",
"output": "0"
},
{
"input": "223093836 966",
"output": "399"
},
{
"input": "233758336 10665466",
"output": "13"
},
{
"input": "223092887 17",
"output": "500"
},
{
"input": "223094728 1858",
"output": "371"
},
{
"input": "223092899 29",
"output": "495"
},
{
"input": "997920 0",
"output": "240"
},
{
"input": "887043 3",
"output": "213"
},
{
"input": "124 24",
"output": "3"
},
{
"input": "982901 101",
"output": "193"
},
{
"input": "357987 35",
"output": "45"
},
{
"input": "954374 1030",
"output": "32"
},
{
"input": "49106 46",
"output": "15"
},
{
"input": "325508499 119510657",
"output": "1"
},
{
"input": "89768760 885778845",
"output": "0"
},
{
"input": "944387968 700818251",
"output": "0"
},
{
"input": "12 3",
"output": "1"
},
{
"input": "1000000000 1",
"output": "19"
},
{
"input": "923456789 3",
"output": "14"
},
{
"input": "1000000000 6",
"output": "6"
},
{
"input": "1000000000 333333300",
"output": "2"
},
{
"input": "5 2",
"output": "1"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "15 3",
"output": "3"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "77 75",
"output": "0"
},
{
"input": "1000000000 1000000000",
"output": "infinity"
}
] | 1,657,738,187 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 140 | 1,638,400 | queries = list(map(int, input().split()))
dividend = queries[0]
rest = queries[1]
res = 0
for i in range(1, dividend):
if dividend % i == rest:
res += 1
if dividend == rest:
print("infinity")
else:
print(res)
| Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation.
Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.
Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has.
Input Specification:
In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given.
Output Specification:
If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation .
Demo Input:
['21 5\n', '9435152 272\n', '10 10\n']
Demo Output:
['2\n', '282\n', 'infinity\n']
Note:
In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
queries = list(map(int, input().split()))
dividend = queries[0]
rest = queries[1]
res = 0
for i in range(1, dividend):
if dividend % i == rest:
res += 1
if dividend == rest:
print("infinity")
else:
print(res)
``` | 0 |
|
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,689,466,966 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | n, a, b = map(int,input().split())
lst = [i for i in range(n)]
while lst[-1] - lst[a] > b:
a += 1
pos = lst[-1] - lst[a] + 1
print(pos)
| Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
n, a, b = map(int,input().split())
lst = [i for i in range(n)]
while lst[-1] - lst[a] > b:
a += 1
pos = lst[-1] - lst[a] + 1
print(pos)
``` | 3 |
|
126 | A | Hot Bath | PROGRAMMING | 1,900 | [
"binary search",
"brute force",
"math"
] | null | null | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is *t*1, and the hot water's temperature is *t*2. The cold water tap can transmit any integer number of water units per second from 0 to *x*1, inclusive. Similarly, the hot water tap can transmit from 0 to *x*2 water units per second.
If *y*1 water units per second flow through the first tap and *y*2 water units per second flow through the second tap, then the resulting bath water temperature will be:
Bob wants to open both taps so that the bath water temperature was not less than *t*0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.
Determine how much each tap should be opened so that Bob was pleased with the result in the end. | You are given five integers *t*1, *t*2, *x*1, *x*2 and *t*0 (1<=≤<=*t*1<=≤<=*t*0<=≤<=*t*2<=≤<=106, 1<=≤<=*x*1,<=*x*2<=≤<=106). | Print two space-separated integers *y*1 and *y*2 (0<=≤<=*y*1<=≤<=*x*1, 0<=≤<=*y*2<=≤<=*x*2). | [
"10 70 100 100 25\n",
"300 500 1000 1000 300\n",
"143 456 110 117 273\n"
] | [
"99 33",
"1000 0",
"76 54"
] | In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible. | 500 | [
{
"input": "10 70 100 100 25",
"output": "99 33"
},
{
"input": "300 500 1000 1000 300",
"output": "1000 0"
},
{
"input": "143 456 110 117 273",
"output": "76 54"
},
{
"input": "10 20 5 5 13",
"output": "4 2"
},
{
"input": "1 3 1999 3444 2",
"output": "1999 1999"
},
{
"input": "100 110 2 2 109",
"output": "0 2"
},
{
"input": "3746 3797 485 485 3747",
"output": "450 9"
},
{
"input": "900000 1000000 50000 50000 960000",
"output": "33332 49998"
},
{
"input": "1 3 100 100 2",
"output": "100 100"
},
{
"input": "1 3 100 100 3",
"output": "0 100"
},
{
"input": "1 1 100 100 1",
"output": "100 100"
},
{
"input": "1 1 1 1 1",
"output": "1 1"
},
{
"input": "10 14 1 1 12",
"output": "1 1"
},
{
"input": "10 14 1 1 13",
"output": "0 1"
},
{
"input": "10 14 1 1 14",
"output": "0 1"
},
{
"input": "10 14 1 1 11",
"output": "1 1"
},
{
"input": "10 14 1 1 10",
"output": "1 0"
},
{
"input": "1 1000000 1000000 1000000 500000",
"output": "1000000 999998"
},
{
"input": "1 1000000 1000000 1000000 2",
"output": "999998 1"
},
{
"input": "1 1000000 1000000 1000000 999999",
"output": "1 999998"
},
{
"input": "3 9 9 2 5",
"output": "4 2"
},
{
"input": "7 9 481 961 9",
"output": "0 961"
},
{
"input": "5 10 6361 6643 9",
"output": "1660 6640"
},
{
"input": "3 10 202534 204124 7",
"output": "153093 204124"
},
{
"input": "4 7 990105 993245 7",
"output": "0 993245"
},
{
"input": "167 6430 3 2 4879",
"output": "0 2"
},
{
"input": "59039 78548 8 5 68239",
"output": "5 5"
},
{
"input": "99065 826220 9 3 659285",
"output": "0 3"
},
{
"input": "973058 995844 1 10 973658",
"output": "1 1"
},
{
"input": "983534 987908 2 7 984750",
"output": "2 1"
},
{
"input": "127873 889327 5550 623544 491743",
"output": "4953 4533"
},
{
"input": "146692 953585 99505 406219 259334",
"output": "92031 14932"
},
{
"input": "61097 812001 384947 188893 662044",
"output": "41007 164334"
},
{
"input": "581106 975502 703094 487920 637713",
"output": "675578 113214"
},
{
"input": "663155 979777 797049 494787 951112",
"output": "28665 287957"
},
{
"input": "129630 805489 631548 761110 577559",
"output": "227930 447929"
},
{
"input": "499637 716156 949694 543785 663905",
"output": "156753 492804"
},
{
"input": "522321 902347 10945 842811 630561",
"output": "9052 3605"
},
{
"input": "285510 831681 329092 849678 821409",
"output": "13696 714532"
},
{
"input": "176902 815637 847541 412251 587604",
"output": "228033 410702"
},
{
"input": "690136 947897 137581 128882 932136",
"output": "6612 101523"
},
{
"input": "122316 918901 393457 621754 907250",
"output": "9025 608019"
},
{
"input": "345903 808776 240052 245730 365687",
"output": "231914 10355"
},
{
"input": "483180 855922 224311 233776 855647",
"output": "141 190974"
},
{
"input": "353408 572330 154358 165573 557017",
"output": "11080 147325"
},
{
"input": "632076 716031 914 915 662639",
"output": "856 490"
},
{
"input": "668704 747356 945 949 696258",
"output": "790 426"
},
{
"input": "463050 509065 994 994 489428",
"output": "737 990"
},
{
"input": "77909 251377 937 952 115397",
"output": "798 220"
},
{
"input": "13612 793764 96 76 398584",
"output": "78 76"
},
{
"input": "1 5 3 5 5",
"output": "0 5"
},
{
"input": "99 99 99 99 99",
"output": "99 99"
},
{
"input": "100 100 100 100 100",
"output": "100 100"
},
{
"input": "1000000 1000000 1000000 1000000 1000000",
"output": "1000000 1000000"
},
{
"input": "1000000 1000000 999999 999998 1000000",
"output": "999999 999998"
},
{
"input": "5 5 5 5 5",
"output": "5 5"
},
{
"input": "10 10 100 100 10",
"output": "100 100"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "1000 1000"
},
{
"input": "10 10 5 5 10",
"output": "5 5"
},
{
"input": "1 2 100 100 2",
"output": "0 100"
},
{
"input": "100 100 1000 1000 100",
"output": "1000 1000"
},
{
"input": "1000 1000000 1000000 1000000 1000000",
"output": "0 1000000"
},
{
"input": "50 100 100 100 100",
"output": "0 100"
},
{
"input": "10 10 20 20 10",
"output": "20 20"
},
{
"input": "1 100000 1000 1 2",
"output": "1000 1"
},
{
"input": "1000 1000000 100000 1000000 1000000",
"output": "0 1000000"
},
{
"input": "1 10 10 10 10",
"output": "0 10"
},
{
"input": "1000000 1000000 50 50 1000000",
"output": "50 50"
},
{
"input": "300 300 1000 1000 300",
"output": "1000 1000"
},
{
"input": "5 5 123 1234 5",
"output": "123 1234"
}
] | 1,691,742,394 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1691742394.4336")# 1691742394.4336188 | Title: Hot Bath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is *t*1, and the hot water's temperature is *t*2. The cold water tap can transmit any integer number of water units per second from 0 to *x*1, inclusive. Similarly, the hot water tap can transmit from 0 to *x*2 water units per second.
If *y*1 water units per second flow through the first tap and *y*2 water units per second flow through the second tap, then the resulting bath water temperature will be:
Bob wants to open both taps so that the bath water temperature was not less than *t*0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.
Determine how much each tap should be opened so that Bob was pleased with the result in the end.
Input Specification:
You are given five integers *t*1, *t*2, *x*1, *x*2 and *t*0 (1<=≤<=*t*1<=≤<=*t*0<=≤<=*t*2<=≤<=106, 1<=≤<=*x*1,<=*x*2<=≤<=106).
Output Specification:
Print two space-separated integers *y*1 and *y*2 (0<=≤<=*y*1<=≤<=*x*1, 0<=≤<=*y*2<=≤<=*x*2).
Demo Input:
['10 70 100 100 25\n', '300 500 1000 1000 300\n', '143 456 110 117 273\n']
Demo Output:
['99 33', '1000 0', '76 54']
Note:
In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible. | ```python
print("_RANDOM_GUESS_1691742394.4336")# 1691742394.4336188
``` | 0 |
|
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
},
{
"input": "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 972 677 973 527 984 559 280 346 580 30 372 547 209 929 492 520 446 726 47 170 699 560 814 206 688 955 308 287 26 102 77 430 262 71 415 586 532 562 419 615 732 658 108 315 268 574 86 12 23 429 640 995 342 305",
"output": "1000"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "30\n94 93 90 94 90 91 93 91 93 94 93 90 100 94 97 94 94 95 94 96 94 98 97 95 97 91 91 95 98 96",
"output": "100"
},
{
"input": "5\n1000000000 5 5 4 4",
"output": "1000000000"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "4"
},
{
"input": "3\n1000000000 1000000000 10000000",
"output": "1005000000"
},
{
"input": "3\n677876423 834056477 553175531",
"output": "1032554216"
},
{
"input": "5\n1000000000 1 1 1 1",
"output": "1000000000"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1333333334"
},
{
"input": "3\n4 10 11",
"output": "13"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1250000000"
}
] | 1,564,065,102 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 216 | 0 | import math
n=int(input())
a=list(map(int,input().split()))
m=sum(a)
r=math.ceil(m/(n-1))
print(int(r))
| Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
Output Specification:
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['3\n3 2 2\n', '4\n2 2 2 2\n']
Demo Output:
['4\n', '3\n']
Note:
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | ```python
import math
n=int(input())
a=list(map(int,input().split()))
m=sum(a)
r=math.ceil(m/(n-1))
print(int(r))
``` | 0 |
|
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor *i* goes to work on the *s**i*-th day and works every *d**i* day. So, he works on days *s**i*,<=*s**i*<=+<=*d**i*,<=*s**i*<=+<=2*d**i*,<=....
The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? | First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). | Output a single integer — the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
{
"input": "6\n1 3\n2 5\n4 7\n7 5\n6 8\n8 8",
"output": "16"
},
{
"input": "10\n4 10\n8 7\n6 5\n2 1\n2 3\n8 8\n2 4\n2 2\n6 7\n7 9",
"output": "34"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "1\n1000 1000",
"output": "1000"
},
{
"input": "42\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "83"
},
{
"input": "2\n5 5\n5 1",
"output": "6"
},
{
"input": "2\n5 5\n5 5",
"output": "10"
},
{
"input": "2\n1 1\n1 1",
"output": "2"
},
{
"input": "2\n1 6\n7 1",
"output": "7"
},
{
"input": "2\n4 3\n4 5",
"output": "9"
},
{
"input": "2\n1 2\n1 3",
"output": "4"
},
{
"input": "3\n2 3\n5 1\n2 1",
"output": "6"
},
{
"input": "2\n2 1\n6 3",
"output": "6"
},
{
"input": "3\n10 1\n4 4\n12 1",
"output": "13"
},
{
"input": "2\n2 2\n10 2",
"output": "10"
},
{
"input": "2\n1 1\n1000 2",
"output": "1000"
},
{
"input": "14\n1000 1\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1",
"output": "13001"
},
{
"input": "2\n2 4\n2 1",
"output": "3"
},
{
"input": "3\n1 100\n100 3\n200 1",
"output": "200"
},
{
"input": "7\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1",
"output": "6001"
},
{
"input": "2\n5 5\n15 5",
"output": "15"
},
{
"input": "2\n2 2\n2 4",
"output": "6"
},
{
"input": "2\n1 1\n10 1",
"output": "10"
},
{
"input": "2\n10 1\n100 1",
"output": "100"
},
{
"input": "15\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1",
"output": "14001"
},
{
"input": "3\n2 1\n1 3\n4 7",
"output": "11"
},
{
"input": "2\n5 5\n100 5",
"output": "100"
},
{
"input": "2\n1 10\n2 30",
"output": "2"
},
{
"input": "4\n2 2\n2 2\n2 2\n2 2",
"output": "8"
},
{
"input": "1\n10 10",
"output": "10"
}
] | 1,574,683,214 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 358 | 2,969,600 | n ,Day = int(input()), 0
for i in range(n):
x ,y = map(int, input().split())
if i==0:
Day = x
continue
while(Day>=x):x+=y
Day = x
print(Day) | Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor *i* goes to work on the *s**i*-th day and works every *d**i* day. So, he works on days *s**i*,<=*s**i*<=+<=*d**i*,<=*s**i*<=+<=2*d**i*,<=....
The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?
Input Specification:
First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000).
Output Specification:
Output a single integer — the minimum day at which Borya can visit the last doctor.
Demo Input:
['3\n2 2\n1 2\n2 2\n', '2\n10 1\n6 5\n']
Demo Output:
['4\n', '11\n']
Note:
In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | ```python
n ,Day = int(input()), 0
for i in range(n):
x ,y = map(int, input().split())
if i==0:
Day = x
continue
while(Day>=x):x+=y
Day = x
print(Day)
``` | 3 |
|
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1).
Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside.
What is the minimal length of the quadcopter path? | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter starting point and the flag do not coincide. | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "100 -100\n-100 -100",
"output": "406"
},
{
"input": "100 -100\n-100 100",
"output": "804"
},
{
"input": "100 -100\n100 100",
"output": "406"
},
{
"input": "-100 100\n-100 -100",
"output": "406"
},
{
"input": "-100 100\n100 -100",
"output": "804"
},
{
"input": "-100 100\n100 100",
"output": "406"
},
{
"input": "100 100\n-100 -100",
"output": "804"
},
{
"input": "100 100\n-100 100",
"output": "406"
},
{
"input": "100 100\n100 -100",
"output": "406"
},
{
"input": "45 -43\n45 -44",
"output": "8"
},
{
"input": "76 76\n75 75",
"output": "8"
},
{
"input": "-34 -56\n-35 -56",
"output": "8"
},
{
"input": "56 -7\n55 -6",
"output": "8"
},
{
"input": "43 -11\n43 -10",
"output": "8"
},
{
"input": "1 -3\n2 -2",
"output": "8"
},
{
"input": "55 71\n56 71",
"output": "8"
},
{
"input": "54 -87\n55 -88",
"output": "8"
},
{
"input": "22 98\n100 33",
"output": "290"
},
{
"input": "37 84\n-83 5",
"output": "402"
},
{
"input": "52 74\n-73 -39",
"output": "480"
},
{
"input": "66 51\n51 -71",
"output": "278"
},
{
"input": "-31 44\n73 86",
"output": "296"
},
{
"input": "-20 34\n-9 55",
"output": "68"
},
{
"input": "-5 19\n-91 -86",
"output": "386"
},
{
"input": "-82 5\n28 -17",
"output": "268"
},
{
"input": "-90 -100\n55 48",
"output": "590"
},
{
"input": "-75 -14\n-32 8",
"output": "134"
},
{
"input": "-53 -28\n-13 -28",
"output": "86"
},
{
"input": "-42 -46\n10 -64",
"output": "144"
},
{
"input": "55 -42\n25 2",
"output": "152"
},
{
"input": "70 -64\n-54 70",
"output": "520"
},
{
"input": "93 -78\n-32 -75",
"output": "260"
},
{
"input": "8 -93\n79 -6",
"output": "320"
},
{
"input": "50 43\n54 10",
"output": "78"
},
{
"input": "65 32\n-37 71",
"output": "286"
},
{
"input": "80 18\n-15 -58",
"output": "346"
},
{
"input": "94 92\n4 -1",
"output": "370"
},
{
"input": "-10 96\n27 64",
"output": "142"
},
{
"input": "-96 78\n-56 32",
"output": "176"
},
{
"input": "-81 64\n-37 -8",
"output": "236"
},
{
"input": "-58 49\n74 -40",
"output": "446"
},
{
"input": "-62 -55\n1 18",
"output": "276"
},
{
"input": "-51 -69\n-78 86",
"output": "368"
},
{
"input": "-29 -80\n-56 -47",
"output": "124"
},
{
"input": "-14 -94\n55 -90",
"output": "150"
},
{
"input": "83 -2\n82 83",
"output": "176"
},
{
"input": "98 -16\n-96 40",
"output": "504"
},
{
"input": "17 -34\n-86 -93",
"output": "328"
},
{
"input": "32 -48\n33 -37",
"output": "28"
},
{
"input": "74 87\n3 92",
"output": "156"
},
{
"input": "89 73\n-80 49",
"output": "390"
},
{
"input": "4 58\n-61 -80",
"output": "410"
},
{
"input": "15 48\n50 -20",
"output": "210"
},
{
"input": "-82 45\n81 46",
"output": "332"
},
{
"input": "-68 26\n-2 6",
"output": "176"
},
{
"input": "-53 4\n-92 -31",
"output": "152"
},
{
"input": "-30 94\n31 -58",
"output": "430"
},
{
"input": "-38 -11\n58 99",
"output": "416"
},
{
"input": "-27 -25\n-28 68",
"output": "192"
},
{
"input": "-5 -39\n-10 -77",
"output": "90"
},
{
"input": "-90 -54\n9 -9",
"output": "292"
},
{
"input": "7 -57\n28 61",
"output": "282"
},
{
"input": "18 -67\n-51 21",
"output": "318"
},
{
"input": "41 -82\n-33 -15",
"output": "286"
},
{
"input": "56 -8\n91 -55",
"output": "168"
},
{
"input": "-23 -13\n-24 -12",
"output": "8"
},
{
"input": "1 32\n1 33",
"output": "8"
},
{
"input": "25 76\n24 76",
"output": "8"
},
{
"input": "-29 -78\n-28 -79",
"output": "8"
},
{
"input": "-77 19\n-76 19",
"output": "8"
},
{
"input": "-53 63\n-53 62",
"output": "8"
},
{
"input": "86 12\n86 11",
"output": "8"
},
{
"input": "14 56\n13 56",
"output": "8"
},
{
"input": "63 41\n62 40",
"output": "8"
},
{
"input": "0 -4\n1 -4",
"output": "8"
},
{
"input": "24 41\n24 42",
"output": "8"
},
{
"input": "48 85\n49 86",
"output": "8"
},
{
"input": "0 0\n0 1",
"output": "8"
},
{
"input": "0 0\n1 0",
"output": "8"
},
{
"input": "0 0\n1 1",
"output": "8"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "0 1\n1 0",
"output": "8"
},
{
"input": "0 1\n1 1",
"output": "8"
},
{
"input": "1 0\n0 0",
"output": "8"
},
{
"input": "1 0\n0 1",
"output": "8"
},
{
"input": "1 0\n1 1",
"output": "8"
},
{
"input": "1 1\n0 0",
"output": "8"
},
{
"input": "1 1\n0 1",
"output": "8"
},
{
"input": "1 1\n1 0",
"output": "8"
},
{
"input": "100 100\n99 -100",
"output": "406"
},
{
"input": "100 100\n-100 99",
"output": "406"
},
{
"input": "-100 -100\n-99 100",
"output": "406"
},
{
"input": "-100 -100\n100 -99",
"output": "406"
},
{
"input": "0 0\n1 2",
"output": "10"
},
{
"input": "0 0\n2 1",
"output": "10"
}
] | 1,508,574,265 | 1,165 | PyPy 3 | OK | TESTS1 | 42 | 93 | 23,142,400 | x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
print(2*(max(abs(x1-x2)+1,2)+max(abs(y1-y2)+1,2))) | Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1).
Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside.
What is the minimal length of the quadcopter path?
Input Specification:
The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter starting point and the flag do not coincide.
Output Specification:
Print the length of minimal path of the quadcopter to surround the flag and return back.
Demo Input:
['1 5\n5 2\n', '0 1\n0 0\n']
Demo Output:
['18\n', '8\n']
Note:
none | ```python
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
print(2*(max(abs(x1-x2)+1,2)+max(abs(y1-y2)+1,2)))
``` | 3 |
|
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,679,455,237 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | n = int(input())
data = input().split()
#disregard starting zeroes:
i = 0
while i < n and data[i] == '0':
i+=1
#disregard trailing zeroes:
j = n - 1
while j > 0 and data[j] == '0':
j -=1
#count occurrences of groups of zeros:
ones = 0
count = 0
while i <= j:
if data[i] =='1':
i +=1
ones += 1
else:
zeros = 0
while i <= j and data[i] == '0':
zeros += 1
i +=1
if zeros > 1:
count += 1
else: ones += 1
print(count + ones)
| 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())
data = input().split()
#disregard starting zeroes:
i = 0
while i < n and data[i] == '0':
i+=1
#disregard trailing zeroes:
j = n - 1
while j > 0 and data[j] == '0':
j -=1
#count occurrences of groups of zeros:
ones = 0
count = 0
while i <= j:
if data[i] =='1':
i +=1
ones += 1
else:
zeros = 0
while i <= j and data[i] == '0':
zeros += 1
i +=1
if zeros > 1:
count += 1
else: ones += 1
print(count + ones)
``` | 3 |
|
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of *k* electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) — number *a**i* stands for the number of sockets on the *i*-th supply-line filter. | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter. | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2\n5 3 4 1 2 1 2",
"output": "5"
},
{
"input": "7 17 5\n1 6 2 1 1 4 3",
"output": "-1"
},
{
"input": "10 25 7\n5 7 4 8 3 3 5 4 5 5",
"output": "4"
},
{
"input": "10 8 4\n1 1 2 1 3 1 3 1 4 2",
"output": "2"
},
{
"input": "13 20 9\n2 9 2 2 5 11 10 10 13 4 6 11 14",
"output": "1"
},
{
"input": "9 30 8\n3 6 10 8 1 5 3 9 3",
"output": "3"
},
{
"input": "15 26 4\n3 6 7 1 5 2 4 4 7 3 8 7 2 4 8",
"output": "4"
},
{
"input": "20 20 3\n6 6 5 1 7 8 8 6 10 7 8 5 6 8 1 7 10 6 2 7",
"output": "2"
},
{
"input": "10 30 5\n4 5 3 3 4 4 4 3 5 1",
"output": "9"
},
{
"input": "20 30 1\n12 19 16 2 11 19 1 15 13 13 3 10 1 18 7 5 6 8 9 1",
"output": "2"
},
{
"input": "50 50 2\n2 2 4 5 2 1 5 4 5 4 5 2 1 2 3 3 5 1 2 2 1 3 4 5 5 4 3 2 2 1 3 2 3 2 4 4 1 3 5 4 3 2 4 3 4 4 4 4 3 4",
"output": "14"
},
{
"input": "5 50 6\n2 1 3 1 3",
"output": "-1"
},
{
"input": "20 50 10\n5 4 3 6 3 7 2 3 7 8 6 3 8 3 3 5 1 9 6 2",
"output": "7"
},
{
"input": "40 40 3\n2 1 4 2 4 2 3 3 3 3 1 2 3 2 2 3 4 2 3 1 2 4 1 4 1 4 3 3 1 1 3 1 3 4 4 3 1 1 2 4",
"output": "14"
},
{
"input": "33 49 16\n40 16 48 49 30 28 8 6 48 39 48 6 24 28 30 35 12 23 49 29 31 8 40 18 16 34 43 15 12 33 14 24 13",
"output": "1"
},
{
"input": "10 49 11\n5 18 1 19 11 11 16 5 6 6",
"output": "3"
},
{
"input": "50 30 1\n2 1 2 1 2 3 3 1 2 2 3 2 1 3 1 3 1 2 2 3 2 1 3 1 1 2 3 2 2 1 1 3 3 2 2 2 3 2 3 3 3 3 1 1 3 1 1 3 1 3",
"output": "15"
},
{
"input": "50 50 2\n1 2 3 2 1 2 4 2 3 4 3 1 3 2 2 3 1 4 2 1 4 4 2 2 2 3 2 3 1 1 4 4 1 1 2 3 4 2 2 3 4 3 4 3 3 3 2 3 1 1",
"output": "19"
},
{
"input": "49 49 3\n8 8 8 7 5 6 6 8 1 3 1 8 8 3 2 1 2 2 5 4 4 7 8 7 6 4 2 5 7 3 4 2 3 2 3 4 5 7 3 3 4 5 5 8 2 5 1 1 7",
"output": "7"
},
{
"input": "4 50 1\n3 11 5 5",
"output": "-1"
},
{
"input": "50 5 1\n1 1 1 1 1 1 1 2 1 1 2 2 2 2 1 2 1 2 1 2 2 1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 1 1 2 1 2",
"output": "4"
},
{
"input": "50 23 2\n2 1 2 2 3 2 1 2 3 3 3 1 3 1 3 2 1 3 2 2 1 1 3 2 2 1 1 3 2 1 2 3 2 2 2 2 1 3 1 2 2 3 3 1 3 3 3 1 2 3",
"output": "11"
},
{
"input": "49 19 2\n3 2 3 2 3 3 2 3 3 1 2 1 2 3 2 3 1 3 1 3 1 3 2 2 2 2 3 3 1 1 2 3 2 3 1 2 3 3 1 1 3 1 1 3 1 1 1 2 3",
"output": "9"
},
{
"input": "10 50 5\n23 18 15 23 26 23 4 29 15 25",
"output": "2"
},
{
"input": "15 38 3\n3 5 5 5 4 1 3 1 5 4 2 4 3 1 1",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "3 6 3\n2 2 2",
"output": "3"
},
{
"input": "1 7 4\n1",
"output": "-1"
},
{
"input": "47 7 4\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",
"output": "-1"
}
] | 1,603,735,607 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 16 | 996 | 11,468,800 | import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
if __name__ == '__main__':
n, m, k = list(map(int, input().strip().split()))
a, b, i = list(map(int, input().strip().split())), 0, 0
a.sort(reverse=True)
if m <= k:
print(b)
else:
while i < len(a):
if m <= k:
break
if k > 0:
k -= 1
elif m > 0:
m += 1
m -= a[i]
b += 1
i += 1
print("-1" if (m > 0 and k == 0) else "{}".format(b))
| Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of *k* electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) — number *a**i* stands for the number of sockets on the *i*-th supply-line filter.
Output Specification:
Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Demo Input:
['3 5 3\n3 1 2\n', '4 7 2\n3 3 2 4\n', '5 5 1\n1 3 1 2 1\n']
Demo Output:
['1\n', '2\n', '-1\n']
Note:
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter. | ```python
import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
if __name__ == '__main__':
n, m, k = list(map(int, input().strip().split()))
a, b, i = list(map(int, input().strip().split())), 0, 0
a.sort(reverse=True)
if m <= k:
print(b)
else:
while i < len(a):
if m <= k:
break
if k > 0:
k -= 1
elif m > 0:
m += 1
m -= a[i]
b += 1
i += 1
print("-1" if (m > 0 and k == 0) else "{}".format(b))
``` | 0 |
|
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "499999999"
},
{
"input": "1924704072",
"output": "481176017"
},
{
"input": "73740586",
"output": "18435146"
},
{
"input": "1925088820",
"output": "481272204"
},
{
"input": "593070992",
"output": "148267747"
},
{
"input": "1925473570",
"output": "481368392"
},
{
"input": "629490186",
"output": "157372546"
},
{
"input": "1980649112",
"output": "495162277"
},
{
"input": "36661322",
"output": "9165330"
},
{
"input": "1943590793",
"output": "0"
},
{
"input": "71207034",
"output": "17801758"
},
{
"input": "1757577394",
"output": "439394348"
},
{
"input": "168305294",
"output": "42076323"
},
{
"input": "1934896224",
"output": "483724055"
},
{
"input": "297149088",
"output": "74287271"
},
{
"input": "1898001634",
"output": "474500408"
},
{
"input": "176409698",
"output": "44102424"
},
{
"input": "1873025522",
"output": "468256380"
},
{
"input": "5714762",
"output": "1428690"
},
{
"input": "1829551192",
"output": "457387797"
},
{
"input": "16269438",
"output": "4067359"
},
{
"input": "1663283390",
"output": "415820847"
},
{
"input": "42549941",
"output": "0"
},
{
"input": "1967345604",
"output": "491836400"
},
{
"input": "854000",
"output": "213499"
},
{
"input": "1995886626",
"output": "498971656"
},
{
"input": "10330019",
"output": "0"
},
{
"input": "1996193634",
"output": "499048408"
},
{
"input": "9605180",
"output": "2401294"
},
{
"input": "1996459740",
"output": "499114934"
},
{
"input": "32691948",
"output": "8172986"
},
{
"input": "1975903308",
"output": "493975826"
},
{
"input": "1976637136",
"output": "494159283"
},
{
"input": "29803038",
"output": "7450759"
},
{
"input": "1977979692",
"output": "494494922"
},
{
"input": "1978595336",
"output": "494648833"
},
{
"input": "27379344",
"output": "6844835"
},
{
"input": "1979729912",
"output": "494932477"
},
{
"input": "1980253780",
"output": "495063444"
},
{
"input": "1980751584",
"output": "495187895"
},
{
"input": "53224878",
"output": "13306219"
},
{
"input": "5",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "2"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "0"
},
{
"input": "14",
"output": "3"
},
{
"input": "15",
"output": "0"
},
{
"input": "16",
"output": "3"
},
{
"input": "17",
"output": "0"
},
{
"input": "18",
"output": "4"
},
{
"input": "19",
"output": "0"
},
{
"input": "21",
"output": "0"
},
{
"input": "22",
"output": "5"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "26",
"output": "6"
},
{
"input": "27",
"output": "0"
},
{
"input": "28",
"output": "6"
},
{
"input": "29",
"output": "0"
},
{
"input": "30",
"output": "7"
},
{
"input": "111",
"output": "0"
},
{
"input": "55",
"output": "0"
},
{
"input": "105",
"output": "0"
},
{
"input": "199",
"output": "0"
},
{
"input": "151",
"output": "0"
}
] | 1,665,842,568 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 46 | 0 | n = int(input())
print([((n//2)-1)//2,0][n%2==1]) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
Output Specification:
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Demo Input:
['6\n', '20\n']
Demo Output:
['1\n', '4\n']
Note:
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | ```python
n = int(input())
print([((n//2)-1)//2,0][n%2==1])
``` | 3 |
|
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*? | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3. | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "84"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "27"
},
{
"input": "1 10\n25",
"output": "0"
},
{
"input": "70 80\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",
"output": "0"
},
{
"input": "3 1\n25 26 27",
"output": "1"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56",
"output": "34"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81",
"output": "70"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "96"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "0"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35",
"output": "13"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "93"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "89"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15",
"output": "1"
},
{
"input": "100 56\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "43"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14",
"output": "50"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27",
"output": "89"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "1 100\n22",
"output": "0"
},
{
"input": "1 0\n22",
"output": "0"
},
{
"input": "1 99\n99",
"output": "0"
},
{
"input": "1 5\n6",
"output": "0"
},
{
"input": "3 1\n10 20 30",
"output": "2"
},
{
"input": "3 0\n1 2 3",
"output": "2"
},
{
"input": "3 2\n1 50 99",
"output": "2"
},
{
"input": "7 4\n1 3 4 9 10 11 12",
"output": "3"
},
{
"input": "2 5\n67 23",
"output": "1"
},
{
"input": "4 2\n1 4 7 9",
"output": "2"
},
{
"input": "2 0\n1 2",
"output": "1"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5",
"output": "3"
},
{
"input": "5 1\n3 5 5 5 6",
"output": "1"
}
] | 1,520,027,159 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 5,632,000 | n,d=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
i=0
while l[len(l)-1]-l[0]>d:
if l[len(l)-2]-l[0]<l[len(l)-1]-l[1]:
l.pop()
elif l[len(l)-2]-l[0]==l[len(l)-1]-l[1]:
if min(l[len(l)-3]-l[0],l[len(l)-2]-l[1])< min(l[len(l)-2]-l[0],l[len(l)-2]-l[1]):
l.pop()
else:
l.pop(0)
else:
l.pop(0)
i=i+1
print(i)
| Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output Specification:
Output a single integer — the minimum number of points you have to remove.
Demo Input:
['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3. | ```python
n,d=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
i=0
while l[len(l)-1]-l[0]>d:
if l[len(l)-2]-l[0]<l[len(l)-1]-l[1]:
l.pop()
elif l[len(l)-2]-l[0]==l[len(l)-1]-l[1]:
if min(l[len(l)-3]-l[0],l[len(l)-2]-l[1])< min(l[len(l)-2]-l[0],l[len(l)-2]-l[1]):
l.pop()
else:
l.pop(0)
else:
l.pop(0)
i=i+1
print(i)
``` | 0 |
|
834 | A | The Useless Toy | PROGRAMMING | 900 | [
"implementation"
] | null | null | Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this. | There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position. | Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. | [
"^ >\n1\n",
"< ^\n3\n",
"^ v\n6\n"
] | [
"cw\n",
"ccw\n",
"undefined\n"
] | none | 500 | [
{
"input": "^ >\n1",
"output": "cw"
},
{
"input": "< ^\n3",
"output": "ccw"
},
{
"input": "^ v\n6",
"output": "undefined"
},
{
"input": "^ >\n999999999",
"output": "ccw"
},
{
"input": "> v\n1",
"output": "cw"
},
{
"input": "v <\n1",
"output": "cw"
},
{
"input": "< ^\n1",
"output": "cw"
},
{
"input": "v <\n422435957",
"output": "cw"
},
{
"input": "v >\n139018901",
"output": "ccw"
},
{
"input": "v ^\n571728018",
"output": "undefined"
},
{
"input": "^ ^\n0",
"output": "undefined"
},
{
"input": "< >\n2",
"output": "undefined"
},
{
"input": "> >\n1000000000",
"output": "undefined"
},
{
"input": "v v\n8",
"output": "undefined"
},
{
"input": "< <\n1568",
"output": "undefined"
},
{
"input": "^ v\n2",
"output": "undefined"
},
{
"input": "^ <\n1",
"output": "ccw"
},
{
"input": "< v\n1",
"output": "ccw"
},
{
"input": "v >\n1",
"output": "ccw"
},
{
"input": "> ^\n1",
"output": "ccw"
},
{
"input": "v <\n422435957",
"output": "cw"
},
{
"input": "v v\n927162384",
"output": "undefined"
},
{
"input": "v ^\n571728018",
"output": "undefined"
},
{
"input": "^ <\n467441155",
"output": "cw"
},
{
"input": "^ >\n822875521",
"output": "cw"
},
{
"input": "^ <\n821690113",
"output": "ccw"
},
{
"input": "^ <\n171288453",
"output": "ccw"
},
{
"input": "^ <\n110821381",
"output": "ccw"
},
{
"input": "^ ^\n539580280",
"output": "undefined"
},
{
"input": "^ >\n861895563",
"output": "ccw"
},
{
"input": "v v\n4",
"output": "undefined"
},
{
"input": "^ ^\n4",
"output": "undefined"
},
{
"input": "> >\n4",
"output": "undefined"
},
{
"input": "< <\n8",
"output": "undefined"
},
{
"input": "v v\n0",
"output": "undefined"
},
{
"input": "^ <\n11",
"output": "cw"
},
{
"input": "< <\n4",
"output": "undefined"
},
{
"input": "< <\n0",
"output": "undefined"
},
{
"input": "< v\n3",
"output": "cw"
},
{
"input": "^ <\n3",
"output": "cw"
},
{
"input": "^ <\n7",
"output": "cw"
},
{
"input": "< >\n6",
"output": "undefined"
},
{
"input": "v >\n3",
"output": "cw"
},
{
"input": "> >\n300",
"output": "undefined"
},
{
"input": "> >\n0",
"output": "undefined"
},
{
"input": "v <\n3",
"output": "ccw"
},
{
"input": "> >\n12",
"output": "undefined"
}
] | 1,501,700,444 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 |
def op(x):
if x == 'v':
return 1
elif x == '<':
return 2
elif x == '^':
return 3
else:
return 4
#n = int(input())
#n, m = map(int, input().split())
s = input()
#c = list(map(int, input().split()))
n = int(input())
l = op(s[1]) - op(s[0])
k == n % 4
if k == 2:
print('undefined')
elif l == k:
print('cw')
else:
print('ccw') | Title: The Useless Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input Specification:
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
Output Specification:
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
Demo Input:
['^ >\n1\n', '< ^\n3\n', '^ v\n6\n']
Demo Output:
['cw\n', 'ccw\n', 'undefined\n']
Note:
none | ```python
def op(x):
if x == 'v':
return 1
elif x == '<':
return 2
elif x == '^':
return 3
else:
return 4
#n = int(input())
#n, m = map(int, input().split())
s = input()
#c = list(map(int, input().split()))
n = int(input())
l = op(s[1]) - op(s[0])
k == n % 4
if k == 2:
print('undefined')
elif l == k:
print('cw')
else:
print('ccw')
``` | -1 |
|
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": "Anton"
},
{
"input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD",
"output": "Friendship"
},
{
"input": "1\nA",
"output": "Anton"
},
{
"input": "1\nD",
"output": "Danik"
},
{
"input": "2\nDA",
"output": "Friendship"
},
{
"input": "4\nDADA",
"output": "Friendship"
},
{
"input": "4\nDAAD",
"output": "Friendship"
},
{
"input": "3\nADD",
"output": "Danik"
},
{
"input": "3\nDAD",
"output": "Danik"
},
{
"input": "2\nDA",
"output": "Friendship"
},
{
"input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA",
"output": "Anton"
}
] | 1,693,399,049 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 921,600 | n = int(input())
s = list(input())
d_c = s.count('D')
d_a = s.count('A')
if d_c > d_a:
print('Danik')
elif d_c < d_a:
print('Anton')
else:
print('Friendship') | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
Output Specification:
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes).
Demo Input:
['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n']
Demo Output:
['Anton\n', 'Danik\n', 'Friendship\n']
Note:
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | ```python
n = int(input())
s = list(input())
d_c = s.count('D')
d_a = s.count('A')
if d_c > d_a:
print('Danik')
elif d_c < d_a:
print('Anton')
else:
print('Friendship')
``` | 3 |
|
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 1,680,031,169 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 8,089,600 | num = int(input())
lst = list(map(int, input().split()))
mx = max(lst)
men = min(lst)
lst.remove(mx)
lst.remove(men)
print (len(lst)) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | ```python
num = int(input())
lst = list(map(int, input().split()))
mx = max(lst)
men = min(lst)
lst.remove(mx)
lst.remove(men)
print (len(lst))
``` | 0 |
|
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX",
"output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX"
},
{
"input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO",
"output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO"
},
{
"input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD",
"output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD"
},
{
"input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW",
"output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW"
},
{
"input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL",
"output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL"
},
{
"input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC",
"output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC"
},
{
"input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN",
"output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN"
},
{
"input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE",
"output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE"
},
{
"input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP",
"output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP"
},
{
"input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG",
"output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG"
},
{
"input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV",
"output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV"
},
{
"input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI",
"output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI"
},
{
"input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX",
"output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX"
},
{
"input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ",
"output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ"
},
{
"input": "P",
"output": "P"
},
{
"input": "Xyzzy",
"output": "Xyzzy"
},
{
"input": "Zzz",
"output": "Zzz"
},
{
"input": "Zp",
"output": "Zp"
}
] | 1,695,094,278 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = input()
list_a = list(a)
list_a[0] = list_a[0].upper()
print("".join(list_a))a = input()
list_a = list(a)
list_a[0] = list_a[0].upper()
print("".join(list_a)) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input Specification:
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output Specification:
Output the given word after capitalization.
Demo Input:
['ApPLe\n', 'konjac\n']
Demo Output:
['ApPLe\n', 'Konjac\n']
Note:
none | ```python
a = input()
list_a = list(a)
list_a[0] = list_a[0].upper()
print("".join(list_a))a = input()
list_a = list(a)
list_a[0] = list_a[0].upper()
print("".join(list_a))
``` | -1 |
|
29 | B | Traffic Lights | PROGRAMMING | 1,500 | [
"implementation"
] | B. Traffic Lights | 2 | 256 | A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light is on for the *g* seconds, and so on.
The car can be instantly accelerated from 0 to *v* and vice versa, can instantly slow down from the *v* to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules? | The first line contains integers *l*, *d*, *v*, *g*, *r* (1<=≤<=*l*,<=*d*,<=*v*,<=*g*,<=*r*<=≤<=1000,<=*d*<=<<=*l*) — the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light. | Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10<=-<=6. | [
"2 1 3 4 5\n",
"5 4 3 1 1\n"
] | [
"0.66666667\n",
"2.33333333\n"
] | none | 1,000 | [
{
"input": "2 1 3 4 5",
"output": "0.66666667"
},
{
"input": "5 4 3 1 1",
"output": "2.33333333"
},
{
"input": "862 33 604 888 704",
"output": "1.42715232"
},
{
"input": "458 251 49 622 472",
"output": "9.34693878"
},
{
"input": "772 467 142 356 889",
"output": "5.43661972"
},
{
"input": "86 64 587 89 657",
"output": "0.14650767"
},
{
"input": "400 333 31 823 74",
"output": "12.90322581"
},
{
"input": "714 474 124 205 491",
"output": "5.75806452"
},
{
"input": "29 12 569 939 259",
"output": "0.05096661"
},
{
"input": "65 24 832 159 171",
"output": "0.07812500"
},
{
"input": "2 1 1 1 1",
"output": "3.00000000"
},
{
"input": "2 1 1 1 1000",
"output": "1002.00000000"
},
{
"input": "2 1 1 1000 1",
"output": "2.00000000"
},
{
"input": "2 1 1 1000 1000",
"output": "2.00000000"
},
{
"input": "2 1 1000 1 1",
"output": "0.00200000"
},
{
"input": "2 1 1000 1 1000",
"output": "0.00200000"
},
{
"input": "2 1 1000 1000 1",
"output": "0.00200000"
},
{
"input": "2 1 1000 1000 1000",
"output": "0.00200000"
},
{
"input": "1000 1 1 1 1",
"output": "1001.00000000"
},
{
"input": "1000 1 1 1 1000",
"output": "2000.00000000"
},
{
"input": "1000 1 1 1000 1",
"output": "1000.00000000"
},
{
"input": "1000 1 1 1000 1000",
"output": "1000.00000000"
},
{
"input": "1000 1 1000 1 1",
"output": "1.00000000"
},
{
"input": "1000 1 1000 1 1000",
"output": "1.00000000"
},
{
"input": "1000 1 1000 1000 1",
"output": "1.00000000"
},
{
"input": "1000 1 1000 1000 1000",
"output": "1.00000000"
},
{
"input": "1000 999 1 1 1",
"output": "1001.00000000"
},
{
"input": "1000 999 1 1 1000",
"output": "1002.00000000"
},
{
"input": "1000 999 1 1000 1",
"output": "1000.00000000"
},
{
"input": "1000 999 1 1000 1000",
"output": "1000.00000000"
},
{
"input": "1000 999 1000 1 1",
"output": "1.00000000"
},
{
"input": "1000 999 1000 1 1000",
"output": "1.00000000"
},
{
"input": "1000 999 1000 1000 1",
"output": "1.00000000"
},
{
"input": "1000 999 1000 1000 1000",
"output": "1.00000000"
}
] | 1,609,699,916 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 218 | 0 | l,d,v,g,r = map(int, input().split())
time = d/v
if time<g:
print(l/v)
elif time == g:
print(d/v + r-(d/v-g) + (l-d)/v)
else:
time = d/v
c = time%(g+r)
if c == 0 or c<g:
print(l/v)
else:
print(d/v+r-(d/v-g)+(l-d)/v)
| Title: Traffic Lights
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light is on for the *g* seconds, and so on.
The car can be instantly accelerated from 0 to *v* and vice versa, can instantly slow down from the *v* to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input Specification:
The first line contains integers *l*, *d*, *v*, *g*, *r* (1<=≤<=*l*,<=*d*,<=*v*,<=*g*,<=*r*<=≤<=1000,<=*d*<=<<=*l*) — the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output Specification:
Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10<=-<=6.
Demo Input:
['2 1 3 4 5\n', '5 4 3 1 1\n']
Demo Output:
['0.66666667\n', '2.33333333\n']
Note:
none | ```python
l,d,v,g,r = map(int, input().split())
time = d/v
if time<g:
print(l/v)
elif time == g:
print(d/v + r-(d/v-g) + (l-d)/v)
else:
time = d/v
c = time%(g+r)
if c == 0 or c<g:
print(l/v)
else:
print(d/v+r-(d/v-g)+(l-d)/v)
``` | 0 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,671,305,460 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a,b,c = map(int, input().split())
if (a*b)//c == (a*b)/c:
print((a*b)/c)
else:
print((a*b)//c+1) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
a,b,c = map(int, input().split())
if (a*b)//c == (a*b)/c:
print((a*b)/c)
else:
print((a*b)//c+1)
``` | 0 |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 3",
"output": "5001"
},
{
"input": "10000 10",
"output": "5000"
},
{
"input": "9999 3",
"output": "5001"
},
{
"input": "9999 2",
"output": "5000"
},
{
"input": "9999 10",
"output": "5000"
},
{
"input": "9999 9",
"output": "5004"
},
{
"input": "18 10",
"output": "10"
},
{
"input": "19 10",
"output": "10"
},
{
"input": "20 10",
"output": "10"
},
{
"input": "21 10",
"output": "20"
},
{
"input": "7688 5",
"output": "3845"
},
{
"input": "4608 5",
"output": "2305"
},
{
"input": "3979 2",
"output": "1990"
},
{
"input": "9985 6",
"output": "4998"
},
{
"input": "3230 8",
"output": "1616"
},
{
"input": "24 9",
"output": "18"
},
{
"input": "3275 8",
"output": "1640"
},
{
"input": "6240 7",
"output": "3122"
},
{
"input": "5227 4",
"output": "2616"
},
{
"input": "3832 6",
"output": "1920"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "10 5",
"output": "5"
},
{
"input": "3 2",
"output": "2"
},
{
"input": "6 4",
"output": "4"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "9 9",
"output": "9"
},
{
"input": "4 5",
"output": "-1"
}
] | 1,669,612,751 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | # https://codeforces.com/problemset/problem/476/A
n, m = map(int, input().split())
b, a = n // 2, n % 2
while b >= 0 and (b + a) % m != 0:
b -= 1
a += 2
if (b + a) % m == 0:
print(b + a)
else:
print(-1) | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
Input Specification:
The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10).
Output Specification:
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
Demo Input:
['10 2\n', '3 5\n']
Demo Output:
['6\n', '-1\n']
Note:
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | ```python
# https://codeforces.com/problemset/problem/476/A
n, m = map(int, input().split())
b, a = n // 2, n % 2
while b >= 0 and (b + a) % m != 0:
b -= 1
a += 2
if (b + a) % m == 0:
print(b + a)
else:
print(-1)
``` | 0 |
|
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,688,935,858 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | color: bool = False
for i in range(int(input()[0])):
for c in input():
if (c != 'C' and c != 'M' and c != 'Y'): continue
color = True
break
print("#Black&White") if not color else print("#Color") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none | ```python
color: bool = False
for i in range(int(input()[0])):
for c in input():
if (c != 'C' and c != 'M' and c != 'Y'): continue
color = True
break
print("#Black&White") if not color else print("#Color")
``` | 3 |
|
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,581,335,636 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n = int(input())
s = input()
l = list(map(int,input().split()))
c = 0
for i in range(len(l) - 1):
if s[i] == 'R' and s[i+1] == 'L' and abs(l[i] - l[i+1]) == 2 :
c +=1
break
else:
print(-1)
exit()
print(c)
| Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
n = int(input())
s = input()
l = list(map(int,input().split()))
c = 0
for i in range(len(l) - 1):
if s[i] == 'R' and s[i+1] == 'L' and abs(l[i] - l[i+1]) == 2 :
c +=1
break
else:
print(-1)
exit()
print(c)
``` | 0 |
|
219 | C | Color Stripe | PROGRAMMING | 1,600 | [
"brute force",
"dp",
"greedy"
] | null | null | A colored stripe is represented by a horizontal row of *n* square cells, each cell is pained one of *k* colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to *k* to repaint the cells. | The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=5·105; 2<=≤<=*k*<=≤<=26). The second line contains *n* uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first *k* English letters may be used. Each letter represents the color of the corresponding cell of the stripe. | Print a single integer — the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe. | [
"6 3\nABBACC\n",
"3 2\nBBB\n"
] | [
"2\nABCACA\n",
"1\nBAB\n"
] | none | 1,500 | [
{
"input": "6 3\nABBACC",
"output": "2\nABCACA"
},
{
"input": "3 2\nBBB",
"output": "1\nBAB"
},
{
"input": "1 2\nA",
"output": "0\nA"
},
{
"input": "1 26\nZ",
"output": "0\nZ"
},
{
"input": "2 2\nAA",
"output": "1\nAB"
},
{
"input": "2 2\nBA",
"output": "0\nBA"
},
{
"input": "6 2\nAAABBB",
"output": "2\nABABAB"
},
{
"input": "8 3\nAABBABBB",
"output": "3\nBACBABCB"
},
{
"input": "10 26\nAAAAAAAAAA",
"output": "5\nBABABABABA"
},
{
"input": "12 3\nAAABBBAAABBB",
"output": "4\nABABCBABABCB"
},
{
"input": "3 2\nAAB",
"output": "1\nBAB"
},
{
"input": "3 3\nBBA",
"output": "1\nABA"
},
{
"input": "3 3\nCCC",
"output": "1\nCAC"
},
{
"input": "8 3\nAABBCCBB",
"output": "4\nBACBACAB"
},
{
"input": "200 2\nBABAABBABBABBABABBBABAAABABBABABBBAABBBBABBAABBABABAAAAABAABBBAAAAAAABBBABAAAABABBBAABABAABAABBBAABBABAAAABABAAAABABABBBABBBAAABAAABAAABABAAABABABBABABABBABBBABBBBBABABBBABAAABAAABAABBAABBABBBBBABBBAB",
"output": "87\nABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"
},
{
"input": "20 2\nBBBBAAAAAABBBAAAAAAB",
"output": "10\nABABABABABABABABABAB"
},
{
"input": "20 3\nCCCCAAAAAAAAAAAAAAAA",
"output": "10\nACACBABABABABABABABA"
},
{
"input": "100 2\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "49\nABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"
},
{
"input": "100 2\nBBBBBBBAAABBAAAABAABBBAABABAAABBBABBAAAABBABAAAAAAAAAAAAABAAABBBAAABAABBBBBBBABBBBAABAAABBBAABBAAAAB",
"output": "48\nBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA"
},
{
"input": "100 2\nABAAABABABAAABAAABAAABABABAAABABABAAABABABAAABAAABAAABABABAAABAAABAAABABABAAABAAABAAABABABAAABABABAA",
"output": "17\nABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"
},
{
"input": "100 2\nABABABABABABABABABABABABABABABABABABABABABBBABABABABABABABABABABABABABABABABABABABABABABABABABABABAB",
"output": "1\nABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"
},
{
"input": "2 3\nAA",
"output": "1\nBA"
},
{
"input": "12 2\nBBBBABABABAB",
"output": "2\nABABABABABAB"
},
{
"input": "4 2\nAABA",
"output": "1\nBABA"
},
{
"input": "6 2\nBAABAB",
"output": "2\nABABAB"
},
{
"input": "10 2\nAABABABABA",
"output": "1\nBABABABABA"
},
{
"input": "6 2\nBBABAB",
"output": "1\nABABAB"
},
{
"input": "5 2\nBBABA",
"output": "1\nABABA"
},
{
"input": "45 26\nABCDEFGHIJKLMNOOOOOPPPPPQQQQQQPPQZZZZASDASDGF",
"output": "10\nABCDEFGHIJKLMNOPOPOPQPQPAQAQAQAPQAZAZASDASDGF"
},
{
"input": "3 2\nBBA",
"output": "1\nABA"
},
{
"input": "4 2\nABBA",
"output": "2\nABAB"
},
{
"input": "6 2\nAABABA",
"output": "1\nBABABA"
},
{
"input": "6 2\nBAAAAB",
"output": "3\nABABAB"
},
{
"input": "4 2\nAABB",
"output": "2\nABAB"
},
{
"input": "7 2\nAAAABBB",
"output": "3\nBABABAB"
},
{
"input": "41 2\nAABAAABBBBBBAAAABBBAAAAAABBBBBBBBAAAAAAAA",
"output": "19\nBABABABABABABABABABABABABABABABABABABABAB"
},
{
"input": "8 2\nAABABABA",
"output": "1\nBABABABA"
},
{
"input": "20 2\nABBABABBBABBABAAAABA",
"output": "8\nBABABABABABABABABABA"
},
{
"input": "5 2\nABBAB",
"output": "2\nBABAB"
},
{
"input": "10 2\nBBABABABAB",
"output": "1\nABABABABAB"
},
{
"input": "6 2\nABBABB",
"output": "3\nABABAB"
}
] | 1,626,521,838 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 124 | 6,963,200 | n, k = map(int, input().split())
s = input()
new_str = ""
def rec(i, last_color):
global new_str
if i == n:
return 0
if s[i] == last_color:
if k == 2:
new_str += "A" if last_color == "B" else "B"
elif i + 1 < n:
new_str += "A" if "A" not in {last_color, s[i+1]} else ("B" if "B" not in {last_color, s[i]} else "C")
else:
new_str += "A" if last_color != "A" else "B"
return rec(i+1, new_str[-1]) + 1
new_str += s[i]
return rec(i+1, s[i])
print(rec(0, 0))
print(new_str) | Title: Color Stripe
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A colored stripe is represented by a horizontal row of *n* square cells, each cell is pained one of *k* colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to *k* to repaint the cells.
Input Specification:
The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=5·105; 2<=≤<=*k*<=≤<=26). The second line contains *n* uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first *k* English letters may be used. Each letter represents the color of the corresponding cell of the stripe.
Output Specification:
Print a single integer — the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe.
Demo Input:
['6 3\nABBACC\n', '3 2\nBBB\n']
Demo Output:
['2\nABCACA\n', '1\nBAB\n']
Note:
none | ```python
n, k = map(int, input().split())
s = input()
new_str = ""
def rec(i, last_color):
global new_str
if i == n:
return 0
if s[i] == last_color:
if k == 2:
new_str += "A" if last_color == "B" else "B"
elif i + 1 < n:
new_str += "A" if "A" not in {last_color, s[i+1]} else ("B" if "B" not in {last_color, s[i]} else "C")
else:
new_str += "A" if last_color != "A" else "B"
return rec(i+1, new_str[-1]) + 1
new_str += s[i]
return rec(i+1, s[i])
print(rec(0, 0))
print(new_str)
``` | 0 |
|
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100",
"output": "NO"
},
{
"input": "1 10\n0 10",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40",
"output": "YES"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "1 1\n0 1",
"output": "YES"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100",
"output": "YES"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100",
"output": "NO"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100",
"output": "YES"
},
{
"input": "2 2\n0 2\n0 1",
"output": "YES"
},
{
"input": "2 100\n0 49\n50 100",
"output": "NO"
},
{
"input": "2 100\n0 50\n50 100",
"output": "YES"
},
{
"input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100",
"output": "YES"
},
{
"input": "100 10\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 10",
"output": "YES"
},
{
"input": "1 4\n1 4",
"output": "NO"
},
{
"input": "3 5\n0 2\n2 5\n3 4",
"output": "YES"
},
{
"input": "2 5\n0 5\n1 2",
"output": "YES"
},
{
"input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5",
"output": "NO"
},
{
"input": "4 10\n0 3\n2 10\n4 10\n5 7",
"output": "YES"
},
{
"input": "3 8\n0 0\n1 8\n2 8",
"output": "NO"
},
{
"input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8",
"output": "YES"
}
] | 1,587,049,905 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | # 3 5
# 0 2
# 2 4
# 3 5
# 3 7
# 0 4
# 2 5
# 6 7
n,m=map(int,input().split())
teleport=[]
limit=[]
i=0
for _ in range(n):
a,b=map(int,input().split())
teleport.append(a)
limit.append(b)
while i < n-1:
if limit[i]>=teleport[i+1]:
# print("This move is possible",limit[i])
if limit[i]>=m:
print("YES")
break
i=i+1
else:
# print("this movement is not possible",limit[i])
print("NO")
break
| Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Output Specification:
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | ```python
# 3 5
# 0 2
# 2 4
# 3 5
# 3 7
# 0 4
# 2 5
# 6 7
n,m=map(int,input().split())
teleport=[]
limit=[]
i=0
for _ in range(n):
a,b=map(int,input().split())
teleport.append(a)
limit.append(b)
while i < n-1:
if limit[i]>=teleport[i+1]:
# print("This move is possible",limit[i])
if limit[i]>=m:
print("YES")
break
i=i+1
else:
# print("this movement is not possible",limit[i])
print("NO")
break
``` | 0 |
|
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period. | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6",
"output": "3"
},
{
"input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32",
"output": "6"
},
{
"input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30",
"output": "10"
},
{
"input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20",
"output": "8"
},
{
"input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49",
"output": "1"
},
{
"input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16",
"output": "5"
},
{
"input": "2\n0 24\n1 0",
"output": "1"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "1\n1 5",
"output": "1"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "3"
},
{
"input": "1\n5 0",
"output": "1"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "5"
},
{
"input": "1\n10 10",
"output": "1"
},
{
"input": "1\n8 0",
"output": "1"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "10"
},
{
"input": "2\n0 0\n0 1",
"output": "1"
},
{
"input": "2\n8 5\n8 5",
"output": "2"
}
] | 1,646,998,510 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n=int(input())
g=[]
h=[]
count=0
for i in range(n):
h,m=map(int,input().split())
g=g+[h+m]
for i in g:
if g.count(i)>1:
count+=1
if count==0:
print(1)
elif count>0:
print(count)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
Output Specification:
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
Demo Input:
['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | ```python
n=int(input())
g=[]
h=[]
count=0
for i in range(n):
h,m=map(int,input().split())
g=g+[h+m]
for i in g:
if g.count(i)>1:
count+=1
if count==0:
print(1)
elif count>0:
print(count)
``` | 0 |
|
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98",
"output": "24"
}
] | 1,433,266,030 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 614,400 | n, m = map(int, input().split())
c = list(sorted(map(int, input().split())))
d = list(sorted(map(int, input().split())))
i, j = 0, 0
while i < n and j < m:
if c[i] <= d[j]:
i += 1
j += 1
print(n-i) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n']
Demo Output:
['0\n', '2\n', '3\n']
Note:
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | ```python
n, m = map(int, input().split())
c = list(sorted(map(int, input().split())))
d = list(sorted(map(int, input().split())))
i, j = 0, 0
while i < n and j < m:
if c[i] <= d[j]:
i += 1
j += 1
print(n-i)
``` | 3 |
|
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad. | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists. | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------",
"output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------"
},
{
"input": "1 1\n-",
"output": "-"
},
{
"input": "4 2\n..\n..\n..\n..",
"output": "BW\nWB\nBW\nWB"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "B\nW\nB\nW\nB"
}
] | 1,660,044,855 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 46 | 0 | n, m = [int(i) for i in input().split()]
chessboard = []
answer = []
for i in range(m):
chessboard.append([i for i in input()])
for i in range(m):
row = []
for j in range(n):
if chessboard[i][j] == '.':
if i + j == 0 or (i + j) % 2 == 0:
row.append('B')
else:
row.append('W')
else:
row.append('-')
answer.append(row)
for row in answer:
print(''.join(row)) | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output Specification:
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Demo Input:
['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.']
Demo Output:
['B\n', 'BW\nWB\n', 'B-B\n---\n--B']
Note:
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | ```python
n, m = [int(i) for i in input().split()]
chessboard = []
answer = []
for i in range(m):
chessboard.append([i for i in input()])
for i in range(m):
row = []
for j in range(n):
if chessboard[i][j] == '.':
if i + j == 0 or (i + j) % 2 == 0:
row.append('B')
else:
row.append('W')
else:
row.append('-')
answer.append(row)
for row in answer:
print(''.join(row))
``` | -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,666,080,044 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Oct 18 16:00:10 2022
@author: hp
"""
t = int(input())
for i in range(t):
x = int(input())
if 360 % (180 - x) == 0:
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
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 18 16:00:10 2022
@author: hp
"""
t = int(input())
for i in range(t):
x = int(input())
if 360 % (180 - x) == 0:
print('YES')
else:
print('NO')
``` | 3 |
|
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,579,175,598 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 156 | 0 | import sys
import math
import bisect
def main():
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for a in A:
if a in B:
C.append(a)
print(' '.join(list(str(a) for a in C)))
if __name__ == "__main__":
main()
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
import sys
import math
import bisect
def main():
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for a in A:
if a in B:
C.append(a)
print(' '.join(list(str(a) for a in C)))
if __name__ == "__main__":
main()
``` | 3 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,671,043,504 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 78 | 409,600 | n = int (input ())
a = input ()
one = 0 ; ze = 0
for i in range (len(a)):
if a [i] == "1":
one += 1
else :
ze += 1
print (abs (one-ze))
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n = int (input ())
a = input ()
one = 0 ; ze = 0
for i in range (len(a)):
if a [i] == "1":
one += 1
else :
ze += 1
print (abs (one-ze))
``` | 3 |
|
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn",
"output": "IGNORE HIM!"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx",
"output": "CHAT WITH HER!"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt",
"output": "IGNORE HIM!"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk",
"output": "IGNORE HIM!"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz",
"output": "IGNORE HIM!"
},
{
"input": "tgcdptnkc",
"output": "IGNORE HIM!"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi",
"output": "IGNORE HIM!"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp",
"output": "IGNORE HIM!"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia",
"output": "IGNORE HIM!"
},
{
"input": "fpellxwskyekoyvrfnuf",
"output": "CHAT WITH HER!"
},
{
"input": "xninyvkuvakfbs",
"output": "IGNORE HIM!"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak",
"output": "CHAT WITH HER!"
},
{
"input": "kmsk",
"output": "IGNORE HIM!"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz",
"output": "CHAT WITH HER!"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq",
"output": "CHAT WITH HER!"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm",
"output": "IGNORE HIM!"
},
{
"input": "ppcpbnhwoizajrl",
"output": "IGNORE HIM!"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv",
"output": "CHAT WITH HER!"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw",
"output": "IGNORE HIM!"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu",
"output": "CHAT WITH HER!"
},
{
"input": "ojjvpnkrxibyevxk",
"output": "CHAT WITH HER!"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg",
"output": "IGNORE HIM!"
},
{
"input": "hkdbykboclchfdsuovvpknwqr",
"output": "IGNORE HIM!"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu",
"output": "IGNORE HIM!"
},
{
"input": "rafcaanqytfclvfdegak",
"output": "CHAT WITH HER!"
},
{
"input": "xczn",
"output": "CHAT WITH HER!"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp",
"output": "IGNORE HIM!"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika",
"output": "CHAT WITH HER!"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh",
"output": "CHAT WITH HER!"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg",
"output": "CHAT WITH HER!"
},
{
"input": "udlpagtpq",
"output": "CHAT WITH HER!"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy",
"output": "CHAT WITH HER!"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten",
"output": "CHAT WITH HER!"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb",
"output": "CHAT WITH HER!"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr",
"output": "CHAT WITH HER!"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc",
"output": "IGNORE HIM!"
},
{
"input": "lnpdosnceumubvk",
"output": "IGNORE HIM!"
},
{
"input": "efrk",
"output": "CHAT WITH HER!"
},
{
"input": "temnownneghnrujforif",
"output": "IGNORE HIM!"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta",
"output": "IGNORE HIM!"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh",
"output": "IGNORE HIM!"
},
{
"input": "gwntwbpj",
"output": "IGNORE HIM!"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim",
"output": "IGNORE HIM!"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd",
"output": "CHAT WITH HER!"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx",
"output": "IGNORE HIM!"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks",
"output": "CHAT WITH HER!"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx",
"output": "CHAT WITH HER!"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc",
"output": "CHAT WITH HER!"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr",
"output": "IGNORE HIM!"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc",
"output": "IGNORE HIM!"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq",
"output": "CHAT WITH HER!"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj",
"output": "IGNORE HIM!"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom",
"output": "CHAT WITH HER!"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo",
"output": "CHAT WITH HER!"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh",
"output": "IGNORE HIM!"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa",
"output": "CHAT WITH HER!"
},
{
"input": "oh",
"output": "CHAT WITH HER!"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri",
"output": "IGNORE HIM!"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp",
"output": "CHAT WITH HER!"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp",
"output": "CHAT WITH HER!"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo",
"output": "CHAT WITH HER!"
},
{
"input": "mnmbupgo",
"output": "IGNORE HIM!"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl",
"output": "IGNORE HIM!"
},
{
"input": "yocxrzspinchmhtmqo",
"output": "CHAT WITH HER!"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv",
"output": "CHAT WITH HER!"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad",
"output": "IGNORE HIM!"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli",
"output": "CHAT WITH HER!"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy",
"output": "IGNORE HIM!"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd",
"output": "IGNORE HIM!"
},
{
"input": "acrzbavz",
"output": "CHAT WITH HER!"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza",
"output": "IGNORE HIM!"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws",
"output": "CHAT WITH HER!"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff",
"output": "CHAT WITH HER!"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu",
"output": "CHAT WITH HER!"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw",
"output": "IGNORE HIM!"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy",
"output": "CHAT WITH HER!"
},
{
"input": "rhh",
"output": "CHAT WITH HER!"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo",
"output": "IGNORE HIM!"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn",
"output": "CHAT WITH HER!"
},
{
"input": "urigreuzpxnej",
"output": "CHAT WITH HER!"
}
] | 1,695,824,766 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s = input()
n = len(s)
distinct = 0
duplicate = []
for i in range(n-1):
flag = False
for j in range(i+1,n):
if s[i] == s[j]:
duplicate.append(s[i])
flag = True
break
if not flag and s[i] not in duplicate:
distinct += 1
if distinct % 2 == 0:
print("CHAT WITH HER")
elif distinct % 2 != 0:
print("IGNORE HIM")
| Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
Input Specification:
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
Output Specification:
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
Demo Input:
['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n']
Demo Output:
['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n']
Note:
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | ```python
s = input()
n = len(s)
distinct = 0
duplicate = []
for i in range(n-1):
flag = False
for j in range(i+1,n):
if s[i] == s[j]:
duplicate.append(s[i])
flag = True
break
if not flag and s[i] not in duplicate:
distinct += 1
if distinct % 2 == 0:
print("CHAT WITH HER")
elif distinct % 2 != 0:
print("IGNORE HIM")
``` | 0 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,665,463,160 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 8,806,400 | n = int(input())
A = tuple(map(int,input().split()))
m = int(input())
B = tuple(map(int,input().split()))
def f_l_search(A, n, s):
for i in range(0, n):
if (hash(A[i] == hash(s))):
return i + 1
V, P = 0, 0
for i in B:
res = f_l_search(A, n, i)
V += res
P += n + 1 - res
print(V, P) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
n = int(input())
A = tuple(map(int,input().split()))
m = int(input())
B = tuple(map(int,input().split()))
def f_l_search(A, n, s):
for i in range(0, n):
if (hash(A[i] == hash(s))):
return i + 1
V, P = 0, 0
for i in B:
res = f_l_search(A, n, i)
V += res
P += n + 1 - res
print(V, P)
``` | 0 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,587,373,668 | 2,147,483,647 | PyPy 3 | OK | TESTS | 114 | 171 | 0 | n, k = [ int(i) for i in input().strip().split(' ')]
f = [ 0 for i in range(26)]
s = input().strip()
for i in s:
f[ord(i)-ord('a')] = f[ord(i)-ord('a')] + 1
if max(f)>k:
print('NO')
else:
print('YES') | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
n, k = [ int(i) for i in input().strip().split(' ')]
f = [ 0 for i in range(26)]
s = input().strip()
for i in s:
f[ord(i)-ord('a')] = f[ord(i)-ord('a')] + 1
if max(f)>k:
print('NO')
else:
print('YES')
``` | 3 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,681,271,252 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
lst=[]
lst1=[]
c=0
for i in range(n):
a,b=input().split()
lst.append(a)
lst1.append(b)
for i in range(len(lst)):
for j in range(len(lst1)):
if lst[i]==lst1[j]:
c=c+1
print(c) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
n=int(input())
lst=[]
lst1=[]
c=0
for i in range(n):
a,b=input().split()
lst.append(a)
lst1.append(b)
for i in range(len(lst)):
for j in range(len(lst1)):
if lst[i]==lst1[j]:
c=c+1
print(c)
``` | 3 |
|
219 | B | Special Offer! Super Price 999 Bourles! | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than *d* bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price. | The first line contains two integers *p* and *d* (1<=≤<=*p*<=≤<=1018; 0<=≤<=*d*<=<<=*p*) — the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print the required price — the maximum price that ends with the largest number of nines and that is less than *p* by no more than *d*.
The required number shouldn't have leading zeroes. | [
"1029 102\n",
"27191 17\n"
] | [
"999\n",
"27189\n"
] | none | 1,000 | [
{
"input": "1029 102",
"output": "999"
},
{
"input": "27191 17",
"output": "27189"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "9 0",
"output": "9"
},
{
"input": "20 1",
"output": "19"
},
{
"input": "100 23",
"output": "99"
},
{
"input": "10281 1",
"output": "10281"
},
{
"input": "2111 21",
"output": "2099"
},
{
"input": "3021 112",
"output": "2999"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "999999999999999999"
},
{
"input": "29287101 301",
"output": "29286999"
},
{
"input": "302918113 8113",
"output": "302917999"
},
{
"input": "23483247283432 47283432",
"output": "23483239999999"
},
{
"input": "47283432 7283432",
"output": "46999999"
},
{
"input": "7283432 7283431",
"output": "6999999"
},
{
"input": "2304324853947 5853947",
"output": "2304319999999"
},
{
"input": "2485348653485 123483",
"output": "2485348599999"
},
{
"input": "29845435345 34543",
"output": "29845429999"
},
{
"input": "2348723847234234 234829384234",
"output": "2348699999999999"
},
{
"input": "2348723847234234 234829384234",
"output": "2348699999999999"
},
{
"input": "596383801524465437 13997918422040",
"output": "596379999999999999"
},
{
"input": "621306590487786841 47851896849379",
"output": "621299999999999999"
},
{
"input": "990575220328844835 100861359807341",
"output": "990499999999999999"
},
{
"input": "403277728241895842 15097810739041",
"output": "403269999999999999"
},
{
"input": "287854791214303304 98046359947548",
"output": "287799999999999999"
},
{
"input": "847222126505823289 115713658562976",
"output": "847199999999999999"
},
{
"input": "991096248227872657 181679439312637",
"output": "990999999999999999"
},
{
"input": "954402996235787062 354162450334047",
"output": "954399999999999999"
},
{
"input": "220466716596033408 44952575147901",
"output": "220459999999999999"
},
{
"input": "559198116944738707 844709119308273",
"output": "558999999999999999"
},
{
"input": "363980380443991024 4242310030748",
"output": "363979999999999999"
},
{
"input": "733498827000355608 13253459808159",
"output": "733489999999999999"
},
{
"input": "757663489894439901 139905688448459",
"output": "757599999999999999"
},
{
"input": "30528581170507487 1199546082507",
"output": "30527999999999999"
},
{
"input": "534463403123444176 67776394133861",
"output": "534399999999999999"
},
{
"input": "399943891120381720 89545256475298",
"output": "399899999999999999"
},
{
"input": "697076786191991245 95935185412097",
"output": "696999999999999999"
},
{
"input": "495773842562930245 17116719198640",
"output": "495769999999999999"
},
{
"input": "343540186435799067 48368225269792",
"output": "343499999999999999"
},
{
"input": "393776794010351632 4138311260892",
"output": "393775999999999999"
},
{
"input": "830005749156754342 157633405415940",
"output": "829999999999999999"
},
{
"input": "735716632509713228 109839072010906",
"output": "735699999999999999"
},
{
"input": "925835698451819219 232827103605000",
"output": "925799999999999999"
},
{
"input": "362064657893189225 54298707317247",
"output": "362059999999999999"
},
{
"input": "286739242579659245 61808986676984",
"output": "286699999999999999"
},
{
"input": "234522568185994645 14536016333590",
"output": "234519999999999999"
},
{
"input": "989980699593228598 382407804389880",
"output": "989899999999999999"
},
{
"input": "953287447601143003 367647762226264",
"output": "952999999999999999"
},
{
"input": "369834331957505226 421031521866991",
"output": "369799999999999999"
},
{
"input": "433225528653135646 16671330805568",
"output": "433219999999999999"
},
{
"input": "664584428369850915 516656201621892",
"output": "664499999999999999"
},
{
"input": "100813383516253625 468493737928751",
"output": "100799999999999999"
},
{
"input": "63600749936231318 12287109070881",
"output": "63599999999999999"
},
{
"input": "196643334958802150 3659421793154",
"output": "196639999999999999"
},
{
"input": "803015192835672406 14043666502157",
"output": "803009999999999999"
},
{
"input": "43201857567928862 5891486380570",
"output": "43199999999999999"
},
{
"input": "142195487377202511 32209508975060",
"output": "142189999999999999"
},
{
"input": "159171676706847083 28512592184962",
"output": "159169999999999999"
},
{
"input": "377788117133266645 12127036235155",
"output": "377779999999999999"
},
{
"input": "949501478909148807 31763408418934",
"output": "949499999999999999"
},
{
"input": "955412075341421601 220849506773896",
"output": "955399999999999999"
},
{
"input": "652742935922718161 11045914932687",
"output": "652739999999999999"
},
{
"input": "371621017875752909 511452352707014",
"output": "371599999999999999"
},
{
"input": "979748686171802330 281906901894586",
"output": "979699999999999999"
},
{
"input": "987860891213585005 85386263418762",
"output": "987799999999999999"
},
{
"input": "59225847802373220 8605552735740",
"output": "59219999999999999"
},
{
"input": "22532595810287625 1459945485391",
"output": "22531999999999999"
},
{
"input": "191654878233371957 258451919478343",
"output": "191599999999999999"
},
{
"input": "796937674525939896 892734175683845",
"output": "796899999999999999"
},
{
"input": "166564871934000326 22888347028438",
"output": "166559999999999999"
},
{
"input": "559198116944738707 84470911930827",
"output": "559189999999999999"
},
{
"input": "559198116944738707 8447091193082",
"output": "559189999999999999"
},
{
"input": "559198116944738707 844709119308",
"output": "559197999999999999"
},
{
"input": "559198116944738707 84470911930",
"output": "559198099999999999"
},
{
"input": "559198116944738707 8447091193",
"output": "559198109999999999"
},
{
"input": "559198116944738707 844709119",
"output": "559198116899999999"
},
{
"input": "559198116944738707 84470911",
"output": "559198116899999999"
},
{
"input": "559198116944738707 8447091",
"output": "559198116939999999"
},
{
"input": "559198116944738707 844709",
"output": "559198116943999999"
},
{
"input": "559198116944738707 84470",
"output": "559198116944699999"
},
{
"input": "559198116944738707 8447",
"output": "559198116944737999"
},
{
"input": "559198116944738707 844",
"output": "559198116944737999"
},
{
"input": "559198116944738707 84",
"output": "559198116944738699"
},
{
"input": "559198116944738707 8",
"output": "559198116944738699"
},
{
"input": "559198116944738707 7",
"output": "559198116944738707"
},
{
"input": "559198116944738707 6",
"output": "559198116944738707"
},
{
"input": "559198116944738707 1",
"output": "559198116944738707"
},
{
"input": "559198116944738707 0",
"output": "559198116944738707"
},
{
"input": "559198116944738700 1",
"output": "559198116944738699"
},
{
"input": "559198116944738700 0",
"output": "559198116944738700"
},
{
"input": "559198116944738999 0",
"output": "559198116944738999"
},
{
"input": "559198116944738999 1",
"output": "559198116944738999"
},
{
"input": "199 100",
"output": "199"
},
{
"input": "99 10",
"output": "99"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "18 17",
"output": "9"
},
{
"input": "199 198",
"output": "199"
},
{
"input": "1000000000000000000 0",
"output": "1000000000000000000"
},
{
"input": "59 3",
"output": "59"
},
{
"input": "9999 10",
"output": "9999"
},
{
"input": "999999999999999998 999999999999999997",
"output": "899999999999999999"
},
{
"input": "8 7",
"output": "8"
}
] | 1,623,165,772 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 436 | 2,150,400 | p,d = map(int,input().split())
k=1;
x=[]
while(10**k<d):
x.append(p-(p%10**k)-1)
k+=1
print(x[-1])
| Title: Special Offer! Super Price 999 Bourles!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than *d* bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price.
Input Specification:
The first line contains two integers *p* and *d* (1<=≤<=*p*<=≤<=1018; 0<=≤<=*d*<=<<=*p*) — the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Output Specification:
Print the required price — the maximum price that ends with the largest number of nines and that is less than *p* by no more than *d*.
The required number shouldn't have leading zeroes.
Demo Input:
['1029 102\n', '27191 17\n']
Demo Output:
['999\n', '27189\n']
Note:
none | ```python
p,d = map(int,input().split())
k=1;
x=[]
while(10**k<d):
x.append(p-(p%10**k)-1)
k+=1
print(x[-1])
``` | -1 |
|
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,687,182,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | t=int(input())
while(t>0):
st=input()
print(len(st))
print(st[0]+str(len(st)-2)+st[-1])
t-=1 | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
t=int(input())
while(t>0):
st=input()
print(len(st))
print(st[0]+str(len(st)-2)+st[-1])
t-=1
``` | 0 |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100",
"output": "NO"
},
{
"input": "1 10\n0 10",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40",
"output": "YES"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "1 1\n0 1",
"output": "YES"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100",
"output": "YES"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100",
"output": "NO"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100",
"output": "YES"
},
{
"input": "2 2\n0 2\n0 1",
"output": "YES"
},
{
"input": "2 100\n0 49\n50 100",
"output": "NO"
},
{
"input": "2 100\n0 50\n50 100",
"output": "YES"
},
{
"input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100",
"output": "YES"
},
{
"input": "100 10\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 10",
"output": "YES"
},
{
"input": "1 4\n1 4",
"output": "NO"
},
{
"input": "3 5\n0 2\n2 5\n3 4",
"output": "YES"
},
{
"input": "2 5\n0 5\n1 2",
"output": "YES"
},
{
"input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5",
"output": "NO"
},
{
"input": "4 10\n0 3\n2 10\n4 10\n5 7",
"output": "YES"
},
{
"input": "3 8\n0 0\n1 8\n2 8",
"output": "NO"
},
{
"input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8",
"output": "YES"
}
] | 1,513,839,963 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 62 | 5,632,000 | a = input().split()
a = list(map(int,a))
n,m = a[0],a[1]
list1 = []
for i in range(0,n):
a = input().split()
a = list(map(int,a))
list1.append(a)
if list1[0][0] != 0:
print ('NO')
else:
list2 = [0]
for i in range(0,n):
if list1[i][0] in list2:
for each in range(list1[i][0],list1[i][1] + 1):
list2.append(each)
if m in list2:
print ('YES')
else:
print ('NO')
| Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Output Specification:
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | ```python
a = input().split()
a = list(map(int,a))
n,m = a[0],a[1]
list1 = []
for i in range(0,n):
a = input().split()
a = list(map(int,a))
list1.append(a)
if list1[0][0] != 0:
print ('NO')
else:
list2 = [0]
for i in range(0,n):
if list1[i][0] in list2:
for each in range(list1[i][0],list1[i][1] + 1):
list2.append(each)
if m in list2:
print ('YES')
else:
print ('NO')
``` | 3 |
|
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,635,000,838 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 4,505,600 | val = input()
previous = ""
answer = []
for current in val:
# 0
if current == "." and previous != "-":
answer.append(0)
previous = ""
if current == "." and previous == "-":
answer.append(1)
previous = ""
if current == "-" and previous == "-":
answer.append(2)
previous = ""
else:
previous = current
for item in answer:
print(item, end="")
print()
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
val = input()
previous = ""
answer = []
for current in val:
# 0
if current == "." and previous != "-":
answer.append(0)
previous = ""
if current == "." and previous == "-":
answer.append(1)
previous = ""
if current == "-" and previous == "-":
answer.append(2)
previous = ""
else:
previous = current
for item in answer:
print(item, end="")
print()
``` | 3.960608 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,672,077,481 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def kol(s):
return s.count("QAQ")
s = input()
print(kol(s))
| Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
def kol(s):
return s.count("QAQ")
s = input()
print(kol(s))
``` | 0 |
|
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 1,694,710,115 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n = int(input())
data = input().split()
a = [int(x) for x in data]
b = [0] * n
for i in range(n):
if b[a[i] - 1] != 1:
b[a[i] - 1] = 1
if b == [1] * n:
print('YES')
else:
print('NO') | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Specification:
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case.
Demo Input:
['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | ```python
n = int(input())
data = input().split()
a = [int(x) for x in data]
b = [0] * n
for i in range(n):
if b[a[i] - 1] != 1:
b[a[i] - 1] = 1
if b == [1] * n:
print('YES')
else:
print('NO')
``` | 0 |
|
140 | B | New Year Cards | PROGRAMMING | 1,800 | [
"brute force",
"greedy",
"implementation"
] | null | null | As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has *n* friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to *n* in the order in which they send the cards. Let's introduce the same numbering for the cards, that is, according to the numbering the *i*-th friend sent to Alexander a card number *i*.
Alexander also sends cards to friends, but he doesn't look for the new cards on the Net. He simply uses the cards previously sent to him (sometimes, however, he does need to add some crucial details). Initially Alexander doesn't have any cards. Alexander always follows the two rules:
1. He will never send to a firend a card that this friend has sent to him. 1. Among the other cards available to him at the moment, Alexander always chooses one that Alexander himself likes most.
Alexander plans to send to each friend exactly one card. Of course, Alexander can send the same card multiple times.
Alexander and each his friend has the list of preferences, which is a permutation of integers from 1 to *n*. The first number in the list is the number of the favorite card, the second number shows the second favorite, and so on, the last number shows the least favorite card.
Your task is to find a schedule of sending cards for Alexander. Determine at which moments of time Alexander must send cards to his friends, to please each of them as much as possible. In other words, so that as a result of applying two Alexander's rules, each friend receives the card that is preferred for him as much as possible.
Note that Alexander doesn't choose freely what card to send, but he always strictly follows the two rules. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=300) — the number of Alexander's friends, equal to the number of cards. Next *n* lines contain his friends' preference lists. Each list consists of *n* different integers from 1 to *n*. The last line contains Alexander's preference list in the same format. | Print *n* space-separated numbers: the *i*-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the *i*-th friend. If there are several solutions, print any of them. | [
"4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4\n"
] | [
"2 1 1 4\n"
] | In the sample, the algorithm of actions Alexander and his friends perform is as follows:
1. Alexander receives card 1 from the first friend. 1. Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3. 1. Alexander receives card 2 from the second friend, now he has two cards — 1 and 2. 1. Alexander sends a card to the first friend. Despite the fact that Alexander likes card 1 more, he sends card 2 as he cannot send a friend the card sent by that very friend. 1. Alexander receives card 3 from the third friend. 1. Alexander receives card 4 from the fourth friend. 1. Among the cards Alexander has number 3 is his favorite and he sends it to the fourth friend.
Note that Alexander can send cards to multiple friends at a time (in this case the second and the third one). Alexander can send card 3 to the fourth friend after he receives the third card or after he receives the fourth card (both variants are correct). | 1,000 | [
{
"input": "4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4",
"output": "2 1 1 3"
},
{
"input": "2\n1 2\n2 1\n2 1",
"output": "2 1"
},
{
"input": "3\n1 2 3\n2 3 1\n1 3 2\n3 2 1",
"output": "2 3 1"
},
{
"input": "5\n1 4 2 3 5\n5 1 3 4 2\n3 2 4 1 5\n1 4 5 3 2\n5 2 3 4 1\n5 4 2 1 3",
"output": "4 5 2 1 2"
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\n10 1 7 8 3 2 4 6 5 9\n3 2 10 4 7 8 5 6 1 9\n5 6 3 10 8 7 2 9 4 1\n6 5 1 3 2 7 9 10 8 4\n1 10 9 3 7 8 4 2 6 5\n6 8 4 5 9 1 2 10 7 3\n9 6 8 5 10 3 1 7 2 4\n5 7 4 8 9 6 1 10 3 2",
"output": "5 1 1 1 4 5 5 1 4 5"
}
] | 1,590,979,595 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 280 | 0 | n = int(input())
frnd = [list(map(int, input().split() )) for _ in range(n)]
ara = list(map(int, input().split() ))
pref = [0]*(n+1)
ans = [0]*(n)
for i in range(n):
pref[ara[i]] = i+1
def better(ro, x, y):
if x == ro:
return y
if y == ro:
return x
if pref[x] < pref[y]:
return x
return min(x, y)
# print(ara)
for ro in range(n):
tgt = frnd[ro][0]
for i in range(1, n):
# print(ro, tgt, frnd[ro][i] , end = ' ')
tgt = better(ro+1, tgt, frnd[ro][i])
# print(tgt)
ans[ro] = tgt
for i in range(n):
print(ans[i], end=' ')
print()
| Title: New Year Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has *n* friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to *n* in the order in which they send the cards. Let's introduce the same numbering for the cards, that is, according to the numbering the *i*-th friend sent to Alexander a card number *i*.
Alexander also sends cards to friends, but he doesn't look for the new cards on the Net. He simply uses the cards previously sent to him (sometimes, however, he does need to add some crucial details). Initially Alexander doesn't have any cards. Alexander always follows the two rules:
1. He will never send to a firend a card that this friend has sent to him. 1. Among the other cards available to him at the moment, Alexander always chooses one that Alexander himself likes most.
Alexander plans to send to each friend exactly one card. Of course, Alexander can send the same card multiple times.
Alexander and each his friend has the list of preferences, which is a permutation of integers from 1 to *n*. The first number in the list is the number of the favorite card, the second number shows the second favorite, and so on, the last number shows the least favorite card.
Your task is to find a schedule of sending cards for Alexander. Determine at which moments of time Alexander must send cards to his friends, to please each of them as much as possible. In other words, so that as a result of applying two Alexander's rules, each friend receives the card that is preferred for him as much as possible.
Note that Alexander doesn't choose freely what card to send, but he always strictly follows the two rules.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=300) — the number of Alexander's friends, equal to the number of cards. Next *n* lines contain his friends' preference lists. Each list consists of *n* different integers from 1 to *n*. The last line contains Alexander's preference list in the same format.
Output Specification:
Print *n* space-separated numbers: the *i*-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the *i*-th friend. If there are several solutions, print any of them.
Demo Input:
['4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4\n']
Demo Output:
['2 1 1 4\n']
Note:
In the sample, the algorithm of actions Alexander and his friends perform is as follows:
1. Alexander receives card 1 from the first friend. 1. Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3. 1. Alexander receives card 2 from the second friend, now he has two cards — 1 and 2. 1. Alexander sends a card to the first friend. Despite the fact that Alexander likes card 1 more, he sends card 2 as he cannot send a friend the card sent by that very friend. 1. Alexander receives card 3 from the third friend. 1. Alexander receives card 4 from the fourth friend. 1. Among the cards Alexander has number 3 is his favorite and he sends it to the fourth friend.
Note that Alexander can send cards to multiple friends at a time (in this case the second and the third one). Alexander can send card 3 to the fourth friend after he receives the third card or after he receives the fourth card (both variants are correct). | ```python
n = int(input())
frnd = [list(map(int, input().split() )) for _ in range(n)]
ara = list(map(int, input().split() ))
pref = [0]*(n+1)
ans = [0]*(n)
for i in range(n):
pref[ara[i]] = i+1
def better(ro, x, y):
if x == ro:
return y
if y == ro:
return x
if pref[x] < pref[y]:
return x
return min(x, y)
# print(ara)
for ro in range(n):
tgt = frnd[ro][0]
for i in range(1, n):
# print(ro, tgt, frnd[ro][i] , end = ' ')
tgt = better(ro+1, tgt, frnd[ro][i])
# print(tgt)
ans[ro] = tgt
for i in range(n):
print(ans[i], end=' ')
print()
``` | 0 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,693,647,079 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 248 | 23,552,000 | n = int(input()) #len of n_array
n_array = {i:a for a,i in enumerate(map(int,input().split()))}
m = int(input()) #len of m_array
m_array = sum(n_array[i] for i in map(int,input().split()))
print(m_array+m,(n*m)-m_array) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
n = int(input()) #len of n_array
n_array = {i:a for a,i in enumerate(map(int,input().split()))}
m = int(input()) #len of m_array
m_array = sum(n_array[i] for i in map(int,input().split()))
print(m_array+m,(n*m)-m_array)
``` | 3 |
|
985 | F | Isomorphic Strings | PROGRAMMING | 2,300 | [
"hashing",
"strings"
] | null | null | You are given a string *s* of length *n* consisting of lowercase English letters.
For two given strings *s* and *t*, say *S* is the set of distinct characters of *s* and *T* is the set of distinct characters of *t*. The strings *s* and *t* are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) *f* between *S* and *T* for which *f*(*s**i*)<==<=*t**i*. Formally:
1. *f*(*s**i*)<==<=*t**i* for any index *i*, 1. for any character there is exactly one character that *f*(*x*)<==<=*y*, 1. for any character there is exactly one character that *f*(*x*)<==<=*y*.
For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best".
You have to handle *m* queries characterized by three integers *x*,<=*y*,<=*len* (1<=≤<=*x*,<=*y*<=≤<=*n*<=-<=*len*<=+<=1). For each query check if two substrings *s*[*x*... *x*<=+<=*len*<=-<=1] and *s*[*y*... *y*<=+<=*len*<=-<=1] are isomorphic. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105) — the length of the string *s* and the number of queries.
The second line contains string *s* consisting of *n* lowercase English letters.
The following *m* lines contain a single query on each line: *x**i*, *y**i* and *len**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*len**i*<=≤<=*n*<=-<=*max*(*x**i*,<=*y**i*)<=+<=1) — the description of the pair of the substrings to check. | For each query in a separate line print "YES" if substrings *s*[*x**i*... *x**i*<=+<=*len**i*<=-<=1] and *s*[*y**i*... *y**i*<=+<=*len**i*<=-<=1] are isomorphic and "NO" otherwise. | [
"7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3\n"
] | [
"YES\nYES\nNO\nYES\n"
] | The queries in the example are following:
1. substrings "a" and "a" are isomorphic: *f*(*a*) = *a*; 1. substrings "ab" and "ca" are isomorphic: *f*(*a*) = *c*, *f*(*b*) = *a*; 1. substrings "bac" and "aba" are not isomorphic since *f*(*b*) and *f*(*c*) must be equal to *a* at same time; 1. substrings "bac" and "cab" are isomorphic: *f*(*b*) = *c*, *f*(*a*) = *a*, *f*(*c*) = *b*. | 0 | [
{
"input": "7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3",
"output": "YES\nYES\nNO\nYES"
},
{
"input": "1 2\nz\n1 1 1\n1 1 1",
"output": "YES\nYES"
},
{
"input": "36 4\naababcbbcbczaaawwwwwaaaabbbbtestbest\n1 7 6\n13 18 5\n23 26 3\n29 33 4",
"output": "YES\nYES\nNO\nNO"
},
{
"input": "4 1\nabac\n1 2 3",
"output": "NO"
},
{
"input": "5 10\ncaabc\n5 4 1\n5 4 1\n1 5 1\n4 2 2\n1 3 1\n5 5 1\n4 4 1\n4 3 2\n1 4 1\n5 1 1",
"output": "YES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "10 30\naccbaaccac\n6 8 3\n2 9 1\n6 8 3\n10 5 1\n6 2 2\n1 4 7\n3 10 1\n6 9 1\n7 7 3\n7 3 2\n8 4 1\n4 9 1\n7 6 4\n6 8 2\n10 2 1\n1 3 5\n5 10 1\n7 10 1\n4 1 2\n8 5 3\n9 8 1\n8 6 2\n6 9 2\n10 3 1\n3 9 1\n5 5 5\n1 5 6\n4 2 6\n10 7 1\n9 8 2",
"output": "NO\nYES\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES"
},
{
"input": "64 1\nabbbbbbaababaaabbabbaabababbabbabbbbbbaabbaaabbbabbbaaaabaaabaaa\n1 33 32",
"output": "NO"
},
{
"input": "64 1\naabbbabaabaaaababbaabbbabbaaababababbbbaabaaaaababbaaababbbabbab\n1 33 32",
"output": "NO"
},
{
"input": "64 1\nbbabaabbabbaaaaabaaabbbbbbbbbbabbaaabbbbbbbbabaabaababaaabbabaaa\n1 33 32",
"output": "NO"
},
{
"input": "64 1\nbbbbaababaabbbabbaaaabbaaaaaaaaaaaaabbabbbbbbaababbabbababbbabaa\n1 33 32",
"output": "NO"
},
{
"input": "64 1\nababbaaabbaabaababbbbbbbbbaabbaabaaabbaabbaaabbabaabaabbaababbba\n1 33 32",
"output": "NO"
},
{
"input": "64 1\nbaabbaababbbbbaaaaaaabaabbbbbbbaaabbbaaaaaababbabbaaabbbbabaaaab\n1 33 32",
"output": "NO"
},
{
"input": "64 1\naabbaabababbaababababbabbabaaabbbbbaaaababbaaabbbaabbaaaabbaaaba\n1 33 32",
"output": "NO"
},
{
"input": "64 1\naaaaaaabaabaabaababbbaabbabbabaabbbbaabaaabbabbaabaaabbabbbbaaba\n1 33 32",
"output": "NO"
},
{
"input": "40 1\nbabbaaaabaabbbaabbaaabbbabbbbbaaaabaaaab\n1 21 20",
"output": "NO"
},
{
"input": "80 1\nabaabbbbaaaaabbabbaaaabbaabaaaaababababaaabaabaaaaababbabbaaaaabbbabbbbaaaaabbbb\n1 41 40",
"output": "NO"
},
{
"input": "24 1\nccacbbabcacabababaacaacc\n1 13 12",
"output": "NO"
},
{
"input": "80 1\naaaabaaaaababbbbbbaabbbabbbbbbaaaaabaaaaabbabbbababaabbbbbbabbababbbbabbaabbabbb\n1 41 40",
"output": "NO"
},
{
"input": "80 1\naaabbbaababbabbbbaabbaabbbaaabbabaabaaabbabaaaaabbbbbaaabaaabbbabaaababbbbbbabba\n1 41 40",
"output": "NO"
},
{
"input": "80 1\naabbbbbaaabaaabbabaabaababbabbbbabbaaabababbabaaaaabbaaaabaabaabbaaaaabaaaabaaba\n1 41 40",
"output": "NO"
}
] | 1,527,859,733 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 170 | 1,024,000 | from sys import stdin
def main():
def f(t):
z = 1
for i in range(t, t + 26):
a = (hh[i + le] - hh[i] * k) % mod
if a:
z = z * a % 2147483693
return z
n, m = map(int, input().split())
hh, k = [0] * 52, 1
kk, mod = [1], 2147483659
prn(mod.bit_length())
for i, c in enumerate(input()):
for _ in range(26):
hh.append(hh[-26] * 2)
hh[ord(c) - 123] += 1
k *= 2
if not i & 31:
k %= mod
for j in range(-26, 0):
hh[j] %= mod
kk.append(k)
l = stdin.read().splitlines()
for i, xyle in enumerate(l):
x, y, le = map(int, xyle.split())
k = kk[le]
le *= 26
l[i] = ('NO', 'YES')[f(x * 26) == f(y * 26)]
print('\n'.join(l))
if __name__ == '__main__':
main()
| Title: Isomorphic Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* of length *n* consisting of lowercase English letters.
For two given strings *s* and *t*, say *S* is the set of distinct characters of *s* and *T* is the set of distinct characters of *t*. The strings *s* and *t* are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) *f* between *S* and *T* for which *f*(*s**i*)<==<=*t**i*. Formally:
1. *f*(*s**i*)<==<=*t**i* for any index *i*, 1. for any character there is exactly one character that *f*(*x*)<==<=*y*, 1. for any character there is exactly one character that *f*(*x*)<==<=*y*.
For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best".
You have to handle *m* queries characterized by three integers *x*,<=*y*,<=*len* (1<=≤<=*x*,<=*y*<=≤<=*n*<=-<=*len*<=+<=1). For each query check if two substrings *s*[*x*... *x*<=+<=*len*<=-<=1] and *s*[*y*... *y*<=+<=*len*<=-<=1] are isomorphic.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105) — the length of the string *s* and the number of queries.
The second line contains string *s* consisting of *n* lowercase English letters.
The following *m* lines contain a single query on each line: *x**i*, *y**i* and *len**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*len**i*<=≤<=*n*<=-<=*max*(*x**i*,<=*y**i*)<=+<=1) — the description of the pair of the substrings to check.
Output Specification:
For each query in a separate line print "YES" if substrings *s*[*x**i*... *x**i*<=+<=*len**i*<=-<=1] and *s*[*y**i*... *y**i*<=+<=*len**i*<=-<=1] are isomorphic and "NO" otherwise.
Demo Input:
['7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3\n']
Demo Output:
['YES\nYES\nNO\nYES\n']
Note:
The queries in the example are following:
1. substrings "a" and "a" are isomorphic: *f*(*a*) = *a*; 1. substrings "ab" and "ca" are isomorphic: *f*(*a*) = *c*, *f*(*b*) = *a*; 1. substrings "bac" and "aba" are not isomorphic since *f*(*b*) and *f*(*c*) must be equal to *a* at same time; 1. substrings "bac" and "cab" are isomorphic: *f*(*b*) = *c*, *f*(*a*) = *a*, *f*(*c*) = *b*. | ```python
from sys import stdin
def main():
def f(t):
z = 1
for i in range(t, t + 26):
a = (hh[i + le] - hh[i] * k) % mod
if a:
z = z * a % 2147483693
return z
n, m = map(int, input().split())
hh, k = [0] * 52, 1
kk, mod = [1], 2147483659
prn(mod.bit_length())
for i, c in enumerate(input()):
for _ in range(26):
hh.append(hh[-26] * 2)
hh[ord(c) - 123] += 1
k *= 2
if not i & 31:
k %= mod
for j in range(-26, 0):
hh[j] %= mod
kk.append(k)
l = stdin.read().splitlines()
for i, xyle in enumerate(l):
x, y, le = map(int, xyle.split())
k = kk[le]
le *= 26
l[i] = ('NO', 'YES')[f(x * 26) == f(y * 26)]
print('\n'.join(l))
if __name__ == '__main__':
main()
``` | -1 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,683,915,528 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n,m,a = [int(i) for i in input().split()]
answer = 0
if n % a != 0:
answer += n//a+1
else:
answer += n //a
if m % a != 0:
answer += m//a+1
else:
answer += m //a
print (answer)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n,m,a = [int(i) for i in input().split()]
answer = 0
if n % a != 0:
answer += n//a+1
else:
answer += n //a
if m % a != 0:
answer += m//a+1
else:
answer += m //a
print (answer)
``` | 0 |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000",
"output": "1"
},
{
"input": "12345 67890123456789123457",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158",
"output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158"
},
{
"input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751",
"output": "1"
},
{
"input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794",
"output": "1"
},
{
"input": "10000 1000000000",
"output": "1"
},
{
"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "11210171722243 65715435710585778347",
"output": "1"
},
{
"input": "2921881079263974825226940825843 767693191032295360887755303860323261471",
"output": "1"
},
{
"input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085",
"output": "1"
},
{
"input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424",
"output": "1"
},
{
"input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614",
"output": "1"
},
{
"input": "15943150466658398903 15943150466658398903",
"output": "15943150466658398903"
},
{
"input": "410470228200245407491525399055972 410470228200245407491525399055972",
"output": "410470228200245407491525399055972"
},
{
"input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307",
"output": "51894705655711504622197349350106792045098781545973899451307"
},
{
"input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410",
"output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410"
},
{
"input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535",
"output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535"
},
{
"input": "1 2000000000",
"output": "1"
},
{
"input": "13 1928834874",
"output": "1"
},
{
"input": "87 2938984237482934238",
"output": "1"
},
{
"input": "213 413",
"output": "1"
},
{
"input": "3 4",
"output": "1"
}
] | 1,667,549,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a,b = map(int,input().split())
def GCD(a,b):
if b == 0:
return a
return GCD(b,a%b)
print(GCD(a,b)) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output Specification:
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
Demo Input:
['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n']
Demo Output:
['1\n', '61803398874989484820458683436563811772030917980576\n']
Note:
none | ```python
a,b = map(int,input().split())
def GCD(a,b):
if b == 0:
return a
return GCD(b,a%b)
print(GCD(a,b))
``` | 0 |
|
713 | A | Sonya and Queries | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not. | The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform.
Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=<<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it. | For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time. | [
"12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n",
"4\n+ 200\n+ 200\n- 200\n? 0\n"
] | [
"2\n1\n2\n1\n1\n",
"1\n"
] | Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000. | 500 | [
{
"input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0",
"output": "2\n1\n2\n1\n1"
},
{
"input": "4\n+ 200\n+ 200\n- 200\n? 0",
"output": "1"
},
{
"input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00",
"output": "3\n2\n3\n4\n4\n2\n2"
},
{
"input": "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\n? 11\n- 50\n? 10\n? 1\n- 9\n? 1\n? 11\n- 79\n? 11",
"output": "0\n1\n0\n2\n1\n0\n1\n0\n1\n0"
},
{
"input": "10\n+ 870566619432760298\n+ 869797178280285214\n+ 609920823721618090\n+ 221159591436767023\n+ 730599542279836538\n? 101001100111001011\n? 001111010101010011\n? 100010100011101110\n? 100110010110001100\n? 110000011101110011",
"output": "0\n0\n0\n0\n0"
},
{
"input": "10\n+ 96135\n? 10111\n+ 63322\n? 10111\n+ 44490\n? 10111\n+ 69312\n? 10111\n? 01100\n+ 59396",
"output": "1\n1\n1\n1\n1"
},
{
"input": "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011",
"output": "1\n1"
},
{
"input": "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29",
"output": "1\n1\n1\n1\n1\n1\n1\n1"
}
] | 1,696,055,332 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 1,331,200 | from collections import defaultdict
d=defaultdict(lambda:-1)
dd=defaultdict(lambda:0)
def check(x,s):
x=str(x)
lx=len(x)
ls=len(s)
if lx>ls:
s="0"*(lx-ls)+s
elif ls>lx:
x="0"*(ls-lx)+x
# print(x,s)
if x==s:
return True
else:
return False
for _ in range(int(input())):
s=input()
# print(dict(d))
if s[0]=='+':
x=s[2::]
xx=""
for i in x:
if int(i)%2==0:
xx+="0"
else:
xx+="1"
d[x]=xx
dd[x]+=1
elif s[0]=='-':
x=s[2::]
dd[x]-=1
else:
# print(dict(d))
c=0
for i,j in d.items():
if dd[i]<=0:
continue
if check(j,s[2::]):
c+=1*dd[i]
print(c) | Title: Sonya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input Specification:
The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform.
Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=<<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output Specification:
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Demo Input:
['12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n', '4\n+ 200\n+ 200\n- 200\n? 0\n']
Demo Output:
['2\n1\n2\n1\n1\n', '1\n']
Note:
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000. | ```python
from collections import defaultdict
d=defaultdict(lambda:-1)
dd=defaultdict(lambda:0)
def check(x,s):
x=str(x)
lx=len(x)
ls=len(s)
if lx>ls:
s="0"*(lx-ls)+s
elif ls>lx:
x="0"*(ls-lx)+x
# print(x,s)
if x==s:
return True
else:
return False
for _ in range(int(input())):
s=input()
# print(dict(d))
if s[0]=='+':
x=s[2::]
xx=""
for i in x:
if int(i)%2==0:
xx+="0"
else:
xx+="1"
d[x]=xx
dd[x]+=1
elif s[0]=='-':
x=s[2::]
dd[x]-=1
else:
# print(dict(d))
c=0
for i,j in d.items():
if dd[i]<=0:
continue
if check(j,s[2::]):
c+=1*dd[i]
print(c)
``` | 0 |
|
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output": "I hate that I love that I hate that I love that I hate it"
},
{
"input": "10",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "18",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "19",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "76",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "77",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "81",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "82",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "85",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "86",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "99",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "98",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "33",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "34",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "57",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
}
] | 1,692,696,203 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | def hulk(n):
if n == 1:
return "I hate it"
feel = hulk(n - 1)
if n % 2 == 0:
return feel.replace("it", "that I love it")
else:
return feel.replace("it", "that I hate it")
n = int(input())
result = hulk(n)
print(result)
| Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
def hulk(n):
if n == 1:
return "I hate it"
feel = hulk(n - 1)
if n % 2 == 0:
return feel.replace("it", "that I love it")
else:
return feel.replace("it", "that I hate it")
n = int(input())
result = hulk(n)
print(result)
``` | 3 |
|
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*. | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only. | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages. | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na",
"output": "kudljmxcse"
},
{
"input": "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm",
"output": "ntqwpadm"
},
{
"input": "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt",
"output": "aflb"
},
{
"input": "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb",
"output": "dzwzyji"
},
{
"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\n1\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn",
"output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg"
},
{
"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\n1\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb",
"output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb"
},
{
"input": "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld",
"output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld"
}
] | 1,537,335,987 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 218 | 0 | n=input()
k=len(n)
ta=[]
p=int(input())
for x in range(p):
ol=input()
if ol[0:k]==n:
ta.append(ol[k:])
else:
pass
if ta==list():
print(n)
else:
ta.sort()
print(n+ta[0]) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*.
Input Specification:
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
Output Specification:
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
Demo Input:
['next\n2\nnextpermutation\nnextelement\n', 'find\n4\nfind\nfindfirstof\nfindit\nfand\n', 'find\n4\nfondfind\nfondfirstof\nfondit\nfand\n']
Demo Output:
['nextelement\n', 'find\n', 'find\n']
Note:
none | ```python
n=input()
k=len(n)
ta=[]
p=int(input())
for x in range(p):
ol=input()
if ol[0:k]==n:
ta.append(ol[k:])
else:
pass
if ta==list():
print(n)
else:
ta.sort()
print(n+ta[0])
``` | 3.9455 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,666,098,127 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | m, n = [int(x) for x in input().split()]
print("%.0f"%((m*n)/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m, n = [int(x) for x in input().split()]
print("%.0f"%((m*n)/2))
``` | 0 |
Subsets and Splits