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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 1,692,290,330 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | x=input()
if "1" in x:
n=x.index('1')
x=x[:n]+x[n+1:]
if "14" in x:
print("YES")
elif "144" in x:
print("YES")
else:
print("NO")
elif "14" in x:
n=x.index('14')
x=x[:n]+x[n+2:]
if "1" in x:
print("YES")
elif "144" in x:
print("YES")
else:
print("NO")
elif "144" in x:
n=x.index('144')
x=x[:n]+x[n+3:]
if "1" in x:
print("YES")
elif "14" in x:
print("YES")
else:
print("NO")
else:
print("NO") | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input Specification:
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Output Specification:
Print "YES" if *n* is a magic number or print "NO" if it's not.
Demo Input:
['114114\n', '1111\n', '441231\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
x=input()
if "1" in x:
n=x.index('1')
x=x[:n]+x[n+1:]
if "14" in x:
print("YES")
elif "144" in x:
print("YES")
else:
print("NO")
elif "14" in x:
n=x.index('14')
x=x[:n]+x[n+2:]
if "1" in x:
print("YES")
elif "144" in x:
print("YES")
else:
print("NO")
elif "144" in x:
n=x.index('144')
x=x[:n]+x[n+3:]
if "1" in x:
print("YES")
elif "14" in x:
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
|
1,010 | C | Border | PROGRAMMING | 1,800 | [
"number theory"
] | null | null | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination.
Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.
Determine for which values $d$ Natasha can make the Martians happy.
Natasha can use only her banknotes. Martians don't give her change. | The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars.
All numbers are given in decimal notation. | On the first line output the number of values $d$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation. | [
"2 8\n12 20\n",
"3 10\n10 20 30\n"
] | [
"2\n0 4 ",
"1\n0 "
] | Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$.
If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it is $40_8$. The last digit is $0_8$.
If you take two banknotes with the value of $20$, the total value will be $40$, this is $50_8$ in the octal system. The last digit is $0_8$.
No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_8$ could also be obtained in other ways.
The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero. | 1,000 | [
{
"input": "2 8\n12 20",
"output": "2\n0 4 "
},
{
"input": "3 10\n10 20 30",
"output": "1\n0 "
},
{
"input": "5 10\n20 16 4 16 2",
"output": "5\n0 2 4 6 8 "
},
{
"input": "10 5\n4 6 8 6 4 10 2 10 8 6",
"output": "5\n0 1 2 3 4 "
},
{
"input": "20 25\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 20 20 20",
"output": "5\n0 5 10 15 20 "
},
{
"input": "30 30\n11 23 7 30 13 6 25 29 1 15 20 5 28 15 19 22 21 5 27 25 29 10 1 4 12 19 1 5 8 10",
"output": "30\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 "
},
{
"input": "40 30\n16 12 12 22 18 28 32 24 36 26 12 30 22 16 32 30 36 18 20 16 12 24 28 20 16 28 8 34 18 18 18 4 4 36 18 10 30 38 18 10",
"output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 "
},
{
"input": "50 30\n15 9 21 39 42 39 3 42 42 39 6 48 39 30 12 39 27 45 30 48 18 33 18 36 27 3 48 12 36 27 15 12 42 39 18 21 48 39 15 42 24 36 33 48 6 48 15 12 30 18",
"output": "10\n0 3 6 9 12 15 18 21 24 27 "
},
{
"input": "1 10\n1",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 2\n1",
"output": "2\n0 1 "
},
{
"input": "60 30\n10 30 45 15 25 60 10 40 35 25 5 40 35 40 15 5 15 35 10 60 25 15 60 10 30 10 5 25 10 15 60 20 30 5 50 50 40 20 55 40 35 15 15 10 60 40 50 50 30 15 25 45 35 40 15 5 5 20 60 45",
"output": "6\n0 5 10 15 20 25 "
},
{
"input": "70 30\n54 30 12 48 42 24 42 60 54 6 36 42 54 66 12 48 54 42 24 54 30 18 30 54 18 60 24 30 54 48 48 60 18 60 60 66 54 18 54 30 24 30 60 54 36 36 60 48 12 60 6 60 42 66 6 42 18 60 54 48 42 18 48 66 18 42 48 30 12 66",
"output": "5\n0 6 12 18 24 "
},
{
"input": "80 30\n30 80 40 40 60 60 40 80 70 80 30 30 60 80 30 70 60 10 10 30 70 60 70 20 40 20 30 10 60 70 70 50 60 70 70 30 70 60 60 70 20 60 10 60 70 80 20 30 30 20 60 50 40 40 80 70 70 20 40 80 30 50 40 10 40 20 70 10 80 10 50 40 50 70 40 80 10 40 60 60",
"output": "3\n0 10 20 "
},
{
"input": "90 30\n90 45 75 75 90 90 45 30 90 15 45 90 15 30 45 60 30 15 30 45 45 45 45 15 45 60 15 60 45 75 45 75 90 60 30 15 60 30 90 75 15 60 15 30 45 30 45 15 30 15 45 30 15 75 90 15 45 15 75 15 75 30 75 45 60 75 15 45 30 75 45 90 45 60 90 45 75 30 30 30 15 15 75 60 75 90 75 60 90 45",
"output": "2\n0 15 "
},
{
"input": "100 30\n30 30 30 90 30 30 90 90 30 90 30 90 90 30 30 30 60 60 60 30 30 60 90 90 90 60 30 90 60 60 90 60 60 60 30 60 60 60 60 90 60 30 60 90 90 90 60 60 90 60 60 60 60 30 30 60 30 60 60 90 30 60 60 60 90 60 90 30 30 60 30 90 90 90 90 60 90 30 30 60 60 30 60 60 60 30 90 60 60 60 90 60 30 90 60 30 30 60 90 90",
"output": "1\n0 "
},
{
"input": "1 10\n2",
"output": "5\n0 2 4 6 8 "
},
{
"input": "1 10\n3",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "5 2\n1 1 1 1 1",
"output": "2\n0 1 "
},
{
"input": "2 30\n6 10",
"output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 "
},
{
"input": "1 10\n10",
"output": "1\n0 "
},
{
"input": "1 10\n20",
"output": "1\n0 "
},
{
"input": "1 2\n1000000000",
"output": "1\n0 "
},
{
"input": "2 6\n2 3",
"output": "6\n0 1 2 3 4 5 "
},
{
"input": "1 5\n4",
"output": "5\n0 1 2 3 4 "
},
{
"input": "2 5\n2 4",
"output": "5\n0 1 2 3 4 "
},
{
"input": "3 30\n6 10 15",
"output": "30\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 "
},
{
"input": "2 7\n3 6",
"output": "7\n0 1 2 3 4 5 6 "
},
{
"input": "2 15\n3 5",
"output": "15\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 "
},
{
"input": "2 12\n4 6",
"output": "6\n0 2 4 6 8 10 "
},
{
"input": "2 10\n3 6",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "2 100000\n2 4",
"output": "50000\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278..."
},
{
"input": "1 14\n4",
"output": "7\n0 2 4 6 8 10 12 "
},
{
"input": "1 13\n5",
"output": "13\n0 1 2 3 4 5 6 7 8 9 10 11 12 "
},
{
"input": "2 420\n412 363",
"output": "420\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "2 30\n10 6",
"output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 "
},
{
"input": "1 5\n3",
"output": "5\n0 1 2 3 4 "
},
{
"input": "1 8\n6",
"output": "4\n0 2 4 6 "
},
{
"input": "3 10\n6 6 6",
"output": "5\n0 2 4 6 8 "
},
{
"input": "1 7\n6",
"output": "7\n0 1 2 3 4 5 6 "
},
{
"input": "1 9\n6",
"output": "3\n0 3 6 "
},
{
"input": "2 10\n7 7",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 8\n5",
"output": "8\n0 1 2 3 4 5 6 7 "
},
{
"input": "2 50\n3 15",
"output": "50\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 "
},
{
"input": "1 6\n4",
"output": "3\n0 2 4 "
},
{
"input": "1 7\n4",
"output": "7\n0 1 2 3 4 5 6 "
},
{
"input": "1 10\n7",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 3\n2",
"output": "3\n0 1 2 "
},
{
"input": "2 10\n2 5",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "2 50\n15 3",
"output": "50\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 "
},
{
"input": "1 5\n2",
"output": "5\n0 1 2 3 4 "
},
{
"input": "2 10\n6 5",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "2 35\n5 7",
"output": "35\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 "
},
{
"input": "2 300\n3 10",
"output": "300\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 100000\n47",
"output": "100000\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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": "2 54\n6 9",
"output": "18\n0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 "
}
] | 1,577,721,493 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 155 | 0 | import math as M
n,k=list(int(i) for i in input().split())
A=list(int(i) for i in input().split())
B=[]
if(n>=2):
g=M.gcd(A[0],A[1])
else:
g=A[0]
for i in range(n):
g=M.gcd(A[i],g)
for j in range(k+1):
d=(g*j)%k
if d not in B:
B.append(d)
#B.sort()
print(len(B))
print(*B)
| Title: Border
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination.
Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.
Determine for which values $d$ Natasha can make the Martians happy.
Natasha can use only her banknotes. Martians don't give her change.
Input Specification:
The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars.
All numbers are given in decimal notation.
Output Specification:
On the first line output the number of values $d$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation.
Demo Input:
['2 8\n12 20\n', '3 10\n10 20 30\n']
Demo Output:
['2\n0 4 ', '1\n0 ']
Note:
Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$.
If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it is $40_8$. The last digit is $0_8$.
If you take two banknotes with the value of $20$, the total value will be $40$, this is $50_8$ in the octal system. The last digit is $0_8$.
No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_8$ could also be obtained in other ways.
The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero. | ```python
import math as M
n,k=list(int(i) for i in input().split())
A=list(int(i) for i in input().split())
B=[]
if(n>=2):
g=M.gcd(A[0],A[1])
else:
g=A[0]
for i in range(n):
g=M.gcd(A[i],g)
for j in range(k+1):
d=(g*j)%k
if d not in B:
B.append(d)
#B.sort()
print(len(B))
print(*B)
``` | 0 |
|
887 | C | Solution for Cube | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube | In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence. | Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise. | [
"2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n"
] | [
"NO",
"YES"
] | In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | 1,500 | [
{
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4",
"output": "NO"
},
{
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3",
"output": "YES"
},
{
"input": "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1",
"output": "NO"
},
{
"input": "3 4 2 3 5 5 6 6 4 5 4 6 5 1 1 1 6 2 1 3 3 2 4 2",
"output": "NO"
},
{
"input": "5 5 2 5 3 3 2 6 6 4 2 4 6 1 4 3 1 6 2 1 3 4 5 1",
"output": "NO"
},
{
"input": "6 6 1 2 6 1 1 3 5 4 3 4 3 5 5 2 4 4 6 2 1 5 3 2",
"output": "NO"
},
{
"input": "2 2 1 1 5 5 5 5 3 3 4 4 1 4 1 4 2 3 2 3 6 6 6 6",
"output": "YES"
},
{
"input": "1 1 1 1 5 5 3 3 4 4 4 4 3 3 2 2 6 6 5 5 2 2 6 6",
"output": "YES"
},
{
"input": "1 1 1 1 3 3 3 3 5 5 5 5 2 2 2 2 4 4 4 4 6 6 6 6",
"output": "NO"
},
{
"input": "5 4 5 4 4 6 4 6 6 3 6 3 1 1 1 1 2 2 2 2 5 3 5 3",
"output": "YES"
},
{
"input": "3 3 5 5 2 2 2 2 6 6 4 4 6 3 6 3 4 5 4 5 1 1 1 1",
"output": "YES"
},
{
"input": "6 6 6 6 2 2 5 5 1 1 1 1 4 4 2 2 5 5 3 3 3 3 4 4",
"output": "YES"
},
{
"input": "4 6 4 6 6 1 6 1 1 3 1 3 2 2 2 2 5 5 5 5 4 3 4 3",
"output": "YES"
},
{
"input": "6 6 2 2 3 3 3 3 4 4 5 5 4 6 4 6 5 2 5 2 1 1 1 1",
"output": "YES"
},
{
"input": "3 3 3 3 4 4 5 5 1 1 1 1 2 2 4 4 5 5 6 6 6 6 2 2",
"output": "YES"
},
{
"input": "2 5 2 5 4 2 4 2 1 4 1 4 6 6 6 6 3 3 3 3 1 5 1 5",
"output": "YES"
},
{
"input": "4 4 3 3 5 5 5 5 1 1 6 6 3 6 3 6 4 1 4 1 2 2 2 2",
"output": "YES"
},
{
"input": "5 5 5 5 6 6 2 2 3 3 3 3 2 2 1 1 4 4 6 6 1 1 4 4",
"output": "YES"
},
{
"input": "1 4 3 4 2 6 5 2 1 5 1 6 3 4 3 6 5 5 1 3 2 6 4 2",
"output": "NO"
},
{
"input": "4 4 2 5 3 2 4 2 5 3 6 4 6 5 1 3 1 5 6 3 1 1 6 2",
"output": "NO"
},
{
"input": "4 5 3 4 5 5 6 3 2 5 1 6 2 1 6 3 1 4 2 3 2 6 1 4",
"output": "NO"
},
{
"input": "3 3 2 3 6 4 4 4 1 2 1 3 2 5 6 6 1 2 6 5 4 5 1 5",
"output": "NO"
},
{
"input": "5 6 1 1 4 5 6 5 4 6 2 1 4 2 6 5 3 2 3 2 3 1 3 4",
"output": "NO"
},
{
"input": "4 4 4 5 2 3 4 1 3 3 1 5 6 5 6 6 1 3 6 2 5 2 1 2",
"output": "NO"
},
{
"input": "3 2 5 6 1 4 3 4 6 5 4 3 2 3 2 2 1 4 1 1 6 5 6 5",
"output": "NO"
},
{
"input": "5 4 6 2 5 6 4 1 6 3 3 1 3 2 4 1 1 6 2 3 5 2 4 5",
"output": "NO"
},
{
"input": "6 6 3 1 5 6 5 3 2 5 3 1 2 4 1 6 4 5 2 2 4 1 3 4",
"output": "NO"
},
{
"input": "6 5 4 1 6 5 2 3 3 5 3 6 4 2 6 5 4 2 1 1 4 1 3 2",
"output": "NO"
},
{
"input": "1 3 5 6 4 4 4 3 5 2 2 2 3 1 5 6 3 4 6 5 1 2 1 6",
"output": "NO"
},
{
"input": "3 6 5 4 4 6 1 4 3 2 5 2 1 2 6 2 5 4 1 3 1 6 5 3",
"output": "NO"
},
{
"input": "5 2 6 1 5 3 5 3 1 1 3 6 6 2 4 2 5 4 4 2 1 3 4 6",
"output": "NO"
},
{
"input": "2 5 6 2 3 6 5 6 2 3 1 3 6 4 5 4 1 1 1 5 3 4 4 2",
"output": "NO"
},
{
"input": "4 5 4 4 3 3 1 2 3 1 1 5 2 2 5 6 6 4 3 2 6 5 1 6",
"output": "NO"
},
{
"input": "5 2 5 2 3 5 3 5 4 3 4 3 6 6 6 6 1 1 1 1 4 2 4 2",
"output": "YES"
},
{
"input": "2 4 2 4 4 5 4 5 5 1 5 1 3 3 3 3 6 6 6 6 2 1 2 1",
"output": "YES"
},
{
"input": "3 5 3 5 5 1 5 1 1 4 1 4 6 6 6 6 2 2 2 2 3 4 3 4",
"output": "YES"
},
{
"input": "2 1 2 1 4 2 4 2 6 4 6 4 5 5 5 5 3 3 3 3 6 1 6 1",
"output": "YES"
},
{
"input": "4 4 2 2 1 1 1 1 5 5 6 6 2 6 2 6 4 5 4 5 3 3 3 3",
"output": "YES"
},
{
"input": "1 1 2 2 4 4 4 4 5 5 6 6 5 1 5 1 6 2 6 2 3 3 3 3",
"output": "YES"
},
{
"input": "2 2 6 6 4 4 4 4 1 1 5 5 1 2 1 2 5 6 5 6 3 3 3 3",
"output": "YES"
},
{
"input": "2 2 3 3 6 6 6 6 4 4 1 1 3 1 3 1 2 4 2 4 5 5 5 5",
"output": "YES"
},
{
"input": "6 6 6 6 4 4 3 3 5 5 5 5 3 3 1 1 2 2 4 4 1 1 2 2",
"output": "YES"
},
{
"input": "2 2 2 2 4 4 5 5 3 3 3 3 6 6 4 4 5 5 1 1 1 1 6 6",
"output": "YES"
},
{
"input": "1 1 1 1 5 5 6 6 3 3 3 3 4 4 5 5 6 6 2 2 2 2 4 4",
"output": "YES"
},
{
"input": "4 4 4 4 2 2 3 3 1 1 1 1 3 3 6 6 5 5 2 2 6 6 5 5",
"output": "YES"
},
{
"input": "1 1 1 1 2 2 3 3 6 6 6 6 5 5 4 4 3 3 2 2 4 4 5 5",
"output": "NO"
},
{
"input": "1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5 6 6 6 6",
"output": "NO"
},
{
"input": "5 5 5 5 1 1 2 2 6 6 6 6 4 4 3 3 3 3 4 4 2 2 1 1",
"output": "NO"
}
] | 1,509,732,256 | 7,156 | Python 3 | WRONG_ANSWER | PRETESTS | 8 | 61 | 0 | a = list( map( int, input().split() ) )
pos = [ [3,4,17,19,9,10,14,16],
[ 13,15,11,12,18,20,1,2],
[2,4,6,8,10,12,21,23],
[1,3,5,7,9,11,22,24]]
for j in range( len(pos) ):
tmp = []
for i in range( len( pos[j] ) ):
tmp.append( a[ pos[j][i]-1 ] )
L = set( tmp )
for i in L:
if tmp.count( i ) > 2:
print( "NO" )
exit(0)
#print( tmp )
for i in range( 0, len(a), 4 ):
x = a[i:i+4]
#print( x )
if x[0] == x[2] and x[1] != x[3]:
print( "NO" )
exit(0)
if x[0] != x[2] and x[1] == x[3]:
print( "NO" )
exit(0)
if x[0] == x[3] and x[1] != x[2]:
print( "NO" )
exit(0)
if x[1] == x[2] and x[0] != x[3]:
print( "NO" )
exit(0)
x = sorted( x )
if len( x ) != 4:
print( "NO" )
exit(0)
if x[0] == x[1] and x[1] == x[2] and x[2] != x[2]:
print( "NO" )
exit(0)
if x[0] != x[1] and x[1] == x[2] and x[2] == x[2]:
print( "NO" )
exit(0)
print( "YES" ) | Title: Solution for Cube
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
Input Specification:
In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence.
Output Specification:
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
Demo Input:
['2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n', '5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n']
Demo Output:
['NO', 'YES']
Note:
In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | ```python
a = list( map( int, input().split() ) )
pos = [ [3,4,17,19,9,10,14,16],
[ 13,15,11,12,18,20,1,2],
[2,4,6,8,10,12,21,23],
[1,3,5,7,9,11,22,24]]
for j in range( len(pos) ):
tmp = []
for i in range( len( pos[j] ) ):
tmp.append( a[ pos[j][i]-1 ] )
L = set( tmp )
for i in L:
if tmp.count( i ) > 2:
print( "NO" )
exit(0)
#print( tmp )
for i in range( 0, len(a), 4 ):
x = a[i:i+4]
#print( x )
if x[0] == x[2] and x[1] != x[3]:
print( "NO" )
exit(0)
if x[0] != x[2] and x[1] == x[3]:
print( "NO" )
exit(0)
if x[0] == x[3] and x[1] != x[2]:
print( "NO" )
exit(0)
if x[1] == x[2] and x[0] != x[3]:
print( "NO" )
exit(0)
x = sorted( x )
if len( x ) != 4:
print( "NO" )
exit(0)
if x[0] == x[1] and x[1] == x[2] and x[2] != x[2]:
print( "NO" )
exit(0)
if x[0] != x[1] and x[1] == x[2] and x[2] == x[2]:
print( "NO" )
exit(0)
print( "YES" )
``` | 0 |
|
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,659,435,815 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | x,y=input().split()
M=int(x)
N=int(y)
print((x*y)/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
x,y=input().split()
M=int(x)
N=int(y)
print((x*y)/2)
``` | -1 |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 6"
},
{
"input": "5\n1 1 1 1 1",
"output": "0 10"
},
{
"input": "5\n2 2 2 2 2",
"output": "0 10"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0 45"
},
{
"input": "3\n2 2 2",
"output": "0 3"
},
{
"input": "3\n3 3 3",
"output": "0 3"
},
{
"input": "2\n10000000 100000000",
"output": "90000000 1"
},
{
"input": "5\n5 5 5 5 5",
"output": "0 10"
},
{
"input": "5\n3 3 3 3 3",
"output": "0 10"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0 15"
},
{
"input": "2\n5 6",
"output": "1 1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0 45"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0 45"
},
{
"input": "4\n4 4 4 4",
"output": "0 6"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0 21"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "0 55"
},
{
"input": "8\n8 8 8 8 8 8 8 8",
"output": "0 28"
},
{
"input": "2\n3 2",
"output": "1 1"
}
] | 1,674,627,372 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 3 | 1,263 | 268,390,400 | n=int(input())
l=list(map(int,input().split( )))
maxi=max(l)
mini=min(l)
dif=maxi-mini
f=[0 for i in range(n) for j in range(n) if i!=j and l[i]-l[j]==dif]
print(dif,len(f)) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
Input Specification:
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
Output Specification:
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Demo Input:
['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n']
Demo Output:
['1 1', '4 1', '2 4']
Note:
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | ```python
n=int(input())
l=list(map(int,input().split( )))
maxi=max(l)
mini=min(l)
dif=maxi-mini
f=[0 for i in range(n) for j in range(n) if i!=j and l[i]-l[j]==dif]
print(dif,len(f))
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,663,834,607 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | x,y,z=0
n=int(input())
for i in range(n):
u=int(input())
x+=int(u[1])
y+=int(u[2])
z+=int(u[3])
if x**2+y**2+z**2 == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
x,y,z=0
n=int(input())
for i in range(n):
u=int(input())
x+=int(u[1])
y+=int(u[2])
z+=int(u[3])
if x**2+y**2+z**2 == 0:
print("YES")
else:
print("NO")
``` | -1 |
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=><=1 is not prime, it's called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".
For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.
When you are done asking queries, print "prime" or "composite" and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.
You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below). | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.
To flush you can use (just after printing an integer and end-of-line):
- fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages.
Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input. | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/>
59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries). | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
},
{
"input": "55",
"output": "composite 6"
},
{
"input": "89",
"output": "prime 15"
},
{
"input": "3",
"output": "prime 16"
},
{
"input": "4",
"output": "composite 2"
},
{
"input": "6",
"output": "composite 4"
},
{
"input": "8",
"output": "composite 2"
},
{
"input": "11",
"output": "prime 15"
},
{
"input": "12",
"output": "composite 2"
},
{
"input": "25",
"output": "composite 4"
},
{
"input": "36",
"output": "composite 2"
},
{
"input": "46",
"output": "composite 10"
},
{
"input": "47",
"output": "prime 15"
},
{
"input": "49",
"output": "composite 5"
},
{
"input": "51",
"output": "composite 8"
},
{
"input": "53",
"output": "prime 15"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "64",
"output": "composite 2"
},
{
"input": "81",
"output": "composite 3"
},
{
"input": "91",
"output": "composite 7"
},
{
"input": "93",
"output": "composite 12"
},
{
"input": "94",
"output": "composite 16"
},
{
"input": "95",
"output": "composite 9"
},
{
"input": "96",
"output": "composite 2"
},
{
"input": "97",
"output": "prime 15"
},
{
"input": "99",
"output": "composite 3"
},
{
"input": "100",
"output": "composite 2"
},
{
"input": "26",
"output": "composite 7"
},
{
"input": "94",
"output": "composite 16"
},
{
"input": "25",
"output": "composite 4"
},
{
"input": "46",
"output": "composite 10"
},
{
"input": "49",
"output": "composite 5"
},
{
"input": "82",
"output": "composite 14"
},
{
"input": "87",
"output": "composite 11"
},
{
"input": "85",
"output": "composite 8"
},
{
"input": "74",
"output": "composite 13"
},
{
"input": "86",
"output": "composite 15"
},
{
"input": "93",
"output": "composite 12"
},
{
"input": "58",
"output": "composite 11"
},
{
"input": "47",
"output": "prime 15"
},
{
"input": "22",
"output": "composite 6"
},
{
"input": "23",
"output": "prime 15"
},
{
"input": "62",
"output": "composite 12"
},
{
"input": "38",
"output": "composite 9"
},
{
"input": "91",
"output": "composite 7"
},
{
"input": "34",
"output": "composite 8"
},
{
"input": "95",
"output": "composite 9"
},
{
"input": "4",
"output": "composite 2"
},
{
"input": "16",
"output": "composite 2"
},
{
"input": "96",
"output": "composite 2"
},
{
"input": "69",
"output": "composite 10"
},
{
"input": "65",
"output": "composite 7"
},
{
"input": "6",
"output": "composite 4"
},
{
"input": "18",
"output": "composite 4"
}
] | 1,698,245,230 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 16 | 77 | 0 | from sys import stdout
ans = 0
for i in range(2,19):
print(i)
stdout.flush()
s = input()
if s =="yes":
ans += 1
print(25)
stdout.flush()
s = input()
if s == "yes":
ans += 1
print(49)
stdout.flush()
s = input()
if s == "yes":
ans += 1
if ans>1:
print("composite")
else:
print("prime") | Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=><=1 is not prime, it's called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".
For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.
When you are done asking queries, print "prime" or "composite" and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.
You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).
Input Specification:
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Output Specification:
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.
To flush you can use (just after printing an integer and end-of-line):
- fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages.
Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input.
Demo Input:
['yes\nno\nyes\n', 'no\nyes\nno\nno\nno\n']
Demo Output:
['2\n80\n5\ncomposite\n', '58\n59\n78\n78\n2\nprime\n']
Note:
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/>
59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries). | ```python
from sys import stdout
ans = 0
for i in range(2,19):
print(i)
stdout.flush()
s = input()
if s =="yes":
ans += 1
print(25)
stdout.flush()
s = input()
if s == "yes":
ans += 1
print(49)
stdout.flush()
s = input()
if s == "yes":
ans += 1
if ans>1:
print("composite")
else:
print("prime")
``` | 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,678,679,818 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, m, a = map(int, input().split())
print(ceil(n // a) * ceil(m // a)) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n, m, a = map(int, input().split())
print(ceil(n // a) * ceil(m // a))
``` | -1 |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,556,612,971 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 0 | #!/usr/bin/env python3
def main():
desc = set()
brand = [0] * 1001
proc = [0] * 1001
tb = [False] * 1001
n = int(input())
total = n
for i in range(n):
a, b = map(int, input().split())
desc.add(a)
brand[a] += 1
proc[b] += 1
tb[b] |= True if a != b else False
for a in desc:
if (tb[a] or proc[a] > 1):
total -= brand[a]
elif proc[a]:
total -= brand[a] - 1
print(total)
if __name__ == "__main__":
main()
| Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none | ```python
#!/usr/bin/env python3
def main():
desc = set()
brand = [0] * 1001
proc = [0] * 1001
tb = [False] * 1001
n = int(input())
total = n
for i in range(n):
a, b = map(int, input().split())
desc.add(a)
brand[a] += 1
proc[b] += 1
tb[b] |= True if a != b else False
for a in desc:
if (tb[a] or proc[a] > 1):
total -= brand[a]
elif proc[a]:
total -= brand[a] - 1
print(total)
if __name__ == "__main__":
main()
``` | 3 |
|
371 | B | Fox Dividing Cheese | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal. | The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109). | If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. | [
"15 20\n",
"14 8\n",
"6 6\n"
] | [
"3\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "15 20",
"output": "3"
},
{
"input": "14 8",
"output": "-1"
},
{
"input": "6 6",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1024",
"output": "10"
},
{
"input": "1024 729",
"output": "16"
},
{
"input": "1024 1048576",
"output": "10"
},
{
"input": "36 30",
"output": "3"
},
{
"input": "100 10",
"output": "2"
},
{
"input": "21 35",
"output": "2"
},
{
"input": "9900 7128",
"output": "5"
},
{
"input": "7920 9900",
"output": "3"
},
{
"input": "576000 972000",
"output": "7"
},
{
"input": "691200 583200",
"output": "8"
},
{
"input": "607500 506250",
"output": "3"
},
{
"input": "881280 765000",
"output": "9"
},
{
"input": "800000 729000",
"output": "13"
},
{
"input": "792000 792000",
"output": "0"
},
{
"input": "513600 513600",
"output": "0"
},
{
"input": "847500 610200",
"output": "5"
},
{
"input": "522784320 784176480",
"output": "2"
},
{
"input": "689147136 861433920",
"output": "3"
},
{
"input": "720212000 864254400",
"output": "3"
},
{
"input": "673067520 807681024",
"output": "3"
},
{
"input": "919536000 993098880",
"output": "5"
},
{
"input": "648293430 540244525",
"output": "3"
},
{
"input": "537814642 537814642",
"output": "0"
},
{
"input": "100000007 800000011",
"output": "-1"
},
{
"input": "900000011 800000011",
"output": "-1"
},
{
"input": "900000011 999900017",
"output": "-1"
},
{
"input": "536870912 387420489",
"output": "47"
},
{
"input": "820125000 874800000",
"output": "6"
},
{
"input": "864000000 607500000",
"output": "9"
},
{
"input": "609120000 913680000",
"output": "2"
},
{
"input": "509607936 306110016",
"output": "24"
},
{
"input": "445906944 528482304",
"output": "8"
},
{
"input": "119144448 423624704",
"output": "7"
},
{
"input": "1 1000000000",
"output": "18"
},
{
"input": "1000000000 1",
"output": "18"
},
{
"input": "1000000000 2",
"output": "17"
},
{
"input": "2 1000000000",
"output": "17"
},
{
"input": "5 1000000000",
"output": "17"
},
{
"input": "1000000000 5",
"output": "17"
},
{
"input": "3 1000000000",
"output": "19"
},
{
"input": "1000000000 3",
"output": "19"
},
{
"input": "1000000000 7",
"output": "-1"
},
{
"input": "2208870 122715",
"output": "3"
},
{
"input": "4812500 7577955",
"output": "16"
},
{
"input": "3303936 3097440",
"output": "6"
},
{
"input": "55404 147744",
"output": "4"
},
{
"input": "10332160 476643528",
"output": "19"
},
{
"input": "21751200 43502400",
"output": "1"
},
{
"input": "19500000 140400000",
"output": "5"
},
{
"input": "1 22",
"output": "-1"
}
] | 1,641,873,975 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | a,b=list(map(int,input().split()))
c=[2,3,5]
fa=[0,0,0,0,0]
fb=[0,0,0,0,0]
for k in c:
while a%k==0:
a=a//k
fa[k-1]+=1
for l in c:
while b%l==0:
b=b//l
fb[l-1]+=1
if a!=b:
print(-1)
else:
ans=0
for i in range(5):
ans+=abs(fa[i]-fb[i])
print(ans) | Title: Fox Dividing Cheese
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
Input Specification:
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
Output Specification:
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
Demo Input:
['15 20\n', '14 8\n', '6 6\n']
Demo Output:
['3\n', '-1\n', '0\n']
Note:
none | ```python
a,b=list(map(int,input().split()))
c=[2,3,5]
fa=[0,0,0,0,0]
fb=[0,0,0,0,0]
for k in c:
while a%k==0:
a=a//k
fa[k-1]+=1
for l in c:
while b%l==0:
b=b//l
fb[l-1]+=1
if a!=b:
print(-1)
else:
ans=0
for i in range(5):
ans+=abs(fa[i]-fb[i])
print(ans)
``` | 3 |
|
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence. | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is 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. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "847194127849",
"output": "255708"
},
{
"input": "294719472984",
"output": "593358"
},
{
"input": "999999911791",
"output": "1414213"
},
{
"input": "999999911792",
"output": "1"
},
{
"input": "100000000000000",
"output": "1749820"
},
{
"input": "1",
"output": "1"
},
{
"input": "99993",
"output": "312"
},
{
"input": "99994",
"output": "313"
},
{
"input": "99995",
"output": "314"
},
{
"input": "99990",
"output": "309"
},
{
"input": "2",
"output": "1"
},
{
"input": "99991",
"output": "310"
},
{
"input": "99992",
"output": "311"
},
{
"input": "99996",
"output": "315"
},
{
"input": "99997",
"output": "316"
},
{
"input": "99998",
"output": "317"
},
{
"input": "99999",
"output": "318"
},
{
"input": "1021",
"output": "31"
},
{
"input": "4",
"output": "1"
},
{
"input": "23",
"output": "2"
},
{
"input": "9994",
"output": "124"
},
{
"input": "99939",
"output": "258"
},
{
"input": "99999998250180",
"output": "14142135"
},
{
"input": "6",
"output": "3"
},
{
"input": "8",
"output": "2"
},
{
"input": "35",
"output": "7"
},
{
"input": "100",
"output": "9"
},
{
"input": "10101010",
"output": "745"
},
{
"input": "103",
"output": "12"
},
{
"input": "102",
"output": "11"
},
{
"input": "101",
"output": "10"
}
] | 1,665,561,598 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 62 | 0 | n=int(input())
def is_ok(mid):
if mid*(mid+1)//2<n:
return True
else:
return False
def binary_search(ng,ok):
while abs(ng-ok)>1:
mid=(ok+ng)//2
if is_ok(mid):
ok=mid
else:
ng=mid
return ok
m=binary_search(10**9,0)
print(n-m*(m+1)//2) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence.
Input Specification:
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is 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.
Output Specification:
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
Demo Input:
['3\n', '5\n', '10\n', '55\n', '56\n']
Demo Output:
['2\n', '2\n', '4\n', '10\n', '1\n']
Note:
none | ```python
n=int(input())
def is_ok(mid):
if mid*(mid+1)//2<n:
return True
else:
return False
def binary_search(ng,ok):
while abs(ng-ok)>1:
mid=(ok+ng)//2
if is_ok(mid):
ok=mid
else:
ng=mid
return ok
m=binary_search(10**9,0)
print(n-m*(m+1)//2)
``` | 3 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,688,303,211 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | s = input()
upper_count = s.count("A-Z")
lower_count = s.count("a-z")
if upper_count > lower_count:
print(s.upper())
else:
print(s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s = input()
upper_count = s.count("A-Z")
lower_count = s.count("a-z")
if upper_count > lower_count:
print(s.upper())
else:
print(s.lower())
``` | 0 |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second.
There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible.
The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible? | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer. | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1\n21 25 16",
"output": "25"
},
{
"input": "3 2\n23 20 26",
"output": "23"
},
{
"input": "3 3\n19 29 28",
"output": "19"
},
{
"input": "100 2\n82 37 88 28 98 30 38 76 90 68 79 29 67 93 19 71 122 103 110 79 20 75 68 101 16 120 114 68 73 71 103 114 99 70 73 18 36 31 32 87 32 79 44 72 58 25 44 72 106 38 47 17 83 41 75 23 49 30 73 67 117 52 22 117 109 89 66 88 75 62 17 35 83 69 63 60 23 120 93 18 112 93 39 72 116 109 106 72 27 123 117 119 87 72 33 73 70 110 43 43",
"output": "122"
},
{
"input": "30 13\n36 82 93 91 48 62 59 96 72 40 45 68 97 70 26 22 35 98 92 83 72 49 70 39 53 94 97 65 37 28",
"output": "70"
},
{
"input": "50 49\n20 77 31 40 18 87 44 64 70 48 29 59 98 33 95 17 69 84 81 17 24 66 37 54 97 55 77 79 42 21 23 42 36 55 81 83 94 45 25 84 20 97 37 95 46 92 73 39 90 71",
"output": "17"
},
{
"input": "40 40\n110 674 669 146 882 590 650 844 427 187 380 711 122 94 38 216 414 874 380 31 895 390 414 557 913 68 665 964 895 708 594 17 24 621 780 509 837 550 630 568",
"output": "17"
},
{
"input": "40 1\n851 110 1523 1572 945 4966 4560 756 2373 4760 144 2579 4022 220 1924 1042 160 2792 2425 4483 2154 4120 319 4617 4686 2502 4797 4941 4590 4478 4705 4355 695 684 1560 684 2780 1090 4995 3113",
"output": "4995"
},
{
"input": "70 12\n6321 2502 557 2734 16524 10133 13931 5045 3897 18993 5745 8687 12344 1724 12071 2345 3852 9312 14432 8615 7461 2439 4751 19872 12266 12997 8276 8155 9502 3047 7226 12754 9447 17349 1888 14564 18257 18099 8924 14199 738 13693 10917 15554 15773 17859 13391 13176 10567 19658 16494 3968 13977 14694 10537 4044 16402 9714 4425 13599 19660 2426 19687 2455 2382 3413 5754 113 7542 8353",
"output": "16402"
},
{
"input": "80 60\n6159 26457 23753 27073 9877 4492 11957 10989 27151 6552 1646 7773 23924 27554 10517 8788 31160 455 12625 22009 22133 15657 14968 31871 15344 16550 27414 876 31213 10895 21508 17516 12747 59 11786 10497 30143 25548 22003 2809 11694 30395 8122 31248 23075 19013 31614 9133 27942 27346 15969 19415 10367 8424 29355 18903 3396 6327 4201 24124 24266 22586 724 1595 3972 17526 2843 20982 23655 12714 18050 15225 2658 7236 27555 13023 729 9022 17386 2585",
"output": "8122"
},
{
"input": "100 1\n199 348 489 76 638 579 982 125 28 401 228 117 195 337 80 914 752 98 679 417 47 225 357 413 849 622 477 620 487 223 321 240 439 393 733 660 652 500 877 40 788 246 376 723 952 601 912 316 598 809 476 932 384 147 982 271 202 695 129 303 304 712 49 306 598 141 833 730 946 708 724 788 202 465 951 118 279 706 214 655 152 976 998 231 487 311 342 317 243 554 977 232 365 643 336 501 761 400 600 528",
"output": "998"
},
{
"input": "80 50\n15160 6853 20254 11358 19535 27691 2983 31650 9219 11833 32053 31695 21511 4320 4384 24843 1454 31543 18796 13815 1546 27926 16276 14315 12542 25370 24890 29647 3584 17867 12446 15072 19852 30207 16361 7964 5343 398 10837 31114 9252 12767 15098 22562 32637 31823 8160 12658 6422 19142 12448 6765 7373 868 31712 24856 23251 29200 8159 16144 27165 4308 13652 12502 4183 7961 3032 26855 8687 12263 24319 7722 19460 30700 29806 1280 21141 25965 25550 26881",
"output": "12448"
},
{
"input": "50 16\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16",
"output": "16"
},
{
"input": "100 1\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16",
"output": "16"
},
{
"input": "100 2\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16",
"output": "16"
},
{
"input": "100 100\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16",
"output": "16"
},
{
"input": "100 99\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16",
"output": "16"
}
] | 1,581,154,516 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 155 | 0 | a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
l.reverse()
print(l[b-1])
| Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second.
There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible.
The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible?
Input Specification:
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer.
Output Specification:
Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
Demo Input:
['3 2\n40 20 30\n', '6 4\n100 20 40 20 50 50\n']
Demo Output:
['30\n', '40\n']
Note:
In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
l.reverse()
print(l[b-1])
``` | 3 |
|
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.
The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
},
{
"input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76",
"output": "58"
},
{
"input": "100\n154\n60\n97\n638\n139\n150\n570\n579\n601\n647\n804\n237\n245\n549\n288\n347\n778\n282\n916\n441\n974\n145\n957\n886\n655\n702\n930\n618\n132\n520\n972\n48\n94\n54\n682\n433\n896\n134\n845\n636\n242\n842\n125\n141\n240\n130\n409\n666\n948\n938\n604\n110\n474\n484\n364\n40\n807\n271\n438\n288\n201\n814\n754\n589\n341\n576\n146\n952\n819\n923\n222\n535\n336\n83\n314\n911\n303\n911\n384\n601\n249\n330\n735\n271\n142\n204\n405\n783\n775\n449\n590\n139\n109\n276\n45\n205\n454\n836\n82\n841",
"output": "50"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n1\n1\n1\n2",
"output": "3"
},
{
"input": "5\n1\n2\n4\n8\n16",
"output": "3"
},
{
"input": "7\n1\n2\n4\n8\n16\n32\n64",
"output": "4"
},
{
"input": "3\n1\n2\n4",
"output": "2"
}
] | 1,566,742,836 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 13,824,000 | n= int(input())
half = int(n/2)
arr=[]
for _ in range(n):
arr.append(int(input()))
arr = sorted(arr)
ind = 0
for i in range(half,n):
if(arr[ind]*2 <= arr[i]):
ind += 1
if(ind == half):
break
print(n-ind)
| Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.
The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
Input Specification:
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
Output Specification:
Output a single integer — the optimal number of visible kangaroos.
Demo Input:
['8\n2\n5\n7\n6\n9\n8\n4\n2\n', '8\n9\n1\n6\n2\n6\n5\n8\n3\n']
Demo Output:
['5\n', '5\n']
Note:
none | ```python
n= int(input())
half = int(n/2)
arr=[]
for _ in range(n):
arr.append(int(input()))
arr = sorted(arr)
ind = 0
for i in range(half,n):
if(arr[ind]*2 <= arr[i]):
ind += 1
if(ind == half):
break
print(n-ind)
``` | 0 |
|
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "14"
},
{
"input": "5 5\n3 2 1 0 0",
"output": "3"
},
{
"input": "8 6\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 7\n10 9 8 7 7 7 5 5",
"output": "8"
},
{
"input": "8 4\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 3\n10 9 8 7 7 7 5 5",
"output": "3"
},
{
"input": "8 1\n10 9 8 7 7 7 5 5",
"output": "1"
},
{
"input": "8 2\n10 9 8 7 7 7 5 5",
"output": "2"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "50 25\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": "50"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 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": "25"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "26"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 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": "50"
},
{
"input": "11 5\n100 99 98 97 96 95 94 93 92 91 90",
"output": "5"
},
{
"input": "10 4\n100 81 70 69 64 43 34 29 15 3",
"output": "4"
},
{
"input": "11 6\n87 71 62 52 46 46 43 35 32 25 12",
"output": "6"
},
{
"input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2",
"output": "12"
},
{
"input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2",
"output": "3"
},
{
"input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5",
"output": "12"
},
{
"input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1",
"output": "9"
},
{
"input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0",
"output": "29"
},
{
"input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4",
"output": "34"
},
{
"input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4",
"output": "44"
},
{
"input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3",
"output": "13"
},
{
"input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3",
"output": "30"
},
{
"input": "2 1\n10 10",
"output": "2"
},
{
"input": "2 2\n10 10",
"output": "2"
},
{
"input": "2 2\n10 0",
"output": "1"
},
{
"input": "2 2\n10 1",
"output": "2"
},
{
"input": "2 1\n10 0",
"output": "1"
},
{
"input": "2 1\n10 2",
"output": "1"
},
{
"input": "50 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10 1\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 2\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 3\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 4\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 5\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 6\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 7\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 8\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 9\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 10\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
}
] | 1,696,925,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | input_str=input()
nk=input_str.split()
n,k=map(int,nk)
input_str=input()
score=input_str.split()
scores=[]
scores=list(map(int,score))
counter=0
for i in scores:
if i>k:
counter+=1
print(counter)
| Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output Specification:
Output the number of participants who advance to the next round.
Demo Input:
['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n']
Demo Output:
['6\n', '0\n']
Note:
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | ```python
input_str=input()
nk=input_str.split()
n,k=map(int,nk)
input_str=input()
score=input_str.split()
scores=[]
scores=list(map(int,score))
counter=0
for i in scores:
if i>k:
counter+=1
print(counter)
``` | 0 |
|
460 | B | Little Dima and Equation | PROGRAMMING | 1,500 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digits in the decimal representation of number *x*.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: *a*, *b*, *c*. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. | The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000). | Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. | [
"3 2 8\n",
"1 2 -18\n",
"2 2 -1\n"
] | [
"3\n10 2008 13726 ",
"0\n",
"4\n1 31 337 967 "
] | none | 1,000 | [
{
"input": "3 2 8",
"output": "3\n10 2008 13726 "
},
{
"input": "1 2 -18",
"output": "0"
},
{
"input": "2 2 -1",
"output": "4\n1 31 337 967 "
},
{
"input": "1 1 0",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 37 963",
"output": "16\n1000 1111 1222 1333 1370 1407 1444 1481 1518 1555 1592 1629 1666 1777 1888 1999 "
},
{
"input": "1 298 -1665",
"output": "17\n123 421 1017 1315 1613 1911 2209 2507 2805 4295 4593 4891 5189 5487 5785 6679 6977 "
},
{
"input": "1 3034 -9234",
"output": "23\n12004 21106 24140 30208 33242 39310 42344 48412 51446 54480 57514 60548 63582 66616 69650 72684 75718 78752 81786 87854 90888 96956 99990 "
},
{
"input": "5 9998 9998",
"output": "0"
},
{
"input": "5 10000 10000",
"output": "0"
},
{
"input": "5 65 352",
"output": "1\n208000352 "
},
{
"input": "5 9999 9999",
"output": "0"
},
{
"input": "4 2099 -38",
"output": "0"
},
{
"input": "1 1 -6708",
"output": "0"
},
{
"input": "5 36 -46",
"output": "0"
},
{
"input": "5 8975 -4",
"output": "0"
},
{
"input": "3 2794 -3354",
"output": "5\n165733932 308990694 392855398 415958984 999999980 "
},
{
"input": "5 1 4473",
"output": "11\n1424330 14353380 17214841 52526348 60470649 69348430 164920697 184532598 205967449 418199966 459169497 "
},
{
"input": "5 1 -9999",
"output": "6\n90001 2466100 17200369 52511876 60456177 205952977 "
},
{
"input": "4 4 6",
"output": "13\n10 1030 40006 114250 202506 262150 521290 937030 1562506 2458630 3694090 4743690 7496650 "
},
{
"input": "5 19 -666",
"output": "0"
},
{
"input": "5 5 -865",
"output": "0"
},
{
"input": "2 8468 -3666",
"output": "2\n7117922 14933886 "
},
{
"input": "4 9359 -3039",
"output": "0"
},
{
"input": "5 5706 -1856",
"output": "0"
},
{
"input": "2 6828 -39",
"output": "2\n7435653 17759589 "
},
{
"input": "5 3903 -9847",
"output": "0"
},
{
"input": "3 1727 4771",
"output": "1\n42124574 "
},
{
"input": "4 1870 9912",
"output": "0"
},
{
"input": "3 6300 7035",
"output": "1\n466761435 "
},
{
"input": "5 8704 -6190",
"output": "0"
},
{
"input": "2 68 3",
"output": "1\n45971 "
},
{
"input": "5 6 -95",
"output": "1\n416063647 "
},
{
"input": "2 28 12",
"output": "2\n4044 7180 "
},
{
"input": "3 37 -70",
"output": "0"
},
{
"input": "5 3 53",
"output": "1\n100663349 "
},
{
"input": "3 2570 4109",
"output": "2\n427587859 999777799 "
},
{
"input": "3 1139 6335",
"output": "2\n12134407 499999999 "
},
{
"input": "3 2278 -1329",
"output": "3\n61504671 145790671 999985999 "
},
{
"input": "4 30 719",
"output": "2\n21219149 899597999 "
},
{
"input": "4 9023 312",
"output": "0"
},
{
"input": "5 10000 9",
"output": "0"
},
{
"input": "5 7698 5337",
"output": "0"
},
{
"input": "5 1 0",
"output": "5\n1 17210368 52521875 60466176 205962976 "
},
{
"input": "5 12 3",
"output": "0"
},
{
"input": "5 3903 153",
"output": "0"
},
{
"input": "5 10000 0",
"output": "1\n10000 "
},
{
"input": "3 2570 -6691",
"output": "1\n999766999 "
},
{
"input": "5 5 13",
"output": "1\n579281018 "
}
] | 1,691,662,692 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691662692.1105928")# 1691662692.110608 | Title: Little Dima and Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digits in the decimal representation of number *x*.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: *a*, *b*, *c*. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.
Input Specification:
The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000).
Output Specification:
Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
Demo Input:
['3 2 8\n', '1 2 -18\n', '2 2 -1\n']
Demo Output:
['3\n10 2008 13726 ', '0\n', '4\n1 31 337 967 ']
Note:
none | ```python
print("_RANDOM_GUESS_1691662692.1105928")# 1691662692.110608
``` | 0 |
|
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries. | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "0\n0\n0\n0"
},
{
"input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4",
"output": "0\n0\n0\n0\n0"
},
{
"input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4",
"output": "0\n1\n0\n0\n0\n1"
},
{
"input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7",
"output": "0\n0\n0\n0\n0\n0\n1"
},
{
"input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0\n0"
},
{
"input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5",
"output": "0\n1\n0\n0\n0\n0\n0\n1\n0"
},
{
"input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1",
"output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0"
},
{
"input": "1 1\n-1\n1 1",
"output": "0"
},
{
"input": "1 1\n1\n1 1",
"output": "0"
}
] | 1,367,772,155 | 2,255 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 10 | 2,000 | 2,560,000 | n, m = [int(i) for i in input().split()]
data = input().split()
pos = sum([int(i) for i in data if int(i) == 1])
minq = min(pos, n - pos)
ans = []
for i in range(m):
req = [int(i) for i in input().split()]
if ((req[1] - req[0])%2 == 0) or ((((req[1] - req[0]) + 1) / 2) > minq):
ans.append(0)
else:
ans.append(1)
for i in ans:
print(i) | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries.
Input Specification:
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
Demo Input:
['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n']
Demo Output:
['0\n1\n0\n', '0\n1\n0\n1\n0\n']
Note:
none | ```python
n, m = [int(i) for i in input().split()]
data = input().split()
pos = sum([int(i) for i in data if int(i) == 1])
minq = min(pos, n - pos)
ans = []
for i in range(m):
req = [int(i) for i in input().split()]
if ((req[1] - req[0])%2 == 0) or ((((req[1] - req[0]) + 1) / 2) > minq):
ans.append(0)
else:
ans.append(1)
for i in ans:
print(i)
``` | 0 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,695,887,788 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | lst=input().split("+")
lst.sort()
print("+".join(lst)) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
lst=input().split("+")
lst.sort()
print("+".join(lst))
``` | 3 |
|
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1"
},
{
"input": "FSFlNEelYY",
"output": "3"
},
{
"input": "lgtyasficu",
"output": "0"
},
{
"input": "WYKUDTDDBT",
"output": "0"
},
{
"input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd",
"output": "0"
},
{
"input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu",
"output": "43"
},
{
"input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR",
"output": "13"
},
{
"input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi",
"output": "27"
},
{
"input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn",
"output": "31"
}
] | 1,588,014,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 216 | 307,200 | s = input()
n = len(s)
li = [1]
for i in range(1, n):
x = ord(s[i])
y = ord(s[i - 1])
if (90 >= x >= 65 and 90 >= y >= 65) or (122 >= x >= 97 and 122 >= y >= 97):
li[-1] += 1
else:
li.append(1)
n = len(li)
t1 = 0
t2 = 0
for i in range(1, n):
if i % 2 == 1:
t1 += li[i]
else:
t2 += li[i]
# print(li)
if 90 >= ord(s[0]) >= 65:
print(min(t1, t2))
else:
if n > 1:
print(min(t1, li[0] + min(t2 - (li[n - 1] if n % 2 == 1 else 0), t1 - li[1])))
else:
print(0) | Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
Input Specification:
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Output Specification:
Print a single number — the least number of actions needed to make the message fancy.
Demo Input:
['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n']
Demo Output:
['5\n', '0\n', '0\n']
Note:
none | ```python
s = input()
n = len(s)
li = [1]
for i in range(1, n):
x = ord(s[i])
y = ord(s[i - 1])
if (90 >= x >= 65 and 90 >= y >= 65) or (122 >= x >= 97 and 122 >= y >= 97):
li[-1] += 1
else:
li.append(1)
n = len(li)
t1 = 0
t2 = 0
for i in range(1, n):
if i % 2 == 1:
t1 += li[i]
else:
t2 += li[i]
# print(li)
if 90 >= ord(s[0]) >= 65:
print(min(t1, t2))
else:
if n > 1:
print(min(t1, li[0] + min(t2 - (li[n - 1] if n % 2 == 1 else 0), t1 - li[1])))
else:
print(0)
``` | 0 |
|
580 | C | Kefa and Park | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.
The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than *m* consecutive vertices with cats.
Your task is to help Kefa count the number of restaurants where he can go. | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then vertex *i* has no cat), or equals to 1 (then vertex *i* has a cat).
Next *n*<=-<=1 lines contains the edges of the tree in the format "*x**i* *y**i*" (without the quotes) (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*), where *x**i* and *y**i* are the vertices of the tree, connected by an edge.
It is guaranteed that the given set of edges specifies a tree. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats. | [
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
] | [
"2\n",
"2\n"
] | Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.
Note to the first sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/785114b4b3f5336f02078c25750f87c5a1d0b4be.png" style="max-width: 100.0%;max-height: 100.0%;"/> The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.
Note to the second sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/e5c07640680c837aec99126d94287872e69aa09a.png" style="max-width: 100.0%;max-height: 100.0%;"/> The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | 1,500 | [
{
"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "2"
},
{
"input": "3 2\n1 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"input": "6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6",
"output": "3"
},
{
"input": "7 3\n1 1 1 1 1 0 1\n1 2\n1 3\n2 4\n3 5\n5 6\n6 7",
"output": "2"
},
{
"input": "15 2\n1 0 1 0 1 0 0 0 0 0 0 0 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15",
"output": "8"
},
{
"input": "2 1\n1 1\n2 1",
"output": "0"
},
{
"input": "12 3\n1 0 1 0 1 1 1 1 0 0 0 0\n6 7\n12 1\n9 7\n1 4\n10 7\n7 1\n11 8\n5 1\n3 7\n5 8\n4 2",
"output": "7"
}
] | 1,696,980,558 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 2,150,400 | from collections import defaultdict
N = 228228
a = defaultdict(list)
c = [0] * N
result_memo = {}
def go(v, pr, k):
if v in result_memo:
return result_memo[v]
if k > m:
return 0
ok = 1
for i in range(len(a[v])):
if a[v][i] != pr:
ok = 0
go(a[v][i], v, k*c[a[v][i]] + c[a[v][i]])
result = ok
result_memo[v] = result
return result
n, m = map(int, input().split())
c = list(map(int, input().split()))
for i in range(n-1):
x, y = map(int, input().split())
x -= 1
y -= 1
a[x].append(y)
a[y].append(x)
go(0, -1, c[0])
print(result_memo[0]) | Title: Kefa and Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.
The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than *m* consecutive vertices with cats.
Your task is to help Kefa count the number of restaurants where he can go.
Input Specification:
The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then vertex *i* has no cat), or equals to 1 (then vertex *i* has a cat).
Next *n*<=-<=1 lines contains the edges of the tree in the format "*x**i* *y**i*" (without the quotes) (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*), where *x**i* and *y**i* are the vertices of the tree, connected by an edge.
It is guaranteed that the given set of edges specifies a tree.
Output Specification:
A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats.
Demo Input:
['4 1\n1 1 0 0\n1 2\n1 3\n1 4\n', '7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n']
Demo Output:
['2\n', '2\n']
Note:
Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.
Note to the first sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/785114b4b3f5336f02078c25750f87c5a1d0b4be.png" style="max-width: 100.0%;max-height: 100.0%;"/> The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.
Note to the second sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/e5c07640680c837aec99126d94287872e69aa09a.png" style="max-width: 100.0%;max-height: 100.0%;"/> The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | ```python
from collections import defaultdict
N = 228228
a = defaultdict(list)
c = [0] * N
result_memo = {}
def go(v, pr, k):
if v in result_memo:
return result_memo[v]
if k > m:
return 0
ok = 1
for i in range(len(a[v])):
if a[v][i] != pr:
ok = 0
go(a[v][i], v, k*c[a[v][i]] + c[a[v][i]])
result = ok
result_memo[v] = result
return result
n, m = map(int, input().split())
c = list(map(int, input().split()))
for i in range(n-1):
x, y = map(int, input().split())
x -= 1
y -= 1
a[x].append(y)
a[y].append(x)
go(0, -1, c[0])
print(result_memo[0])
``` | 0 |
|
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,690,199,945 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | a,b=map(int,input().split(' '))
lst= list(map(int, input().split(" ")))
count =0
for i in range(len(lst)):
lst[i]+=b
if lst[i]<=5:
count+=1
print(count//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | ```python
a,b=map(int,input().split(' '))
lst= list(map(int, input().split(" ")))
count =0
for i in range(len(lst)):
lst[i]+=b
if lst[i]<=5:
count+=1
print(count//3)
``` | 3 |
|
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn! | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa". | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "ab\nbb",
"output": "NO"
},
{
"input": "zzaa\naazz",
"output": "YES"
},
{
"input": "azza\nzaaz",
"output": "YES"
},
{
"input": "abc\nabc",
"output": "YES"
},
{
"input": "abc\nacb",
"output": "NO"
},
{
"input": "azzz\nzzaz",
"output": "YES"
},
{
"input": "abcd\ndcab",
"output": "YES"
},
{
"input": "abcd\ncdab",
"output": "YES"
},
{
"input": "abcd\ndcba",
"output": "YES"
},
{
"input": "abcd\nacbd",
"output": "NO"
},
{
"input": "oloaxgddgujq\noloaxgujqddg",
"output": "YES"
},
{
"input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta",
"output": "YES"
},
{
"input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz",
"output": "YES"
},
{
"input": "snyaydaeobufdg\nsnyaydaeobufdg",
"output": "YES"
},
{
"input": "baaaaa\nabaaaa",
"output": "NO"
},
{
"input": "hhiisug\nmzdjwju",
"output": "NO"
},
{
"input": "bbbabbabaaab\naaaabbabbbbb",
"output": "NO"
},
{
"input": "bbaaab\naababb",
"output": "NO"
},
{
"input": "aabbaaaa\naaaaabab",
"output": "NO"
},
{
"input": "aab\naba",
"output": "NO"
},
{
"input": "abcddd\nbacddd",
"output": "NO"
},
{
"input": "qgiufelsfhanx\naaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "aabaababaaba\naababaaababa",
"output": "NO"
},
{
"input": "nocdqzdriyyil\naaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "zdmctxl\nkojqhgw",
"output": "NO"
},
{
"input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw",
"output": "NO"
},
{
"input": "abc\nbac",
"output": "NO"
},
{
"input": "ottceez\npcstdvz",
"output": "NO"
}
] | 1,576,913,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | def equal(str1,str2):
if(str1==str2):
return 1
if(len(str1)!=len(str2)):
return 0
if(len(str1)==1 and len(str2)==1):
return 0
else:
hl1=str1[0:len(str1)//2]
hr1=str1[len(str1)//2:len(str1)]
hl2=str2[0:len(str2)//2]
hr2=str2[len(str2)//2:len(str2)]
print("hl1->",hl1)
print("hr1->",hr1)
print("hl2->",hl2)
print("hr2->",hr2)
return ((equal(hl1,hl2) and equal(hr1,hr2)) or (equal(hl1,hr2) and equal(hr1,hl2)))
def main():
str1=input()
str2=input()
result=equal(str1,str2)
if(result==1):
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
| Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn!
Input Specification:
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Output Specification:
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
Demo Input:
['aaba\nabaa\n', 'aabb\nabab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa". | ```python
def equal(str1,str2):
if(str1==str2):
return 1
if(len(str1)!=len(str2)):
return 0
if(len(str1)==1 and len(str2)==1):
return 0
else:
hl1=str1[0:len(str1)//2]
hr1=str1[len(str1)//2:len(str1)]
hl2=str2[0:len(str2)//2]
hr2=str2[len(str2)//2:len(str2)]
print("hl1->",hl1)
print("hr1->",hr1)
print("hl2->",hl2)
print("hr2->",hr2)
return ((equal(hl1,hl2) and equal(hr1,hr2)) or (equal(hl1,hr2) and equal(hr1,hl2)))
def main():
str1=input()
str2=input()
result=equal(str1,str2)
if(result==1):
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
``` | 0 |
|
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,664,883,156 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | w = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
K = 0
L = 0
while L < len(l) and s < w:
s += l[i]
i += 1
if s >= w:
print(i)
else:
print("1") | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
w = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
K = 0
L = 0
while L < len(l) and s < w:
s += l[i]
i += 1
if s >= w:
print(i)
else:
print("1")
``` | -1 |
|
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500",
"output": "6"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39",
"output": "6"
},
{
"input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064",
"output": "5"
},
{
"input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697",
"output": "21"
}
] | 1,698,136,382 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 124 | 13,619,200 | n = int(input())
line = list(map(int,input().split()))
line.sort()
queue = []
for i in line:
if i >= sum(queue):
queue.append(i)
print(len(queue)) | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Output Specification:
Print a single number — the maximum number of not disappointed people in the queue.
Demo Input:
['5\n15 2 1 5 3\n']
Demo Output:
['4\n']
Note:
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | ```python
n = int(input())
line = list(map(int,input().split()))
line.sort()
queue = []
for i in line:
if i >= sum(queue):
queue.append(i)
print(len(queue))
``` | 3 |
|
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggglgpep",
"output": "2"
},
{
"input": "iegdlraaidefgegiagrdfhihe",
"output": "2"
},
{
"input": "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg",
"output": "1"
},
{
"input": "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw",
"output": "2"
},
{
"input": "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbkvviwntdhqscvkmphnkkljizndnbjt",
"output": "3"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "99"
},
{
"input": "ikiikiikikiiikkkkkikkkkiiiiikkiiikkiikiikkkkikkkikikkikiiikkikikiiikikkkiiikkkikkikkikkkkiiikkiiiiii",
"output": "10"
},
{
"input": "ovovhoovvhohhhvhhvhhvhovoohovhhoooooovohvooooohvvoooohvvovhhvhovhhvoovhvhvoovovvhooovhhooovohvhhovhv",
"output": "8"
},
{
"input": "ccwckkkycccccckwckwkwkwkkkkyycykcccycyckwywcckwykcycykkkwcycwwcykcwkwkwwykwkwcykywwwyyykckkyycckwcwk",
"output": "5"
},
{
"input": "ttketfkefktfztezzkzfkkeetkkfktftzktezekkeezkeeetteeteefetefkzzzetekfftkeffzkktffzkzzeftfeezfefzffeef",
"output": "4"
},
{
"input": "rtharczpfznrgdnkltchafduydgbgkdjqrmjqyfmpwjwphrtsjbmswkanjlprbnduaqbcjqxlxmkspkhkcnzbqwxonzxxdmoigti",
"output": "2"
},
{
"input": "fplrkfklvwdeiynbjgaypekambmbjfnoknlhczhkdmljicookdywdgpnlnqlpunnkebnikgcgcjefeqhknvlynmvjcegvcdgvvdb",
"output": "2"
},
{
"input": "txbciieycswqpniwvzipwlottivvnfsysgzvzxwbctcchfpvlbcjikdofhpvsknptpjdbxemtmjcimetkemdbettqnbvzzbdyxxb",
"output": "2"
},
{
"input": "fmubmfwefikoxtqvmaavwjxmoqltapexkqxcsztpezfcltqavuicefxovuswmqimuikoppgqpiapqutkczgcvxzutavkujxvpklv",
"output": "3"
},
{
"input": "ipsrjylhpkjvlzncfixipstwcicxqygqcfrawpzzvckoveyqhathglblhpkjvlzncfixipfajaqobtzvthmhgbuawoxoknirclxg",
"output": "15"
},
{
"input": "kcnjsntjzcbgzjscrsrjkrbytqsrptzspzctjrorsyggrtkcnjsntjzcbgzjscrsrjyqbrtpcgqirsrrjbbbrnyqstnrozcoztt",
"output": "20"
},
{
"input": "unhcfnrhsqetuerjqcetrhlsqgfnqfntvkgxsscquolxxroqgtchffyccetrhlsqgfnqfntvkgxsscquolxxroqgtchffhfqvx",
"output": "37"
},
{
"input": "kkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckkkkkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckckckkc",
"output": "46"
},
{
"input": "mlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydbrxdmlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydik",
"output": "47"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "0"
},
{
"input": "tttttbttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttmttttttt",
"output": "85"
},
{
"input": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffff",
"output": "61"
},
{
"input": "cccccccccccccccccccccccwcccccccccccccccccccccuccccccccccccccnccccccccccccccccccccccccccccccccccccccc",
"output": "38"
},
{
"input": "ffffffffffffffffffffffffffufffgfffffffffffffffffffffffffffffffffffffffgffffffftffffffgffffffffffffff",
"output": "38"
},
{
"input": "rrrrrrrrrrrrrrrrrrrlhbrrrrrrrrurrrrrrrfrrqrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrewrrrrrrryrrxrrrrrrrrrrr",
"output": "33"
},
{
"input": "vyvvvvvvvvzvvvvvzvvvwvvvvrvvvvvvvvvvvvvvvrvvvvvvvvvpkvvpvgvvvvvvvvvvvvvgvvvvvvvvvvvvvvvvvvysvvvbvvvv",
"output": "17"
},
{
"input": "cbubbbbbbbbbbfbbbbbbbbjbobbbbbbbbbbibbubbbbjbbbnzgbbzbbfbbbbbbbbbbbfbpbbbbbbbbbbygbbbgbabbbbbbbhibbb",
"output": "12"
},
{
"input": "lrqrrrrrrrjrrrrrcdrrgrrmwvrrrrrrrrrxfzrmrmrryrrrurrrdrrrrrrrrrrererrrsrrrrrrrrrrrqrrrrcrrwjsrrlrrrrr",
"output": "10"
},
{
"input": "ssssusisisosscssssztzessssyspskjssvosiissussszsosssslsssdsssvssvsssslsssmsfjasjsssssowscsjsssszsspss",
"output": "8"
},
{
"input": "uukuuuumueuuuujuukgdhbztuuuubbguuocuozfaunqufjujuguyuuvkuuauubuubuucuvtjuuuuuusduduuuuuuuueunuuuuuzu",
"output": "7"
},
{
"input": "jpkkgwklngwqcfzmwkkpcwkkkkkekkkekkkdsykqwjkkkhkkkxdnukkkkkkmkqykkkxqklkskkrkkkkkqqjikkkkkkpknkkkkkoh",
"output": "7"
},
{
"input": "bmzbbfbbhqxwthtbbisbbbbbtbbfbbpbfbbpbkbjfbcbbbbzbbbdwmbbbrnvqdbbtbbuglrnbbbbvmbyblebbabibrevaxbbjbqb",
"output": "6"
},
{
"input": "qqqmqqqsbteqqopsuqiqumrqzpqnqgqeniqqkyqqyqqqpxzqeqqquhdqquhqqqfqjirqaqqaquxqoqqjqqqqbjbgqcqqqqicnkqc",
"output": "4"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaavaaaaaaauaaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "44"
},
{
"input": "a",
"output": "0"
},
{
"input": "fg",
"output": "0"
},
{
"input": "yy",
"output": "1"
},
{
"input": "abcabcabc",
"output": "6"
},
{
"input": "qwerqwedqwes",
"output": "3"
}
] | 1,682,581,950 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 184 | 0 | def main():
s = input()
l = len(s)
for i in range(l, 0, -1):
substring_dict = {}
for j in range(l - i + 1):
substring = s[j: j + i]
if substring in substring_dict:
print(i)
return
substring_dict[substring] = None
print(0)
if __name__ == "__main__":
main()
| Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Specification:
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.
Output Specification:
Output one number — length of the longest substring that can be met in the string at least twice.
Demo Input:
['abcd\n', 'ababa\n', 'zzz\n']
Demo Output:
['0', '3', '2']
Note:
none | ```python
def main():
s = input()
l = len(s)
for i in range(l, 0, -1):
substring_dict = {}
for j in range(l - i + 1):
substring = s[j: j + i]
if substring in substring_dict:
print(i)
return
substring_dict[substring] = None
print(0)
if __name__ == "__main__":
main()
``` | 3.954 |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 1,684,501,774 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | a = input()
b = int(a)
money = [100, 20, 10, 5, 1]
count = 0
while b != 0:
for i in money:
if b >= i :
b -= i
count += 1
break
print(count)
| Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input Specification:
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output Specification:
Output the minimum number of bills that Allen could receive.
Demo Input:
['125\n', '43\n', '1000000000\n']
Demo Output:
['3\n', '5\n', '10000000\n']
Note:
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | ```python
a = input()
b = int(a)
money = [100, 20, 10, 5, 1]
count = 0
while b != 0:
for i in money:
if b >= i :
b -= i
count += 1
break
print(count)
``` | 0 |
|
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"output": "NO"
},
{
"input": "3 3\n1 1\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n1 2\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n2 2\n1 2 3\n1 2 3",
"output": "NO"
},
{
"input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49",
"output": "YES"
},
{
"input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100",
"output": "YES"
},
{
"input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99",
"output": "YES"
},
{
"input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81",
"output": "YES"
},
{
"input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10",
"output": "NO"
},
{
"input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "1 1\n1 1\n-1000000000\n30",
"output": "YES"
},
{
"input": "3 3\n1 3\n1 3 3\n3 3 3",
"output": "YES"
},
{
"input": "3 3\n1 1\n3 3 3\n2 2 2",
"output": "NO"
},
{
"input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7",
"output": "NO"
},
{
"input": "3 4\n2 2\n5 6 7\n1 2 3 4",
"output": "NO"
},
{
"input": "3 3\n3 3\n1 2 3\n4 5 6",
"output": "YES"
},
{
"input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9",
"output": "YES"
}
] | 1,596,287,539 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 6,963,200 | na, nb = map(int, input().split())
k,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
for _ in range(k):
a1 = min(a)
i = a.index(a1)
a.pop(i)
x = a1
y = 0
for _ in range(k):
b1 = max(b)
i = b.index(b1)
b.pop(i)
y = b1
if y > x:
print("YES")
else:
print("NO") | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
Input Specification:
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Output Specification:
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
Demo Input:
['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
na, nb = map(int, input().split())
k,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
for _ in range(k):
a1 = min(a)
i = a.index(a1)
a.pop(i)
x = a1
y = 0
for _ in range(k):
b1 = max(b)
i = b.index(b1)
b.pop(i)
y = b1
if y > x:
print("YES")
else:
print("NO")
``` | -1 |
|
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 1,580,299,297 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | def fl(s):
sfCount = 0
fsCount = 0
for i in range(0, len(s)-1):
if s[i] + s[i+1] == "SF":
sfCount += 1
elif s[i] + s[i+1] == "FS":
fsCount += 1
if sfCount > fsCount:
print("YES")
else:
print("NO")
input()
s = input()
fl(s) | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
Input Specification:
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Output Specification:
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | ```python
def fl(s):
sfCount = 0
fsCount = 0
for i in range(0, len(s)-1):
if s[i] + s[i+1] == "SF":
sfCount += 1
elif s[i] + s[i+1] == "FS":
fsCount += 1
if sfCount > fsCount:
print("YES")
else:
print("NO")
input()
s = input()
fl(s)
``` | 3 |
|
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip. | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "25 9712",
"output": "11"
},
{
"input": "9 7601",
"output": "5"
},
{
"input": "1 9058",
"output": "0"
},
{
"input": "29 7772",
"output": "26"
},
{
"input": "45 9465",
"output": "14"
},
{
"input": "46 866",
"output": "5"
},
{
"input": "29 1241",
"output": "20"
},
{
"input": "17 4248",
"output": "12"
},
{
"input": "20 8082",
"output": "11"
},
{
"input": "50 9555",
"output": "0"
},
{
"input": "4 7455",
"output": "2"
},
{
"input": "36 880",
"output": "4"
},
{
"input": "24 7440",
"output": "9"
},
{
"input": "44 7888",
"output": "12"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "50 10000",
"output": "40"
},
{
"input": "1 10000",
"output": "0"
},
{
"input": "50 1",
"output": "0"
},
{
"input": "50 50",
"output": "5"
}
] | 1,630,261,715 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 6,963,200 | def fn(i):
return i*(i+1)//2
n,m=map(int,input().split())
k=1
s=(n*(n+1)/2)
rem=m
if(m>s):
while(rem>s):
rem-=s
for i in range(n):
if(fn(i)<=rem and fn(i+1)>rem):
print(int(rem-fn(i))) | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Output Specification:
Print the number of chips the presenter ended up with.
Demo Input:
['4 11\n', '17 107\n', '3 8\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip. | ```python
def fn(i):
return i*(i+1)//2
n,m=map(int,input().split())
k=1
s=(n*(n+1)/2)
rem=m
if(m>s):
while(rem>s):
rem-=s
for i in range(n):
if(fn(i)<=rem and fn(i+1)>rem):
print(int(rem-fn(i)))
``` | 0 |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 87 200 62 168 51 185 192 118",
"output": "48"
},
{
"input": "1 1\n10000",
"output": "5000"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "2 2\n2 2",
"output": "1"
}
] | 1,490,869,005 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 11,878,400 | def solve():
n, k = map(int, input().split())
w = [int(i) for i in input().split()]
ans = sum((wi + k - 1) // k for wi in w)
ans = (ans + 1) // 2
print(ans)
if __name__ == '__main__':
solve() | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
Output Specification:
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
Demo Input:
['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n']
Demo Output:
['3\n', '5\n']
Note:
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | ```python
def solve():
n, k = map(int, input().split())
w = [int(i) for i in input().split()]
ans = sum((wi + k - 1) // k for wi in w)
ans = (ans + 1) // 2
print(ans)
if __name__ == '__main__':
solve()
``` | 3 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,614,878,943 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | def t(st):
hello= "hello"
i=0
for j in range(0,len(st)):
if i==5:
return "YES"
if st[j]==hello[i]:
i +=1
if i <5:
return "NO"
else:
return "YES"
ad= input()
print(t(ad)) | 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
def t(st):
hello= "hello"
i=0
for j in range(0,len(st)):
if i==5:
return "YES"
if st[j]==hello[i]:
i +=1
if i <5:
return "NO"
else:
return "YES"
ad= input()
print(t(ad))
``` | 3.969 |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,610,774,577 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | def isprime(n):
for i in range(2, n // 2 + 1):
if n % i == 0:
return False
return True
n, m = map(int, input().split())
if not isprime(m):
ans = "NO"
else:
ans = "YES"
for k in range(n + 1, m):
if isprime(k):
ans = "NO"
break
print(ans)
| Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none | ```python
def isprime(n):
for i in range(2, n // 2 + 1):
if n % i == 0:
return False
return True
n, m = map(int, input().split())
if not isprime(m):
ans = "NO"
else:
ans = "YES"
for k in range(n + 1, m):
if isprime(k):
ans = "NO"
break
print(ans)
``` | 3.969 |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input": "3 2 W\nOO\nWW\nWW",
"output": "1"
},
{
"input": "3 3 U\nUOO\nUVV\nUVV",
"output": "2"
},
{
"input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.",
"output": "1"
},
{
"input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ",
"output": "2"
},
{
"input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN",
"output": "3"
},
{
"input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J",
"output": "3"
},
{
"input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB",
"output": "2"
},
{
"input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..",
"output": "3"
},
{
"input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA",
"output": "4"
},
{
"input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY",
"output": "6"
},
{
"input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA",
"output": "4"
}
] | 1,660,214,509 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 2,662,400 | n, m, p = input().split(' ')
n = int(n)
m = int(m)
matrix = []
president_desk = []
seen = set()
for i in range(n):
row = list(input())
for j, x in enumerate(row):
if x == p:
president_desk.append((i, j))
matrix.append(row)
for (x, y) in president_desk:
for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
xn = x + dx
yn = y + dy
if xn>=0 and xn<n and yn>=0 and yn<m and matrix[xn][yn]!=p and matrix[xn][yn]!='.':
seen.add(matrix[xn][yn])
print(len(seen)) | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input Specification:
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output Specification:
Print the only number — the amount of President's deputies.
Demo Input:
['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n']
Demo Output:
['2\n', '0\n']
Note:
none | ```python
n, m, p = input().split(' ')
n = int(n)
m = int(m)
matrix = []
president_desk = []
seen = set()
for i in range(n):
row = list(input())
for j, x in enumerate(row):
if x == p:
president_desk.append((i, j))
matrix.append(row)
for (x, y) in president_desk:
for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
xn = x + dx
yn = y + dy
if xn>=0 and xn<n and yn>=0 and yn<m and matrix[xn][yn]!=p and matrix[xn][yn]!='.':
seen.add(matrix[xn][yn])
print(len(seen))
``` | 3.964664 |
0 | none | none | none | 0 | [
"none"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*. | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 0 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "100 0",
"output": "100"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "160 2",
"output": "800"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "3 1",
"output": "30"
},
{
"input": "4 1",
"output": "20"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "6 1",
"output": "30"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "8 1",
"output": "40"
},
{
"input": "9 1",
"output": "90"
},
{
"input": "10 1",
"output": "10"
},
{
"input": "11 1",
"output": "110"
},
{
"input": "12 1",
"output": "60"
},
{
"input": "16 2",
"output": "400"
},
{
"input": "2 2",
"output": "100"
},
{
"input": "1 2",
"output": "100"
},
{
"input": "5 2",
"output": "100"
},
{
"input": "15 2",
"output": "300"
},
{
"input": "36 2",
"output": "900"
},
{
"input": "1 8",
"output": "100000000"
},
{
"input": "8 8",
"output": "100000000"
},
{
"input": "96 8",
"output": "300000000"
},
{
"input": "175 8",
"output": "700000000"
},
{
"input": "9999995 8",
"output": "199999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "12345678 8",
"output": "617283900000000"
},
{
"input": "78125 8",
"output": "100000000"
},
{
"input": "390625 8",
"output": "100000000"
},
{
"input": "1953125 8",
"output": "500000000"
},
{
"input": "9765625 8",
"output": "2500000000"
},
{
"input": "68359375 8",
"output": "17500000000"
},
{
"input": "268435456 8",
"output": "104857600000000"
},
{
"input": "125829120 8",
"output": "9830400000000"
},
{
"input": "128000 8",
"output": "400000000"
},
{
"input": "300000 8",
"output": "300000000"
},
{
"input": "3711871 8",
"output": "371187100000000"
},
{
"input": "55555 8",
"output": "1111100000000"
},
{
"input": "222222222 8",
"output": "11111111100000000"
},
{
"input": "479001600 8",
"output": "7484400000000"
},
{
"input": "655360001 7",
"output": "6553600010000000"
},
{
"input": "655360001 8",
"output": "65536000100000000"
},
{
"input": "1000000000 1",
"output": "1000000000"
},
{
"input": "1000000000 7",
"output": "1000000000"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "10000000 8",
"output": "100000000"
},
{
"input": "1000000 8",
"output": "100000000"
},
{
"input": "10000009 8",
"output": "1000000900000000"
},
{
"input": "10000005 8",
"output": "200000100000000"
},
{
"input": "10000002 8",
"output": "500000100000000"
},
{
"input": "999999997 8",
"output": "99999999700000000"
},
{
"input": "999999997 7",
"output": "9999999970000000"
},
{
"input": "999999995 8",
"output": "19999999900000000"
},
{
"input": "123 8",
"output": "12300000000"
},
{
"input": "24 2",
"output": "600"
},
{
"input": "16 4",
"output": "10000"
},
{
"input": "123456787 8",
"output": "12345678700000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "101 1",
"output": "1010"
},
{
"input": "50 2",
"output": "100"
},
{
"input": "999999818 1",
"output": "4999999090"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "123 1",
"output": "1230"
},
{
"input": "16 1",
"output": "80"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "15304 6",
"output": "1913000000"
},
{
"input": "3 8",
"output": "300000000"
},
{
"input": "4 2",
"output": "100"
},
{
"input": "100000 7",
"output": "10000000"
},
{
"input": "5 8",
"output": "100000000"
},
{
"input": "16724 6",
"output": "4181000000"
},
{
"input": "999999999 1",
"output": "9999999990"
},
{
"input": "999999990 8",
"output": "9999999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "100000 1",
"output": "100000"
},
{
"input": "8 3",
"output": "1000"
},
{
"input": "16768 6",
"output": "262000000"
},
{
"input": "123456789 1",
"output": "1234567890"
},
{
"input": "2 8",
"output": "100000000"
},
{
"input": "999999937 8",
"output": "99999993700000000"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "2000000 7",
"output": "10000000"
},
{
"input": "1999998 2",
"output": "99999900"
},
{
"input": "125 3",
"output": "1000"
}
] | 1,505,654,488 | 988 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 3 | 1,000 | 0 | def main():
N, K = map(int, input().split())
x = 10 ** K
while True:
if x % N > 0:
x += 10 ** K
else:
print(x)
break
main()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Output Specification:
Print the *k*-rounding of *n*.
Demo Input:
['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n']
Demo Output:
['30000\n', '10000\n', '38101\n', '12345678900000000\n']
Note:
none | ```python
def main():
N, K = map(int, input().split())
x = 10 ** K
while True:
if x % N > 0:
x += 10 ** K
else:
print(x)
break
main()
``` | 0 |
|
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.
Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other. | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
"input": "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11",
"output": "4"
},
{
"input": "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5",
"output": "27"
},
{
"input": "3 0",
"output": "-1"
},
{
"input": "3 2\n2 3\n2 1",
"output": "-1"
},
{
"input": "3 3\n3 1\n3 2\n2 1",
"output": "0"
},
{
"input": "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2",
"output": "3"
},
{
"input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6",
"output": "2"
},
{
"input": "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1",
"output": "3"
},
{
"input": "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4",
"output": "7"
},
{
"input": "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204",
"output": "6"
},
{
"input": "4000 0",
"output": "-1"
}
] | 1,597,809,112 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
n,m = map(int,input().split())
g = [set() for i in range(n)]
l = []
p = [0 for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
a-=1
b-=1
p[a]+=1
p[b]+=1
g[a].add(b)
g[b].add(a)
l.append(a,b)
ans = 1000000
for i,j in l:
for k in range(n):
if k in g[i] and k in g[j]:
ans = min(ans,p[i]+p[j]+p[k])
if ans = 1000000:
ans = -1
else:
ans = ans-6
print(ans) | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.
Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
Input Specification:
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once.
Output Specification:
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
Demo Input:
['5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n', '7 4\n2 1\n3 6\n5 1\n1 7\n']
Demo Output:
['2\n', '-1\n']
Note:
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other. | ```python
import sys
n,m = map(int,input().split())
g = [set() for i in range(n)]
l = []
p = [0 for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
a-=1
b-=1
p[a]+=1
p[b]+=1
g[a].add(b)
g[b].add(a)
l.append(a,b)
ans = 1000000
for i,j in l:
for k in range(n):
if k in g[i] and k in g[j]:
ans = min(ans,p[i]+p[j]+p[k])
if ans = 1000000:
ans = -1
else:
ans = ans-6
print(ans)
``` | -1 |
|
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes. | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions. | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 57 78\n66 60 45"
},
{
"input": "0 17 14\n15 0 15\n16 13 0",
"output": "14 17 14\n15 15 15\n16 13 16"
},
{
"input": "0 97 56\n69 0 71\n84 43 0",
"output": "57 97 56\n69 70 71\n84 43 83"
},
{
"input": "0 1099 1002\n1027 0 1049\n1074 977 0",
"output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063"
},
{
"input": "0 98721 99776\n99575 0 99123\n98922 99977 0",
"output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148"
},
{
"input": "0 6361 2304\n1433 0 8103\n7232 3175 0",
"output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897"
},
{
"input": "0 99626 99582\n99766 0 99258\n99442 99398 0",
"output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696"
},
{
"input": "0 99978 99920\n99950 0 99918\n99948 99890 0",
"output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964"
},
{
"input": "0 840 666\n612 0 948\n894 720 0",
"output": "834 840 666\n612 780 948\n894 720 726"
},
{
"input": "0 28 10\n12 0 24\n26 8 0",
"output": "16 28 10\n12 18 24\n26 8 20"
},
{
"input": "0 120 83\n98 0 90\n105 68 0",
"output": "79 120 83\n98 94 90\n105 68 109"
},
{
"input": "0 86900 85807\n85836 0 86842\n86871 85778 0",
"output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368"
},
{
"input": "0 74 78\n78 0 74\n74 78 0",
"output": "76 74 78\n78 76 74\n74 78 76"
},
{
"input": "0 505 681\n605 0 657\n581 757 0",
"output": "707 505 681\n605 631 657\n581 757 555"
},
{
"input": "0 662 918\n822 0 854\n758 1014 0",
"output": "934 662 918\n822 838 854\n758 1014 742"
},
{
"input": "0 93 95\n93 0 97\n95 97 0",
"output": "97 93 95\n93 95 97\n95 97 93"
},
{
"input": "0 709 712\n719 0 695\n702 705 0",
"output": "700 709 712\n719 707 695\n702 705 714"
},
{
"input": "0 7 6\n9 0 1\n4 3 0",
"output": "2 7 6\n9 5 1\n4 3 8"
},
{
"input": "0 9 2\n3 0 7\n8 1 0",
"output": "4 9 2\n3 5 7\n8 1 6"
},
{
"input": "0 1 43\n13 0 61\n31 73 0",
"output": "67 1 43\n13 37 61\n31 73 7"
},
{
"input": "0 100000 100000\n100000 0 100000\n100000 100000 0",
"output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"
}
] | 1,642,147,574 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 512,000 | m=[]
for _ in range(3):
n=[int(i) for i in input().split()]
m.append(n)
a=-m[0][1]-m[0][2]+m[1][0]+m[1][2]
a1=m[2][0]+m[2][1]
b=m[1][0]+m[1][2]
x=int((a+a1)/2)
y=int((a1-a)/2)
z=int(b-x)
m[0][0]=x
m[1][1]=y
m[2][2]=z
for i in range(3):
for j in range(2):
print(m[i][j],end='')
print(m[i][2]) | Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes.
Input Specification:
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Output Specification:
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions.
Demo Input:
['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n']
Demo Output:
['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n']
Note:
none | ```python
m=[]
for _ in range(3):
n=[int(i) for i in input().split()]
m.append(n)
a=-m[0][1]-m[0][2]+m[1][0]+m[1][2]
a1=m[2][0]+m[2][1]
b=m[1][0]+m[1][2]
x=int((a+a1)/2)
y=int((a1-a)/2)
z=int(b-x)
m[0][0]=x
m[1][1]=y
m[2][2]=z
for i in range(3):
for j in range(2):
print(m[i][j],end='')
print(m[i][2])
``` | 0 |
|
120 | E | Put Knight! | PROGRAMMING | 1,400 | [
"games",
"math"
] | null | null | Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=*c*<=-<=2), (*r*<=+<=1,<=*c*<=+<=2), (*r*<=+<=1,<=*c*<=-<=2), (*r*<=-<=2,<=*c*<=+<=1), (*r*<=-<=2,<=*c*<=-<=1), (*r*<=+<=2,<=*c*<=+<=1) and (*r*<=+<=2,<=*c*<=-<=1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts. | The first line contains integer *T* (1<=≤<=*T*<=≤<=100) — the number of boards, for which you should determine the winning player. Next *T* lines contain *T* integers *n**i* (1<=≤<=*n**i*<=≤<=10000) — the sizes of the chessboards. | For each *n**i*<=×<=*n**i* board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1". | [
"2\n2\n1\n"
] | [
"1\n0\n"
] | none | 0 | [
{
"input": "2\n2\n1",
"output": "1\n0"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "0\n1\n0\n1\n0\n1\n0\n1\n0\n1"
},
{
"input": "15\n10\n4\n7\n8\n9\n6\n2\n1\n3\n1\n5\n2\n3\n4\n5",
"output": "1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0"
},
{
"input": "6\n10\n7\n10\n8\n5\n1",
"output": "1\n0\n1\n1\n0\n0"
},
{
"input": "100\n5\n6\n8\n7\n5\n7\n10\n2\n8\n3\n10\n3\n7\n3\n2\n7\n10\n3\n7\n3\n9\n5\n1\n1\n1\n5\n7\n5\n4\n8\n7\n3\n2\n10\n5\n10\n1\n10\n5\n2\n10\n6\n4\n10\n7\n6\n10\n8\n8\n5\n5\n7\n5\n7\n8\n6\n7\n8\n5\n8\n7\n9\n1\n1\n1\n5\n10\n6\n3\n3\n2\n7\n5\n2\n4\n4\n10\n1\n5\n2\n9\n1\n9\n9\n8\n2\n6\n9\n8\n2\n6\n2\n1\n10\n10\n8\n9\n7\n8\n8",
"output": "0\n1\n1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n0\n0\n1\n1"
},
{
"input": "100\n59\n95\n11\n67\n65\n90\n93\n53\n29\n63\n74\n47\n5\n67\n70\n67\n56\n66\n10\n33\n81\n63\n41\n77\n62\n58\n19\n95\n68\n2\n99\n85\n85\n94\n52\n87\n20\n85\n74\n58\n74\n85\n76\n95\n46\n1\n28\n89\n100\n75\n94\n46\n29\n21\n89\n42\n95\n72\n18\n65\n73\n99\n98\n59\n59\n74\n80\n47\n68\n58\n94\n1\n63\n90\n74\n77\n36\n9\n13\n100\n64\n55\n63\n70\n97\n50\n48\n7\n81\n25\n31\n64\n57\n12\n42\n61\n95\n83\n79\n84",
"output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1"
},
{
"input": "100\n62\n25\n86\n34\n47\n37\n38\n18\n42\n48\n39\n59\n74\n41\n58\n96\n50\n19\n40\n42\n43\n80\n100\n64\n54\n2\n36\n56\n80\n77\n29\n21\n87\n58\n87\n92\n30\n73\n87\n8\n30\n98\n52\n47\n67\n95\n12\n87\n98\n18\n16\n52\n36\n1\n100\n23\n49\n60\n89\n14\n100\n6\n34\n27\n30\n81\n33\n10\n59\n64\n74\n33\n28\n19\n78\n79\n87\n98\n30\n78\n42\n77\n80\n87\n34\n72\n19\n86\n36\n19\n15\n94\n61\n11\n32\n91\n44\n33\n32\n48",
"output": "1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1"
},
{
"input": "100\n17\n6\n14\n53\n81\n33\n31\n31\n4\n34\n4\n70\n94\n64\n46\n25\n92\n19\n70\n4\n57\n45\n59\n51\n47\n45\n2\n69\n91\n3\n10\n4\n89\n71\n21\n46\n87\n60\n100\n59\n37\n12\n75\n98\n88\n89\n49\n38\n44\n14\n39\n57\n95\n82\n11\n56\n51\n97\n9\n14\n27\n14\n17\n43\n2\n88\n37\n21\n98\n70\n55\n66\n93\n47\n30\n30\n87\n86\n46\n56\n67\n99\n98\n3\n23\n42\n90\n18\n91\n14\n46\n73\n65\n10\n70\n72\n45\n31\n84\n59",
"output": "0\n1\n1\n0\n0\n0\n0\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n0"
},
{
"input": "100\n20\n36\n41\n21\n15\n80\n24\n44\n18\n20\n17\n82\n63\n38\n34\n53\n85\n20\n48\n13\n19\n11\n18\n86\n39\n89\n20\n30\n3\n30\n39\n40\n91\n35\n56\n52\n97\n48\n12\n9\n93\n25\n50\n50\n9\n32\n85\n89\n42\n9\n14\n15\n54\n14\n70\n37\n5\n86\n80\n63\n6\n74\n1\n11\n22\n96\n89\n85\n37\n76\n83\n47\n58\n28\n83\n32\n38\n75\n63\n33\n45\n70\n16\n20\n59\n63\n62\n97\n46\n56\n30\n52\n17\n60\n61\n54\n94\n29\n37\n71",
"output": "1\n1\n0\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0"
},
{
"input": "100\n24\n18\n68\n40\n49\n27\n17\n9\n31\n6\n81\n93\n31\n12\n22\n82\n27\n20\n78\n23\n33\n76\n78\n73\n83\n32\n37\n91\n15\n4\n20\n75\n93\n48\n91\n58\n7\n36\n25\n59\n1\n38\n73\n1\n31\n26\n69\n40\n40\n53\n36\n21\n12\n95\n81\n17\n6\n23\n52\n11\n33\n81\n84\n80\n94\n3\n42\n48\n76\n81\n64\n79\n23\n56\n87\n82\n89\n63\n80\n11\n71\n92\n33\n37\n48\n33\n33\n77\n1\n50\n13\n82\n21\n59\n51\n83\n96\n27\n89\n83",
"output": "1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n0\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0"
},
{
"input": "100\n27\n47\n95\n7\n82\n22\n9\n21\n45\n40\n46\n5\n52\n34\n10\n11\n21\n73\n8\n85\n95\n41\n37\n8\n75\n24\n3\n52\n26\n31\n49\n11\n95\n12\n25\n12\n17\n71\n37\n10\n56\n51\n97\n100\n52\n20\n5\n91\n86\n48\n59\n26\n19\n27\n92\n50\n8\n60\n23\n11\n12\n89\n68\n96\n66\n58\n94\n59\n15\n39\n92\n12\n36\n85\n39\n84\n41\n52\n97\n89\n48\n14\n51\n53\n85\n54\n4\n9\n56\n44\n45\n61\n25\n58\n41\n65\n45\n25\n42\n94",
"output": "0\n0\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1"
},
{
"input": "100\n30\n29\n70\n26\n16\n70\n2\n34\n59\n26\n11\n16\n20\n8\n98\n39\n14\n73\n38\n94\n9\n6\n96\n95\n67\n68\n21\n13\n38\n57\n30\n95\n97\n25\n60\n17\n75\n59\n98\n60\n64\n64\n72\n52\n73\n15\n42\n41\n84\n91\n34\n32\n78\n7\n51\n31\n62\n49\n43\n60\n40\n49\n51\n64\n38\n66\n46\n23\n6\n45\n73\n92\n1\n65\n91\n86\n92\n40\n14\n19\n74\n36\n68\n70\n22\n76\n75\n88\n11\n86\n28\n39\n29\n9\n31\n47\n46\n23\n94\n6",
"output": "1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n1\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n0\n1\n0\n1\n1"
},
{
"input": "100\n34\n58\n97\n93\n50\n17\n95\n47\n72\n11\n76\n28\n89\n82\n86\n68\n56\n74\n68\n4\n72\n24\n3\n82\n60\n11\n39\n74\n50\n32\n59\n30\n99\n89\n94\n71\n84\n46\n10\n10\n19\n30\n95\n3\n94\n57\n26\n40\n82\n87\n56\n38\n37\n40\n62\n64\n64\n86\n14\n8\n19\n57\n87\n80\n58\n73\n99\n86\n45\n51\n53\n25\n66\n94\n95\n36\n43\n29\n31\n97\n52\n58\n86\n87\n10\n45\n46\n68\n66\n80\n60\n70\n33\n8\n22\n28\n96\n21\n47\n18",
"output": "1\n1\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n1"
},
{
"input": "100\n37\n88\n24\n60\n84\n12\n40\n12\n86\n97\n88\n39\n9\n4\n74\n97\n50\n75\n46\n65\n86\n89\n62\n17\n52\n55\n4\n88\n61\n58\n88\n66\n1\n2\n29\n77\n94\n34\n23\n9\n27\n43\n71\n55\n67\n52\n62\n91\n80\n82\n79\n95\n95\n20\n73\n45\n18\n23\n85\n9\n46\n64\n70\n48\n30\n80\n51\n97\n84\n57\n82\n57\n31\n22\n47\n39\n95\n17\n96\n74\n30\n81\n4\n3\n47\n67\n17\n99\n21\n74\n43\n49\n37\n6\n12\n58\n97\n20\n51\n30",
"output": "0\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n1"
},
{
"input": "100\n91\n83\n93\n95\n65\n56\n2\n7\n85\n42\n28\n26\n84\n62\n65\n23\n78\n49\n15\n100\n72\n86\n71\n19\n5\n71\n49\n100\n29\n59\n92\n82\n41\n53\n50\n57\n98\n80\n5\n65\n58\n68\n58\n72\n8\n64\n67\n44\n5\n79\n3\n59\n19\n22\n33\n85\n63\n23\n62\n50\n67\n52\n9\n14\n29\n31\n46\n3\n60\n82\n60\n12\n89\n87\n95\n51\n87\n54\n16\n36\n67\n90\n72\n77\n10\n14\n9\n76\n92\n82\n85\n59\n87\n75\n52\n76\n79\n24\n33\n76",
"output": "0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1"
}
] | 1,665,366,252 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | t = int(input())
for _ in range(t):
n = int(input())
print(1 - n % 2) | Title: Put Knight!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=*c*<=-<=2), (*r*<=+<=1,<=*c*<=+<=2), (*r*<=+<=1,<=*c*<=-<=2), (*r*<=-<=2,<=*c*<=+<=1), (*r*<=-<=2,<=*c*<=-<=1), (*r*<=+<=2,<=*c*<=+<=1) and (*r*<=+<=2,<=*c*<=-<=1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts.
Input Specification:
The first line contains integer *T* (1<=≤<=*T*<=≤<=100) — the number of boards, for which you should determine the winning player. Next *T* lines contain *T* integers *n**i* (1<=≤<=*n**i*<=≤<=10000) — the sizes of the chessboards.
Output Specification:
For each *n**i*<=×<=*n**i* board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1".
Demo Input:
['2\n2\n1\n']
Demo Output:
['1\n0\n']
Note:
none | ```python
t = int(input())
for _ in range(t):
n = int(input())
print(1 - n % 2)
``` | -1 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,696,672,691 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | ans = 0
for _ in range(int(input())):
x = input().split(' ')
l = []
for i in x:
l.append(int(i))
num = 0
ans = ans + (sum(l) >= 2)
print(ans) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
ans = 0
for _ in range(int(input())):
x = input().split(' ')
l = []
for i in x:
l.append(int(i))
num = 0
ans = ans + (sum(l) >= 2)
print(ans)
``` | 3 |
|
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator. | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training. | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
},
{
"input": "3\n1 1 3",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "5\n1 2 4 3 5",
"output": "4"
},
{
"input": "5\n2 2 2 4 3",
"output": "4"
},
{
"input": "4\n1 2 3 1",
"output": "3"
},
{
"input": "6\n7 3 10 7 3 11",
"output": "4"
},
{
"input": "2\n3 4",
"output": "2"
},
{
"input": "5\n1 1 1 1 1",
"output": "3"
},
{
"input": "4\n1 3 2 3",
"output": "3"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "3\n32 10 23",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "3\n1 2 4",
"output": "3"
},
{
"input": "6\n3 3 3 2 4 4",
"output": "4"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "5\n1 3 3 1 1",
"output": "3"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "4\n1 2 1 3",
"output": "3"
},
{
"input": "3\n2 2 1",
"output": "2"
},
{
"input": "4\n2 3 3 3",
"output": "3"
},
{
"input": "4\n3 2 3 3",
"output": "3"
},
{
"input": "4\n2 1 1 1",
"output": "2"
},
{
"input": "3\n2 1 4",
"output": "3"
},
{
"input": "2\n6 7",
"output": "2"
},
{
"input": "4\n3 3 4 3",
"output": "3"
},
{
"input": "4\n1 1 2 5",
"output": "4"
},
{
"input": "4\n1 8 7 3",
"output": "3"
},
{
"input": "6\n2 2 2 2 2 3",
"output": "4"
},
{
"input": "3\n2 2 5",
"output": "3"
},
{
"input": "4\n1 1 2 1",
"output": "3"
},
{
"input": "5\n1 1 2 2 3",
"output": "4"
},
{
"input": "5\n9 5 3 4 8",
"output": "3"
},
{
"input": "3\n3 3 1",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "3"
},
{
"input": "3\n1 3 5",
"output": "3"
},
{
"input": "4\n1 1 3 6",
"output": "4"
},
{
"input": "6\n1 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n3 1 3",
"output": "2"
},
{
"input": "5\n3 4 5 1 2",
"output": "3"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "5\n3 1 2 5 2",
"output": "4"
},
{
"input": "4\n1 1 1 4",
"output": "4"
},
{
"input": "4\n2 6 1 10",
"output": "4"
},
{
"input": "4\n2 2 3 2",
"output": "3"
},
{
"input": "4\n4 2 2 1",
"output": "2"
},
{
"input": "6\n1 1 1 1 1 4",
"output": "5"
},
{
"input": "3\n3 2 2",
"output": "2"
},
{
"input": "6\n1 3 5 1 7 4",
"output": "5"
},
{
"input": "5\n1 2 4 8 16",
"output": "5"
},
{
"input": "5\n1 2 4 4 4",
"output": "4"
},
{
"input": "6\n4 2 1 2 3 1",
"output": "3"
},
{
"input": "4\n3 2 1 5",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n2 4 7",
"output": "3"
},
{
"input": "5\n1 1 1 1 3",
"output": "4"
},
{
"input": "3\n3 1 5",
"output": "3"
},
{
"input": "4\n1 2 3 7",
"output": "4"
},
{
"input": "3\n1 4 6",
"output": "3"
},
{
"input": "4\n2 1 2 2",
"output": "3"
},
{
"input": "2\n4 5",
"output": "2"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "3\n2 3 6",
"output": "3"
},
{
"input": "6\n1 1 4 1 1 5",
"output": "4"
},
{
"input": "5\n2 2 2 2 1",
"output": "3"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "4\n2 2 1 4",
"output": "3"
},
{
"input": "5\n2 2 3 4 4",
"output": "4"
},
{
"input": "4\n3 1 1 2",
"output": "2"
},
{
"input": "5\n3 4 1 4 5",
"output": "4"
},
{
"input": "4\n1 3 1 6",
"output": "4"
},
{
"input": "5\n1 1 1 2 2",
"output": "4"
},
{
"input": "4\n1 4 2 4",
"output": "3"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 8",
"output": "9"
},
{
"input": "4\n1 4 5 1",
"output": "3"
},
{
"input": "5\n1 1 1 1 5",
"output": "5"
},
{
"input": "4\n1 3 4 1",
"output": "3"
},
{
"input": "4\n2 2 2 3",
"output": "3"
},
{
"input": "4\n2 3 2 4",
"output": "3"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "3\n4 3 2",
"output": "2"
},
{
"input": "3\n6 5 2",
"output": "2"
},
{
"input": "69\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",
"output": "35"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "4"
},
{
"input": "5\n1 2 5 4 5",
"output": "4"
},
{
"input": "2\n9 10",
"output": "2"
},
{
"input": "3\n1 1 5",
"output": "3"
},
{
"input": "4\n3 4 3 5",
"output": "3"
},
{
"input": "4\n1 4 3 3",
"output": "3"
},
{
"input": "4\n7 1 3 4",
"output": "2"
},
{
"input": "3\n100 100 1",
"output": "2"
},
{
"input": "4\n5 2 2 2",
"output": "2"
}
] | 1,592,239,239 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 170 | 14,131,200 | from math import ceil
n=int(input())
a=list(map(int,input().split()))
s=sum(a); hf=ceil(s/2); s2=0
for i in range(n):
s2+=a[i]
if s2>=hf: print(i+1); break | Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Output Specification:
Print the index of the day when Polycarp will celebrate the equator.
Demo Input:
['4\n1 3 2 1\n', '6\n2 2 2 2 2 2\n']
Demo Output:
['2\n', '3\n']
Note:
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training. | ```python
from math import ceil
n=int(input())
a=list(map(int,input().split()))
s=sum(a); hf=ceil(s/2); s2=0
for i in range(n):
s2+=a[i]
if s2>=hf: print(i+1); break
``` | 3 |
|
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872",
"output": "NO"
},
{
"input": "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122\n-8984 6122\n7137 -326",
"output": "YES"
},
{
"input": "12\n-9765 1132\n-1382 -215\n-9405 7284\n-2040 3947\n-9360 3150\n6425 9386\n806 -2278\n-2121 -7284\n5663 -1608\n-8377 9297\n6245 708\n8470 6024",
"output": "YES"
},
{
"input": "15\n8122 -9991\n-4068 -3386\n8971 3731\n3458 5161\n-8700 7562\n2691 8735\n-1510 -3892\n5183 -3753\n-7018 6637\n-7454 3386\n-818 -6377\n6771 -8647\n-7357 -1246\n-6186 1922\n9889 -3627",
"output": "YES"
},
{
"input": "20\n-5264 6424\n-3664 -7459\n-2780 -9859\n-3317 6842\n5681 -8092\n1555 1904\n-6684 1414\n6593 -1253\n-5708 -1202\n335 1733\n-926 7579\n3459 -1904\n-4486 4006\n6201 3616\n2847 -5255\n8438 7057\n8171 6042\n-9102 3545\n7731 -233\n6264 6563",
"output": "YES"
},
{
"input": "30\n-398 -1774\n313 -6974\n2346 -4657\n8552 -9647\n-5265 1538\n8195 4864\n-5641 -5219\n-1394 8563\n-1190 1992\n-4669 -1156\n7574 256\n9206 -2414\n4140 -549\n-294 2169\n7029 -2871\n3808 -9799\n3141 5690\n4648 -2680\n-5990 9800\n-2299 1697\n6077 -7177\n-400 -9724\n-4644 -2392\n-2198 -9531\n-2105 9386\n-8165 -4201\n-1589 -7916\n2518 -7840\n4173 -6949\n-3368 -9943",
"output": "NO"
}
] | 1,645,291,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
original_post=[]
final_spit=[]
for i in range(0,n):
x,d=[int(x) for x in input().split()]
original_post.append(x)
final_spit.append(x+d)
cnt=0
print(original_post)
print(final_spit)
for i in range(0,n):
p=original_post[i]
if(p in final_spit):
k=final_spit[i]
i=final_spit.index(p)
if(original_post[i]==k):
cnt+=1
if(cnt!=0):
print("YES")
else:
print("NO") | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.
Output Specification:
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
Demo Input:
['2\n0 1\n1 -1\n', '3\n0 1\n1 1\n2 -2\n', '5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
n=int(input())
original_post=[]
final_spit=[]
for i in range(0,n):
x,d=[int(x) for x in input().split()]
original_post.append(x)
final_spit.append(x+d)
cnt=0
print(original_post)
print(final_spit)
for i in range(0,n):
p=original_post[i]
if(p in final_spit):
k=final_spit[i]
i=final_spit.index(p)
if(original_post[i]==k):
cnt+=1
if(cnt!=0):
print("YES")
else:
print("NO")
``` | 0 |
922 | C | Cave Painting | PROGRAMMING | 1,600 | [
"brute force",
"number theory"
] | null | null | Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that:
- 1<=≤<=*i*<=<<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*. | The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). | Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper). | [
"4 4\n",
"5 3\n"
] | [
"No\n",
"Yes\n"
] | In the first sample remainders modulo 1 and 4 coincide. | 1,250 | [
{
"input": "4 4",
"output": "No"
},
{
"input": "5 3",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "744 18",
"output": "No"
},
{
"input": "47879 10",
"output": "Yes"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "No"
},
{
"input": "657180569218773599 42",
"output": "Yes"
},
{
"input": "442762254977842799 30",
"output": "Yes"
},
{
"input": "474158606260730555 1",
"output": "Yes"
},
{
"input": "807873101233533988 39",
"output": "No"
},
{
"input": "423 7",
"output": "No"
},
{
"input": "264306177888923090 5",
"output": "No"
},
{
"input": "998857801526481788 87",
"output": "No"
},
{
"input": "999684044704565212 28",
"output": "No"
},
{
"input": "319575605003866172 71",
"output": "No"
},
{
"input": "755804560577415016 17",
"output": "No"
},
{
"input": "72712630136142067 356370939",
"output": "No"
},
{
"input": "807264258068668062 33080422",
"output": "No"
},
{
"input": "808090496951784190 311661970",
"output": "No"
},
{
"input": "808916740129867614 180178111",
"output": "No"
},
{
"input": "1 2",
"output": "Yes"
},
{
"input": "2 1",
"output": "Yes"
},
{
"input": "57334064998850639 19",
"output": "Yes"
},
{
"input": "144353716412182199 11",
"output": "Yes"
},
{
"input": "411002215096001759 11",
"output": "Yes"
},
{
"input": "347116374613371527 3",
"output": "Yes"
},
{
"input": "518264351335130399 37",
"output": "Yes"
},
{
"input": "192435891235905239 11",
"output": "Yes"
},
{
"input": "491802505049361659 7",
"output": "Yes"
},
{
"input": "310113769227703889 3",
"output": "Yes"
},
{
"input": "876240758958364799 41",
"output": "Yes"
},
{
"input": "173284263472319999 33",
"output": "Yes"
},
{
"input": "334366426725130799 29",
"output": "Yes"
},
{
"input": "415543470272330399 26",
"output": "Yes"
},
{
"input": "631689521541558479 22",
"output": "Yes"
},
{
"input": "581859366558790319 14",
"output": "Yes"
},
{
"input": "224113913709159599 10",
"output": "Yes"
},
{
"input": "740368848764104559 21",
"output": "Yes"
},
{
"input": "895803074828822159 17",
"output": "Yes"
},
{
"input": "400349974997012039 13",
"output": "Yes"
},
{
"input": "205439024252247599 5",
"output": "Yes"
},
{
"input": "197688463911338399 39",
"output": "Yes"
},
{
"input": "283175367224349599 39",
"output": "Yes"
},
{
"input": "893208176423362799 31",
"output": "Yes"
},
{
"input": "440681012669897999 27",
"output": "Yes"
},
{
"input": "947403664618451039 19",
"output": "Yes"
},
{
"input": "232435556779345919 19",
"output": "Yes"
},
{
"input": "504428493840551279 23",
"output": "Yes"
},
{
"input": "30019549241681999 20",
"output": "Yes"
},
{
"input": "648000813924303839 16",
"output": "Yes"
},
{
"input": "763169499725761451 488954176053755860",
"output": "No"
},
{
"input": "199398459594277592 452260924647536414",
"output": "No"
},
{
"input": "635627415167826436 192195636386541160",
"output": "No"
},
{
"input": "71856370741375281 155502380685354417",
"output": "No"
},
{
"input": "731457367464667229 118809129279134971",
"output": "No"
},
{
"input": "167686318743248777 858743836723172421",
"output": "No"
},
{
"input": "603915274316797622 822050585316952974",
"output": "No"
},
{
"input": "647896534275160623 65689274138731296",
"output": "No"
},
{
"input": "648722777453244047 501918229712280140",
"output": "No"
},
{
"input": "649549020631327471 41923378183538525",
"output": "No"
},
{
"input": "650375259514443599 597748177714153637",
"output": "No"
},
{
"input": "651201506987494319 33977137582669778",
"output": "No"
},
{
"input": "652027745870610447 470206093156218622",
"output": "No"
},
{
"input": "652853989048693871 906435048729767466",
"output": "No"
},
{
"input": "653680227931809999 342664004303316311",
"output": "No"
},
{
"input": "654506475404860719 375019787446735639",
"output": "No"
},
{
"input": "655332714287976847 438493956600157103",
"output": "No"
},
{
"input": "166512305365727033 900267947832156186",
"output": "No"
},
{
"input": "167338548543810457 336496907700672326",
"output": "No"
},
{
"input": "168164787426926585 772725863274221171",
"output": "No"
},
{
"input": "523 3",
"output": "No"
},
{
"input": "39211 6",
"output": "No"
},
{
"input": "22151 9",
"output": "No"
},
{
"input": "1 3",
"output": "No"
},
{
"input": "47 5",
"output": "No"
},
{
"input": "999999998999999999 1000000000",
"output": "No"
},
{
"input": "11 6",
"output": "No"
},
{
"input": "7 4",
"output": "No"
},
{
"input": "1 10",
"output": "No"
},
{
"input": "9 5",
"output": "No"
},
{
"input": "2519 20",
"output": "No"
},
{
"input": "700001 3",
"output": "Yes"
},
{
"input": "13 7",
"output": "No"
},
{
"input": "999999 10000",
"output": "No"
},
{
"input": "1 4",
"output": "No"
},
{
"input": "232792559 30",
"output": "No"
},
{
"input": "1 5",
"output": "No"
},
{
"input": "5 4",
"output": "No"
},
{
"input": "5 8",
"output": "No"
},
{
"input": "55 4",
"output": "No"
}
] | 1,592,827,301 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 93 | 0 | n,k = map(int, input().split())
if not n&1:
print('No')
else:
d = {}
i,f = 1, True
while i <= k:
if (n%i) in d:
f = False
break
else:
d[(n%i)] = 1
i += 1
print('Yes' if f else 'No')
| Title: Cave Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that:
- 1<=≤<=*i*<=<<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*.
Input Specification:
The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018).
Output Specification:
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
Demo Input:
['4 4\n', '5 3\n']
Demo Output:
['No\n', 'Yes\n']
Note:
In the first sample remainders modulo 1 and 4 coincide. | ```python
n,k = map(int, input().split())
if not n&1:
print('No')
else:
d = {}
i,f = 1, True
while i <= k:
if (n%i) in d:
f = False
break
else:
d[(n%i)] = 1
i += 1
print('Yes' if f else 'No')
``` | 0 |
|
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input": "2\n100 100",
"output": "2"
},
{
"input": "3\n100 100 100",
"output": "3"
},
{
"input": "11\n1 2 3 4 5 6 5 4 3 2 1",
"output": "11"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1",
"output": "81"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1",
"output": "85"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 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 100 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 100 8 7 6 1 4 3 2 1",
"output": "96"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 100 10 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 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 100 11 10 9 8 7 6 5 4 3 2 1",
"output": "55"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "59"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "86"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "83"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "74"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "52"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1",
"output": "98"
},
{
"input": "10\n1 4 4 4 4 4 1 2 4 3",
"output": "7"
}
] | 1,696,075,989 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 80 | 124 | 2,252,800 | # Author : //- kibrom Hailu -\\
import sys
# from collections import Counter, defaultdict, deque
# from math import ceil, floor, gcd, inf, sqrt
# from itertools import permutations, combinations, accumulate
# from bisect import bisect_left, bisect_right
# from heapq imortt heapify , heappop , heappush , heappushpop , heapreplace
def SI():return sys.stdin.readline().rstrip()
def I():return int(SI())
def M():return map(int, SI().split())
def IL():return list(map(int, SI().split()))
def F():return float(SI())
def FL():return list(map(float, SI().split()))
def main():
n = I()
arr = IL()
def maxres(x,arr):
ans = 0
l = x-1
r = x+1
while l > -1 or r < len(arr):
if (l > -1 and r < len(arr)) and (arr[l+1] >= arr[l] and arr[r-1] >= arr[r]):
ans += 2
l -= 1
r += 1
elif l > -1 and arr[l+1] >= arr[l]:
ans += 1
l -= 1
elif r < len(arr) and arr[r-1] >= arr[r]:
ans += 1
r += 1
else: break
return ans
max_ans = 0
for i in range(n):
max_ans = max(max_ans,maxres(i,arr)+1)
print(max_ans)
if __name__ == "__main__":
main()
| Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output Specification:
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Demo Input:
['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n']
Demo Output:
['1\n', '3\n', '6\n']
Note:
none | ```python
# Author : //- kibrom Hailu -\\
import sys
# from collections import Counter, defaultdict, deque
# from math import ceil, floor, gcd, inf, sqrt
# from itertools import permutations, combinations, accumulate
# from bisect import bisect_left, bisect_right
# from heapq imortt heapify , heappop , heappush , heappushpop , heapreplace
def SI():return sys.stdin.readline().rstrip()
def I():return int(SI())
def M():return map(int, SI().split())
def IL():return list(map(int, SI().split()))
def F():return float(SI())
def FL():return list(map(float, SI().split()))
def main():
n = I()
arr = IL()
def maxres(x,arr):
ans = 0
l = x-1
r = x+1
while l > -1 or r < len(arr):
if (l > -1 and r < len(arr)) and (arr[l+1] >= arr[l] and arr[r-1] >= arr[r]):
ans += 2
l -= 1
r += 1
elif l > -1 and arr[l+1] >= arr[l]:
ans += 1
l -= 1
elif r < len(arr) and arr[r-1] >= arr[r]:
ans += 1
r += 1
else: break
return ans
max_ans = 0
for i in range(n):
max_ans = max(max_ans,maxres(i,arr)+1)
print(max_ans)
if __name__ == "__main__":
main()
``` | 3.964804 |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better. | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"
},
{
"input": "0\n2",
"output": "***\n*0*\n*2*\n***"
},
{
"input": "O\no\nd",
"output": "***\n*O*\n*o*\n*d*\n***"
},
{
"input": "0v uO M6Sy",
"output": "************\n*0v uO M6Sy*\n************"
},
{
"input": "fm v\nOL U W",
"output": "**********\n* fm v *\n*OL U W*\n**********"
},
{
"input": "vb\nJ\nyU\nZ",
"output": "****\n*vb*\n*J *\n*yU*\n* Z*\n****"
},
{
"input": "N\nSV\nEh\n6f\nX6\n9e",
"output": "****\n*N *\n*SV*\n*Eh*\n*6f*\n*X6*\n*9e*\n****"
},
{
"input": "Pj\nA\nFA\nP\nVJ\nU\nEb\nW",
"output": "****\n*Pj*\n*A *\n*FA*\n* P*\n*VJ*\n*U *\n*Eb*\n* W*\n****"
},
{
"input": "T\n7j\nS\nb\nq8\nVZ\nn\n4T\niZ\npA",
"output": "****\n*T *\n*7j*\n* S*\n*b *\n*q8*\n*VZ*\n* n*\n*4T*\n*iZ*\n*pA*\n****"
},
{
"input": "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\nSr\n\n\nV\n\n5\n\nAq\n\n\n\nJ\nR\n\n04\nJ\nv\nhU\n\n\n\nY\nG\n4\n\nG\nb\n\n\n9\n\n6\nd\n\n2\n\n\nE\n7\n\nr\n\n\n\n\nKC\ns\nE\n\nab\n4\nx\n\n\n\n\n\nEe\n4\n\nl\n\np\n\nG\nM\n\n\nn\n\n\nm0\n\nw\n\n\nP\n\n\n\n0",
"output": "****\n*8 *\n* *\n* *\n* *\n* y*\n*W *\n* *\n* *\n* *\n*3B*\n* *\n* w*\n*V *\n* *\n* *\n* *\n* L*\n*Sr*\n* *\n* *\n*V *\n* *\n* 5*\n* *\n*Aq*\n* *\n* *\n* *\n*J *\n* R*\n* *\n*04*\n*J *\n* v*\n*hU*\n* *\n* *\n* *\n*Y *\n* G*\n*4 *\n* *\n* G*\n*b *\n* *\n* *\n* 9*\n* *\n*6 *\n* d*\n* *\n*2 *\n* *\n* *\n* E*\n*7 *\n* *\n* r*\n* *\n* *\n* *\n* *\n*KC*\n*s *\n* E*\n* *\n*ab*\n*4 *\n* x*\n* *\n* *\n* *\n* *\n* *\n*Ee*\n*4 *\n* *\n* l*\n* *\n*p *\n* *\n* G*\n*M *\n* *\n*..."
},
{
"input": "U",
"output": "***\n*U*\n***"
}
] | 1,684,820,855 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | lines=[]
max_length=0
while True:
try:
line=input().strip()
except EOFError:
break
lines.append(line)
max_length=max(max_length,len(line))
width=max_length+2
print("*"*width)
align_left=True
for line in lines:
line_length=len(line)
if line_length%2!=width%2:
if align_left:
start_position=0
else:
start_position=width-line_length
align_left=not align_left
else:
start_position=(width-line_length)//2
formatted_line="*"+" "*start_position+line+" "*(width-start_position-line_length)+"*"
print(formatted_line)
print("*"*width) | Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck!
Input Specification:
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Output Specification:
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
Demo Input:
['This is\n\nCodeforces\nBeta\nRound\n5\n', 'welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n']
Demo Output:
['************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n', '****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n']
Note:
none | ```python
lines=[]
max_length=0
while True:
try:
line=input().strip()
except EOFError:
break
lines.append(line)
max_length=max(max_length,len(line))
width=max_length+2
print("*"*width)
align_left=True
for line in lines:
line_length=len(line)
if line_length%2!=width%2:
if align_left:
start_position=0
else:
start_position=width-line_length
align_left=not align_left
else:
start_position=(width-line_length)//2
formatted_line="*"+" "*start_position+line+" "*(width-start_position-line_length)+"*"
print(formatted_line)
print("*"*width)
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109) — the number of elements in the permutation and the lexicographical number of the permutation. | If the *k*-th permutation of numbers from 1 to *n* does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes *i*, that *i* and *a**i* are both lucky numbers. | [
"7 4\n",
"4 7\n"
] | [
"1\n",
"1\n"
] | A permutation is an ordered set of *n* elements, where each integer from 1 to *n* occurs exactly once. The element of permutation in position with index *i* is denoted as *a*<sub class="lower-index">*i*</sub> (1 ≤ *i* ≤ *n*). Permutation *a* is lexicographically smaller that permutation *b* if there is such a *i* (1 ≤ *i* ≤ *n*), that *a*<sub class="lower-index">*i*</sub> < *b*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* < *i*) *a*<sub class="lower-index">*j*</sub> = *b*<sub class="lower-index">*j*</sub>. Let's make a list of all possible permutations of *n* elements and sort it in the order of lexicographical increasing. Then the lexicographically *k*-th permutation is the *k*-th element of this list of permutations.
In the first sample the permutation looks like that:
1 2 3 4 6 7 5
The only suitable position is 4.
In the second sample the permutation looks like that:
2 1 3 4
The only suitable position is 4. | 0 | [
{
"input": "7 4",
"output": "1"
},
{
"input": "4 7",
"output": "1"
},
{
"input": "7 1",
"output": "2"
},
{
"input": "7 5040",
"output": "1"
},
{
"input": "10 1023",
"output": "0"
},
{
"input": "7 7477",
"output": "-1"
},
{
"input": "10 10000",
"output": "1"
},
{
"input": "3 7",
"output": "-1"
},
{
"input": "27 1",
"output": "2"
},
{
"input": "40 8544",
"output": "2"
},
{
"input": "47 1",
"output": "4"
},
{
"input": "47 8547744",
"output": "3"
},
{
"input": "50 1000000000",
"output": "4"
},
{
"input": "64 87",
"output": "4"
},
{
"input": "98 854555",
"output": "6"
},
{
"input": "100 1",
"output": "6"
},
{
"input": "9985 5888454",
"output": "30"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1000000000",
"output": "-1"
},
{
"input": "10 1000000000",
"output": "-1"
},
{
"input": "20 1000000000",
"output": "2"
},
{
"input": "777777 1",
"output": "126"
},
{
"input": "777777 2",
"output": "125"
},
{
"input": "777474 10000",
"output": "120"
},
{
"input": "1000000000 1",
"output": "1022"
},
{
"input": "777777777 5",
"output": "1021"
},
{
"input": "777777777 1",
"output": "1022"
},
{
"input": "777477774 1",
"output": "989"
},
{
"input": "444747744 1000000000",
"output": "554"
},
{
"input": "475 88555458",
"output": "8"
},
{
"input": "12 855448",
"output": "1"
},
{
"input": "20 1000000000",
"output": "2"
},
{
"input": "47 99998544",
"output": "2"
},
{
"input": "49 1000000000",
"output": "2"
},
{
"input": "854459 95554455",
"output": "126"
},
{
"input": "77777779 1000000000",
"output": "508"
},
{
"input": "77 47",
"output": "5"
},
{
"input": "6999 85488877",
"output": "22"
},
{
"input": "7479 58884598",
"output": "24"
},
{
"input": "1000000000 1000000000",
"output": "1022"
},
{
"input": "7 1000",
"output": "0"
},
{
"input": "7 124",
"output": "1"
},
{
"input": "7 2048",
"output": "1"
},
{
"input": "7 3001",
"output": "1"
},
{
"input": "7 127",
"output": "1"
},
{
"input": "7 980",
"output": "1"
},
{
"input": "7 5000",
"output": "0"
},
{
"input": "7 4095",
"output": "2"
},
{
"input": "7 3856",
"output": "0"
},
{
"input": "7 5032",
"output": "0"
},
{
"input": "7 4999",
"output": "0"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-1"
},
{
"input": "7 985",
"output": "1"
},
{
"input": "4 25",
"output": "-1"
},
{
"input": "6 121",
"output": "1"
},
{
"input": "11 39916801",
"output": "-1"
},
{
"input": "29 1000000000",
"output": "2"
},
{
"input": "10 4589",
"output": "1"
},
{
"input": "10 100000",
"output": "1"
},
{
"input": "10 98564",
"output": "1"
},
{
"input": "10 1",
"output": "2"
},
{
"input": "10 100000009",
"output": "-1"
}
] | 1,691,484,434 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1691484434.4335277")# 1691484434.433544 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109) — the number of elements in the permutation and the lexicographical number of the permutation.
Output Specification:
If the *k*-th permutation of numbers from 1 to *n* does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes *i*, that *i* and *a**i* are both lucky numbers.
Demo Input:
['7 4\n', '4 7\n']
Demo Output:
['1\n', '1\n']
Note:
A permutation is an ordered set of *n* elements, where each integer from 1 to *n* occurs exactly once. The element of permutation in position with index *i* is denoted as *a*<sub class="lower-index">*i*</sub> (1 ≤ *i* ≤ *n*). Permutation *a* is lexicographically smaller that permutation *b* if there is such a *i* (1 ≤ *i* ≤ *n*), that *a*<sub class="lower-index">*i*</sub> < *b*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* < *i*) *a*<sub class="lower-index">*j*</sub> = *b*<sub class="lower-index">*j*</sub>. Let's make a list of all possible permutations of *n* elements and sort it in the order of lexicographical increasing. Then the lexicographically *k*-th permutation is the *k*-th element of this list of permutations.
In the first sample the permutation looks like that:
1 2 3 4 6 7 5
The only suitable position is 4.
In the second sample the permutation looks like that:
2 1 3 4
The only suitable position is 4. | ```python
print("_RANDOM_GUESS_1691484434.4335277")# 1691484434.433544
``` | 0 |
|
735 | D | Taxes | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while for *n*<==<=25 he needs to pay 5 and if *n*<==<=2 he pays only 1 burle.
As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial *n* in several parts *n*1<=+<=*n*2<=+<=...<=+<=*n**k*<==<=*n* (here *k* is arbitrary, even *k*<==<=1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition *n**i*<=≥<=2 should hold for all *i* from 1 to *k*.
Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split *n* in parts. | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. | Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. | [
"4\n",
"27\n"
] | [
"2\n",
"3\n"
] | none | 1,750 | [
{
"input": "4",
"output": "2"
},
{
"input": "27",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "2000000000",
"output": "2"
},
{
"input": "26",
"output": "2"
},
{
"input": "7",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "11",
"output": "1"
},
{
"input": "1000000007",
"output": "1"
},
{
"input": "1000000009",
"output": "1"
},
{
"input": "1999999999",
"output": "3"
},
{
"input": "1000000011",
"output": "2"
},
{
"input": "101",
"output": "1"
},
{
"input": "103",
"output": "1"
},
{
"input": "1001",
"output": "3"
},
{
"input": "1003",
"output": "3"
},
{
"input": "10001",
"output": "3"
},
{
"input": "10003",
"output": "3"
},
{
"input": "129401294",
"output": "2"
},
{
"input": "234911024",
"output": "2"
},
{
"input": "192483501",
"output": "3"
},
{
"input": "1234567890",
"output": "2"
},
{
"input": "719241201",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "33",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "15",
"output": "2"
},
{
"input": "147",
"output": "3"
},
{
"input": "60119912",
"output": "2"
},
{
"input": "45",
"output": "2"
},
{
"input": "21",
"output": "2"
},
{
"input": "9975",
"output": "2"
},
{
"input": "17",
"output": "1"
},
{
"input": "99",
"output": "2"
},
{
"input": "49",
"output": "2"
},
{
"input": "243",
"output": "2"
},
{
"input": "43",
"output": "1"
},
{
"input": "39",
"output": "2"
},
{
"input": "6",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "1"
},
{
"input": "14",
"output": "2"
},
{
"input": "16",
"output": "2"
},
{
"input": "18",
"output": "2"
},
{
"input": "19",
"output": "1"
},
{
"input": "20",
"output": "2"
},
{
"input": "22",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "24",
"output": "2"
},
{
"input": "962",
"output": "2"
},
{
"input": "29",
"output": "1"
},
{
"input": "55",
"output": "2"
},
{
"input": "125",
"output": "3"
},
{
"input": "1999999929",
"output": "2"
},
{
"input": "493",
"output": "2"
},
{
"input": "10000021",
"output": "2"
},
{
"input": "541",
"output": "1"
},
{
"input": "187",
"output": "3"
},
{
"input": "95",
"output": "3"
},
{
"input": "999991817",
"output": "3"
},
{
"input": "37998938",
"output": "2"
},
{
"input": "1847133842",
"output": "2"
},
{
"input": "1000000005",
"output": "3"
},
{
"input": "19828",
"output": "2"
},
{
"input": "998321704",
"output": "2"
},
{
"input": "370359",
"output": "3"
},
{
"input": "115",
"output": "2"
},
{
"input": "200000015",
"output": "3"
},
{
"input": "479001600",
"output": "2"
},
{
"input": "536870912",
"output": "2"
},
{
"input": "10759922",
"output": "2"
},
{
"input": "1999999927",
"output": "1"
},
{
"input": "123",
"output": "3"
},
{
"input": "200743933",
"output": "3"
},
{
"input": "949575615",
"output": "3"
},
{
"input": "99990001",
"output": "1"
},
{
"input": "715827883",
"output": "1"
},
{
"input": "5592406",
"output": "2"
},
{
"input": "8388609",
"output": "3"
},
{
"input": "1908903481",
"output": "3"
},
{
"input": "1076153021",
"output": "3"
},
{
"input": "344472101",
"output": "3"
}
] | 1,590,402,991 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 109 | 307,200 | from math import sqrt
primes = []
def initialize(MAX):
numbers = [0] * (MAX + 1)
n = MAX
numbers[1]==False
for i in range(2, int(sqrt(n)) + 1):
if (not numbers[i]):
for j in range(i * i, n + 1, i):
# Set the non-primes to true
numbers[j] = True;
for i in range(1, n + 1):
if (numbers[i] == False):
primes.append(i);
def combinationSum(nums, target):
res = []
nums.sort()
def dfs(left, path, idx):
if not left:
res.append(path[:])
else:
for i, val in enumerate(nums[idx:]):
if val > left: break
dfs(left - val, path + [val], idx + i)
dfs(target, [], 0)
return res
num=int(input())
initialize(num)
x=num
print(len(max(combinationSum(primes,num)))) | Title: Taxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while for *n*<==<=25 he needs to pay 5 and if *n*<==<=2 he pays only 1 burle.
As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial *n* in several parts *n*1<=+<=*n*2<=+<=...<=+<=*n**k*<==<=*n* (here *k* is arbitrary, even *k*<==<=1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition *n**i*<=≥<=2 should hold for all *i* from 1 to *k*.
Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split *n* in parts.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt.
Output Specification:
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
Demo Input:
['4\n', '27\n']
Demo Output:
['2\n', '3\n']
Note:
none | ```python
from math import sqrt
primes = []
def initialize(MAX):
numbers = [0] * (MAX + 1)
n = MAX
numbers[1]==False
for i in range(2, int(sqrt(n)) + 1):
if (not numbers[i]):
for j in range(i * i, n + 1, i):
# Set the non-primes to true
numbers[j] = True;
for i in range(1, n + 1):
if (numbers[i] == False):
primes.append(i);
def combinationSum(nums, target):
res = []
nums.sort()
def dfs(left, path, idx):
if not left:
res.append(path[:])
else:
for i, val in enumerate(nums[idx:]):
if val > left: break
dfs(left - val, path + [val], idx + i)
dfs(target, [], 0)
return res
num=int(input())
initialize(num)
x=num
print(len(max(combinationSum(primes,num))))
``` | -1 |
|
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,597,672,291 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 280 | 0 | s=input()
p=input()
if(p==s[::-1]):
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()
p=input()
if(p==s[::-1]):
print("YES")
else:
print("NO")
``` | 3.93 |
416 | B | Art Union | PROGRAMMING | 1,300 | [
"brute force",
"dp",
"implementation"
] | null | null | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these *n* colors. Adding the *j*-th color to the *i*-th picture takes the *j*-th painter *t**ij* units of time.
Order is important everywhere, so the painters' work is ordered by the following rules:
- Each picture is first painted by the first painter, then by the second one, and so on. That is, after the *j*-th painter finishes working on the picture, it must go to the (*j*<=+<=1)-th painter (if *j*<=<<=*n*); - each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on; - each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest; - as soon as the *j*-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.
Given that the painters start working at time 0, find for each picture the time when it is ready for sale. | The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), where *t**ij* is the time the *j*-th painter needs to work on the *i*-th picture. | Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture. | [
"5 1\n1\n2\n3\n4\n5\n",
"4 2\n2 5\n3 1\n5 3\n10 1\n"
] | [
"1 3 6 10 15 ",
"7 8 13 21 "
] | none | 1,000 | [
{
"input": "5 1\n1\n2\n3\n4\n5",
"output": "1 3 6 10 15 "
},
{
"input": "4 2\n2 5\n3 1\n5 3\n10 1",
"output": "7 8 13 21 "
},
{
"input": "1 1\n66",
"output": "66 "
},
{
"input": "2 2\n1 1\n1 1",
"output": "2 3 "
},
{
"input": "2 2\n10 1\n10 1",
"output": "11 21 "
},
{
"input": "1 5\n1 95 44 14 35",
"output": "189 "
},
{
"input": "7 1\n80\n92\n24\n88\n40\n45\n7",
"output": "80 172 196 284 324 369 376 "
},
{
"input": "1 2\n51 44",
"output": "95 "
},
{
"input": "2 1\n19\n4",
"output": "19 23 "
},
{
"input": "2 2\n1 10\n1 1",
"output": "11 12 "
},
{
"input": "3 3\n3 9 4\n5 10 8\n4 4 7",
"output": "16 30 37 "
},
{
"input": "10 3\n6 10 3\n2 7 9\n10 4 7\n6 3 4\n6 2 6\n8 4 4\n5 9 8\n6 9 7\n2 7 10\n2 6 2",
"output": "19 32 39 43 49 53 61 68 78 80 "
}
] | 1,643,111,903 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 732 | 9,625,600 | R=lambda:map(int,input().split())
m,n=R()
t=0
a=[]
s=0
for _ in range(m):
w=list(R())
s+=w[0]
t=max(t,s)
t+=sum(w[1:])
print(t,end=' ')
| Title: Art Union
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these *n* colors. Adding the *j*-th color to the *i*-th picture takes the *j*-th painter *t**ij* units of time.
Order is important everywhere, so the painters' work is ordered by the following rules:
- Each picture is first painted by the first painter, then by the second one, and so on. That is, after the *j*-th painter finishes working on the picture, it must go to the (*j*<=+<=1)-th painter (if *j*<=<<=*n*); - each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on; - each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest; - as soon as the *j*-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.
Given that the painters start working at time 0, find for each picture the time when it is ready for sale.
Input Specification:
The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), where *t**ij* is the time the *j*-th painter needs to work on the *i*-th picture.
Output Specification:
Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture.
Demo Input:
['5 1\n1\n2\n3\n4\n5\n', '4 2\n2 5\n3 1\n5 3\n10 1\n']
Demo Output:
['1 3 6 10 15 ', '7 8 13 21 ']
Note:
none | ```python
R=lambda:map(int,input().split())
m,n=R()
t=0
a=[]
s=0
for _ in range(m):
w=list(R())
s+=w[0]
t=max(t,s)
t+=sum(w[1:])
print(t,end=' ')
``` | 0 |
|
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times. | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4. | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 1 24",
"output": "5"
},
{
"input": "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45",
"output": "0"
},
{
"input": "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18",
"output": "15"
},
{
"input": "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 28 13 8 5 9 2 3 2 29 13 1 2 18 29 28 4 13 3 14 9 20 26 1 19 13 7 8 22 7 5 13 14 10 23",
"output": "29"
},
{
"input": "10\n135 188 160 167 179 192 195 192 193 191",
"output": "0"
},
{
"input": "15\n2 19 19 22 15 24 6 36 20 3 18 27 20 1 10",
"output": "6"
},
{
"input": "25\n8 1 2 1 2 5 3 4 2 6 3 3 4 1 6 1 6 1 4 5 2 9 1 2 1",
"output": "13"
},
{
"input": "40\n4784 4824 4707 4343 4376 4585 4917 4848 3748 4554 3390 4944 4845 3922 4617 4606 4815 4698 4595 4942 4327 4983 4833 4507 3721 4863 4633 4553 4991 4922 4733 4396 4747 4724 4886 4226 4025 4928 4990 4792",
"output": "0"
},
{
"input": "60\n1219 19 647 1321 21 242 677 901 10 165 434 978 448 163 919 517 1085 10 516 920 653 1363 62 98 629 928 998 1335 1448 85 357 432 1298 561 663 182 2095 801 59 208 765 1653 642 645 1378 221 911 749 347 849 43 1804 62 73 613 143 860 297 278 148",
"output": "37"
},
{
"input": "100\n4204 4719 4688 3104 4012 4927 4696 4614 4826 4792 3891 4672 4914 4740 4968 3879 4424 4755 3856 3837 4965 4939 4030 4941 4504 4668 4908 4608 3660 4822 4846 3945 4539 4819 4895 3746 4324 4233 4135 4956 4983 4546 4673 4617 3533 4851 4868 4838 4998 4769 4899 4578 3841 4974 4627 4990 4524 4939 4469 4233 4434 4339 4446 4979 4354 4912 4558 4609 4436 3883 4379 4927 4824 4819 4984 4660 4874 3732 4853 4268 4761 4402 4642 4577 4635 4564 4113 4896 4943 4122 4413 4597 3768 4731 4669 4958 4548 4263 4657 3651",
"output": "0"
},
{
"input": "100\n1354 1797 588 3046 1290 745 217 907 113 381 523 935 791 415 92 1597 1739 1774 240 27 1262 2498 52 1339 1031 1355 2036 230 489 7 69 877 530 2664 1230 940 2712 2651 3410 480 332 699 957 2257 1877 1940 452 1652 1216 3144 236 165 1109 888 1649 346 24 183 1061 1226 2694 3225 2021 1145 907 1671 1599 3395 942 1959 555 1281 675 1125 1386 732 1081 326 256 26 1009 1772 2687 1173 491 709 390 992 519 203 1029 1381 846 1515 705 2859 282 147 1824 299",
"output": "63"
},
{
"input": "100\n2794 2201 4935 564 2876 4472 4196 2571 2260 1479 1451 3497 245 2805 4834 3872 4294 1299 937 2983 1458 3278 1098 2990 4447 4337 4388 947 3708 3382 3694 4562 3827 2312 3760 1181 2830 1256 1054 1583 2094 931 86 2526 998 3420 2248 3461 3662 1715 5 4123 1051 545 3704 1084 1916 695 794 121 1000 1611 3674 1910 4795 2805 825 2392 3551 1148 3738 4650 791 288 1064 2011 2991 2116 2179 3333 1303 498 1610 3092 1935 3450 3524 2624 1596 2801 2290 2297 2327 1602 4779 3135 1231 4203 3283 3580",
"output": "51"
},
{
"input": "2\n1 5",
"output": "1"
}
] | 1,698,770,480 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 374 | 13,926,400 | import fileinput
from bisect import bisect
inputs = []
for line in fileinput.input("input.txt"):
inputs.append(line)
n = int(inputs[0])
measurements = sorted(list(map(int, inputs[1].split())))
print(measurements)
count = 0
i = 0
j = n - 1
while i < j and measurements[j] > 2 * measurements[i]:
left = measurements[i]
right = measurements[j]
left_diff = bisect(measurements, 2 * left) - i
right_diff = j - bisect(measurements, right / 2)
if left_diff <= right_diff: i += 1
else: j -= 1
count += 1
with open("output.txt", "w") as f:
f.write(str(count) + "\n")
| Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
Output Specification:
Print a single integer — the minimum number of results Vasya will have to remove.
Demo Input:
['6\n4 5 3 8 3 7\n', '4\n4 3 2 4\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4. | ```python
import fileinput
from bisect import bisect
inputs = []
for line in fileinput.input("input.txt"):
inputs.append(line)
n = int(inputs[0])
measurements = sorted(list(map(int, inputs[1].split())))
print(measurements)
count = 0
i = 0
j = n - 1
while i < j and measurements[j] > 2 * measurements[i]:
left = measurements[i]
right = measurements[j]
left_diff = bisect(measurements, 2 * left) - i
right_diff = j - bisect(measurements, right / 2)
if left_diff <= right_diff: i += 1
else: j -= 1
count += 1
with open("output.txt", "w") as f:
f.write(str(count) + "\n")
``` | 0 |
|
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"output": "20"
},
{
"input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20",
"output": "10"
},
{
"input": "7 5 1\n0 100 2 2 0 2 1",
"output": "20"
},
{
"input": "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 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": "10"
},
{
"input": "100 50 1\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 0 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": "490"
},
{
"input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0",
"output": "10"
},
{
"input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "980"
},
{
"input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "10"
},
{
"input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98",
"output": "890"
},
{
"input": "7 4 5\n1 0 6 0 5 6 0",
"output": "10"
},
{
"input": "7 4 5\n1 6 5 0 0 6 0",
"output": "10"
},
{
"input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0",
"output": "90"
},
{
"input": "2 1 100\n0 1",
"output": "10"
},
{
"input": "2 2 100\n1 0",
"output": "10"
},
{
"input": "10 1 88\n0 95 0 0 0 0 0 94 0 85",
"output": "90"
},
{
"input": "10 2 14\n2 0 1 26 77 39 41 100 13 32",
"output": "10"
},
{
"input": "10 3 11\n0 0 0 0 0 62 0 52 1 35",
"output": "60"
},
{
"input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88",
"output": "10"
},
{
"input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82",
"output": "70"
},
{
"input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1",
"output": "180"
},
{
"input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0",
"output": "210"
},
{
"input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37",
"output": "80"
},
{
"input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77",
"output": "190"
},
{
"input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84",
"output": "190"
},
{
"input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15",
"output": "580"
},
{
"input": "97 44 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 51 19",
"output": "520"
},
{
"input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67",
"output": "490"
},
{
"input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23",
"output": "890"
},
{
"input": "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14",
"output": "970"
},
{
"input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10",
"output": "990"
},
{
"input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10",
"output": "490"
},
{
"input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2",
"output": "500"
},
{
"input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20",
"output": "50"
},
{
"input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0",
"output": "990"
},
{
"input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0",
"output": "10"
},
{
"input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51",
"output": "140"
},
{
"input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4",
"output": "390"
},
{
"input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68",
"output": "130"
},
{
"input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59",
"output": "10"
},
{
"input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32",
"output": "10"
},
{
"input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98",
"output": "160"
},
{
"input": "5 2 20\n27 0 32 21 19",
"output": "30"
},
{
"input": "6 4 10\n10 0 0 0 0 10",
"output": "20"
},
{
"input": "8 7 100\n1 0 0 0 0 0 0 1",
"output": "10"
},
{
"input": "5 3 20\n1 21 0 0 1",
"output": "20"
},
{
"input": "4 3 1\n0 0 0 1",
"output": "10"
},
{
"input": "5 2 3\n4 0 5 6 1",
"output": "30"
},
{
"input": "5 3 87\n88 89 0 1 90",
"output": "10"
},
{
"input": "5 3 20\n15 30 0 15 35",
"output": "10"
},
{
"input": "6 3 50\n0 0 0 1 2 0",
"output": "10"
},
{
"input": "6 4 9\n100 9 10 0 0 9",
"output": "20"
},
{
"input": "5 4 20\n0 20 0 0 20",
"output": "10"
},
{
"input": "6 3 3\n1 5 0 2 2 0",
"output": "10"
},
{
"input": "5 4 100\n0 1 0 0 1",
"output": "10"
}
] | 1,613,491,667 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 78 | 0 | n,m,k=map(int,input().split())
arr=list(map(int,input().split()))
count=[]
for i in range(n):
if(arr[i]!=0 and arr[i]<=k):
count.append(abs(i-(m-1)))
print((min(count))*10) | Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
Input Specification:
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars.
Output Specification:
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
Demo Input:
['5 1 20\n0 27 32 21 19\n', '7 3 50\n62 0 0 0 99 33 22\n', '10 5 100\n1 0 1 0 0 0 0 0 1 1\n']
Demo Output:
['40', '30', '20']
Note:
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | ```python
n,m,k=map(int,input().split())
arr=list(map(int,input().split()))
count=[]
for i in range(n):
if(arr[i]!=0 and arr[i]<=k):
count.append(abs(i-(m-1)))
print((min(count))*10)
``` | 3 |
|
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of integers from 1 to *n* inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with *n* meteorids, colours of which being integer sequences *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* respectively. Meteoroids' colours were also between 1 and *n* inclusive, and the two sequences were not identical, that is, at least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds.
Well, she almost had it all — each of the sequences *a* and *b* matched exactly *n*<=-<=1 elements in Sengoku's permutation. In other words, there is exactly one *i* (1<=≤<=*i*<=≤<=*n*) such that *a**i*<=≠<=*p**i*, and exactly one *j* (1<=≤<=*j*<=≤<=*n*) such that *b**j*<=≠<=*p**j*.
For now, Sengoku is able to recover the actual colour sequences *a* and *b* through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night. | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the first meteor outburst.
The third line contains *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of colours in the second meteor outburst. At least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds. | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10\n1 2 3 4 5 6 7 8 7 10\n1 2 3 4 5 6 7 8 9 9",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10\n1 2 3 4 5 6 7 8 4 10\n1 2 3 4 5 6 7 6 9 10",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10\n8 6 1 7 9 3 5 2 10 9\n8 6 1 7 4 3 5 2 10 4",
"output": "8 6 1 7 4 3 5 2 10 9"
},
{
"input": "10\n2 9 7 7 8 5 4 10 6 1\n2 8 7 3 8 5 4 10 6 1",
"output": "2 9 7 3 8 5 4 10 6 1"
},
{
"input": "2\n2 2\n1 1",
"output": "1 2"
},
{
"input": "3\n1 2 2\n1 3 3",
"output": "1 3 2"
},
{
"input": "3\n2 2 3\n1 2 1",
"output": "1 2 3"
},
{
"input": "3\n1 3 3\n1 1 3",
"output": "1 2 3"
},
{
"input": "3\n2 1 1\n2 3 3",
"output": "2 3 1"
},
{
"input": "3\n3 3 2\n1 1 2",
"output": "1 3 2"
},
{
"input": "3\n1 3 3\n3 3 2",
"output": "1 3 2"
},
{
"input": "4\n3 2 3 4\n1 2 1 4",
"output": "1 2 3 4"
},
{
"input": "4\n2 2 3 4\n1 2 3 2",
"output": "1 2 3 4"
},
{
"input": "4\n1 2 4 4\n2 2 3 4",
"output": "1 2 3 4"
},
{
"input": "4\n4 1 3 4\n2 1 3 2",
"output": "2 1 3 4"
},
{
"input": "4\n3 2 1 3\n4 2 1 2",
"output": "4 2 1 3"
},
{
"input": "4\n1 4 1 3\n2 4 1 4",
"output": "2 4 1 3"
},
{
"input": "4\n1 3 4 4\n3 3 2 4",
"output": "1 3 2 4"
},
{
"input": "5\n5 4 5 3 1\n4 4 2 3 1",
"output": "5 4 2 3 1"
},
{
"input": "5\n4 1 2 4 5\n3 1 2 5 5",
"output": "3 1 2 4 5"
},
{
"input": "3\n2 2 3\n1 3 3",
"output": "1 2 3"
},
{
"input": "3\n1 1 3\n2 3 3",
"output": "2 1 3"
},
{
"input": "5\n5 4 5 3 1\n2 4 4 3 1",
"output": "2 4 5 3 1"
},
{
"input": "3\n3 3 1\n2 1 1",
"output": "2 3 1"
},
{
"input": "5\n5 4 3 5 2\n5 4 1 1 2",
"output": "5 4 3 1 2"
},
{
"input": "6\n1 2 3 4 2 5\n1 6 3 4 4 5",
"output": "1 6 3 4 2 5"
},
{
"input": "4\n1 3 2 1\n2 3 2 1",
"output": "4 3 2 1"
},
{
"input": "4\n1 3 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 10 10\n1 2 3 4 5 6 7 8 9 10 3",
"output": "1 2 3 4 5 6 7 8 9 10 11"
},
{
"input": "5\n1 2 3 2 5\n1 4 3 3 5",
"output": "1 4 3 2 5"
},
{
"input": "5\n1 2 3 4 3\n1 2 5 4 2",
"output": "1 2 5 4 3"
},
{
"input": "5\n1 2 3 4 4\n1 2 3 4 3",
"output": "1 2 3 4 5"
},
{
"input": "4\n1 3 1 4\n1 3 4 4",
"output": "1 3 2 4"
},
{
"input": "5\n2 5 3 2 1\n4 5 3 3 1",
"output": "4 5 3 2 1"
},
{
"input": "5\n1 2 3 2 5\n1 3 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "5\n5 2 3 4 5\n2 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "5\n5 4 1 1 2\n5 4 3 5 2",
"output": "5 4 3 1 2"
},
{
"input": "4\n1 4 3 4\n1 3 3 4",
"output": "1 2 3 4"
},
{
"input": "4\n1 2 3 1\n1 2 3 2",
"output": "1 2 3 4"
},
{
"input": "5\n4 5 3 3 1\n2 5 3 2 1",
"output": "4 5 3 2 1"
},
{
"input": "5\n1 2 3 5 5\n1 2 3 4 3",
"output": "1 2 3 4 5"
},
{
"input": "4\n2 3 3 4\n2 4 3 4",
"output": "2 1 3 4"
}
] | 1,497,927,631 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 92 | 512,000 | #!/usr/bin/env python
from collections import defaultdict
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = defaultdict(list)
not_equal_indices = set()
not_equal_nums = set(range(1, a[0] + 1))
for i, (bb, cc) in enumerate(zip(b, c)):
if bb != cc:
not_equal_indices.add(i)
else:
not_equal_nums.remove(bb)
if len(not_equal_indices) == 1:
b[not_equal_indices.pop()] = not_equal_nums.pop()
else:
for i in list(not_equal_indices):
if b[i] in not_equal_nums:
not_equal_nums.remove(b[i])
not_equal_indices.remove(i)
for i in not_equal_indices:
b[i] = not_equal_nums.pop()
print(' '.join(map(str, b)))
| Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of integers from 1 to *n* inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with *n* meteorids, colours of which being integer sequences *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* respectively. Meteoroids' colours were also between 1 and *n* inclusive, and the two sequences were not identical, that is, at least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds.
Well, she almost had it all — each of the sequences *a* and *b* matched exactly *n*<=-<=1 elements in Sengoku's permutation. In other words, there is exactly one *i* (1<=≤<=*i*<=≤<=*n*) such that *a**i*<=≠<=*p**i*, and exactly one *j* (1<=≤<=*j*<=≤<=*n*) such that *b**j*<=≠<=*p**j*.
For now, Sengoku is able to recover the actual colour sequences *a* and *b* through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.
Input Specification:
The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the first meteor outburst.
The third line contains *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of colours in the second meteor outburst. At least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds.
Output Specification:
Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists.
Demo Input:
['5\n1 2 3 4 3\n1 2 5 4 5\n', '5\n4 4 2 3 1\n5 4 5 3 1\n', '4\n1 1 3 4\n1 4 3 4\n']
Demo Output:
['1 2 5 4 3\n', '5 4 2 3 1\n', '1 2 3 4\n']
Note:
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | ```python
#!/usr/bin/env python
from collections import defaultdict
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = defaultdict(list)
not_equal_indices = set()
not_equal_nums = set(range(1, a[0] + 1))
for i, (bb, cc) in enumerate(zip(b, c)):
if bb != cc:
not_equal_indices.add(i)
else:
not_equal_nums.remove(bb)
if len(not_equal_indices) == 1:
b[not_equal_indices.pop()] = not_equal_nums.pop()
else:
for i in list(not_equal_indices):
if b[i] in not_equal_nums:
not_equal_nums.remove(b[i])
not_equal_indices.remove(i)
for i in not_equal_indices:
b[i] = not_equal_nums.pop()
print(' '.join(map(str, b)))
``` | 0 |
|
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,684,782,147 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 4 | 124 | 0 | f = open("input.txt", "r")
door = str(f.readline())[0:-1]
rail = int(str(f.readline()))
f.close()
if door == "front":
out = "L" if rail == 1 else "R"
else:
out = "R" if rail == 1 else "L"
f = open("output.txt", "w")
f.write(out) | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
Input Specification:
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Output Specification:
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
Demo Input:
['front\n1\n']
Demo Output:
['L\n']
Note:
none | ```python
f = open("input.txt", "r")
door = str(f.readline())[0:-1]
rail = int(str(f.readline()))
f.close()
if door == "front":
out = "L" if rail == 1 else "R"
else:
out = "R" if rail == 1 else "L"
f = open("output.txt", "w")
f.write(out)
``` | 3 |
|
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n510000",
"output": "490000"
},
{
"input": "3\n2 5 27",
"output": "26"
},
{
"input": "2\n600000 800000",
"output": "400000"
},
{
"input": "5\n2 5 6 27 29",
"output": "28"
},
{
"input": "1\n500001",
"output": "499999"
},
{
"input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055",
"output": "98054"
},
{
"input": "1\n900000",
"output": "100000"
},
{
"input": "1\n500000",
"output": "499999"
},
{
"input": "1\n999998",
"output": "2"
},
{
"input": "3\n999997 999998 999999",
"output": "3"
},
{
"input": "2\n999997 999999",
"output": "3"
},
{
"input": "2\n2 999998",
"output": "2"
},
{
"input": "2\n500000 500001",
"output": "499999"
},
{
"input": "1\n500002",
"output": "499998"
},
{
"input": "1\n700000",
"output": "300000"
},
{
"input": "2\n2 999999",
"output": "1"
},
{
"input": "2\n999998 999999",
"output": "2"
},
{
"input": "1\n999995",
"output": "5"
},
{
"input": "2\n499999 500001",
"output": "499999"
},
{
"input": "1\n499999",
"output": "499998"
},
{
"input": "2\n100 999900",
"output": "100"
},
{
"input": "2\n499999 500000",
"output": "499999"
},
{
"input": "2\n500001 999999",
"output": "499999"
},
{
"input": "3\n500000 500001 500002",
"output": "499999"
},
{
"input": "2\n2 500001",
"output": "499999"
},
{
"input": "2\n499999 999999",
"output": "499998"
},
{
"input": "2\n2 500000",
"output": "499999"
},
{
"input": "4\n2 3 4 999999",
"output": "3"
},
{
"input": "2\n100000 500001",
"output": "499999"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n800000",
"output": "200000"
},
{
"input": "1\n505050",
"output": "494950"
},
{
"input": "1\n753572",
"output": "246428"
},
{
"input": "2\n576696 760487",
"output": "423304"
},
{
"input": "10\n3 4 5 6 7 8 9 10 11 12",
"output": "11"
},
{
"input": "4\n2 3 4 5",
"output": "4"
},
{
"input": "4\n999996 999997 999998 999999",
"output": "4"
}
] | 1,615,657,235 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 7,680,000 | import sys,math
n = int(input())
a = list(map(int,input().split()))
start = 1
last = 10**6
prize = 0
for i in a:
if (i-start)<(last-i):
prize+=i-start
start = max(start,i)
else:
prize+=(last-i-1)
start = min(last,i)
print(prize)
| Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Output Specification:
Print one integer — the minimum number of seconds it will take to collect all prizes.
Demo Input:
['3\n2 3 9\n', '2\n2 999995\n']
Demo Output:
['8\n', '5\n']
Note:
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | ```python
import sys,math
n = int(input())
a = list(map(int,input().split()))
start = 1
last = 10**6
prize = 0
for i in a:
if (i-start)<(last-i):
prize+=i-start
start = max(start,i)
else:
prize+=(last-i-1)
start = min(last,i)
print(prize)
``` | 0 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,698,310,790 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n, k = map(int, input().split())
if(n%2==0):
half = n/2
if(k>half):
dif = int(abs(k - half))
print(2*dif)
else:
print(2*k-1)
else:
half = (n-1)/2 +1
if(k>half):
dif = int(abs(k- half))
print(2*dif)
else:
print(2*k-1)
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
n, k = map(int, input().split())
if(n%2==0):
half = n/2
if(k>half):
dif = int(abs(k - half))
print(2*dif)
else:
print(2*k-1)
else:
half = (n-1)/2 +1
if(k>half):
dif = int(abs(k- half))
print(2*dif)
else:
print(2*k-1)
``` | 3 |
|
660 | B | Seating On Bus | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to *m* (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , *n*-th row left window seat, *n*-th row right window seat.
After occupying all the window seats (for *m*<=><=2*n*) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , *n*-th row left non-window seat, *n*-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , *n*-th row left non-window seat, *n*-th row left window seat, *n*-th row right non-window seat, *n*-th row right window seat.
You are given the values *n* and *m*. Output *m* numbers from 1 to *m*, the order in which the passengers will get off the bus. | The only line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=4*n*) — the number of pairs of rows and the number of passengers. | Print *m* distinct integers from 1 to *m* — the order in which the passengers will get off the bus. | [
"2 7\n",
"9 36\n"
] | [
"5 1 6 2 7 3 4\n",
"19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18\n"
] | none | 0 | [
{
"input": "2 7",
"output": "5 1 6 2 7 3 4"
},
{
"input": "9 36",
"output": "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 4",
"output": "3 1 4 2"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "10 10",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10 40",
"output": "21 1 22 2 23 3 24 4 25 5 26 6 27 7 28 8 29 9 30 10 31 11 32 12 33 13 34 14 35 15 36 16 37 17 38 18 39 19 40 20"
},
{
"input": "10 39",
"output": "21 1 22 2 23 3 24 4 25 5 26 6 27 7 28 8 29 9 30 10 31 11 32 12 33 13 34 14 35 15 36 16 37 17 38 18 39 19 20"
},
{
"input": "77 1",
"output": "1"
},
{
"input": "77 13",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13"
},
{
"input": "77 53",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53"
},
{
"input": "77 280",
"output": "155 1 156 2 157 3 158 4 159 5 160 6 161 7 162 8 163 9 164 10 165 11 166 12 167 13 168 14 169 15 170 16 171 17 172 18 173 19 174 20 175 21 176 22 177 23 178 24 179 25 180 26 181 27 182 28 183 29 184 30 185 31 186 32 187 33 188 34 189 35 190 36 191 37 192 38 193 39 194 40 195 41 196 42 197 43 198 44 199 45 200 46 201 47 202 48 203 49 204 50 205 51 206 52 207 53 208 54 209 55 210 56 211 57 212 58 213 59 214 60 215 61 216 62 217 63 218 64 219 65 220 66 221 67 222 68 223 69 224 70 225 71 226 72 227 73 228 74 22..."
},
{
"input": "100 1",
"output": "1"
},
{
"input": "100 13",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13"
},
{
"input": "100 77",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77"
},
{
"input": "100 103",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103"
},
{
"input": "100 200",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "100 199",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "100 201",
"output": "201 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "100 300",
"output": "201 1 202 2 203 3 204 4 205 5 206 6 207 7 208 8 209 9 210 10 211 11 212 12 213 13 214 14 215 15 216 16 217 17 218 18 219 19 220 20 221 21 222 22 223 23 224 24 225 25 226 26 227 27 228 28 229 29 230 30 231 31 232 32 233 33 234 34 235 35 236 36 237 37 238 38 239 39 240 40 241 41 242 42 243 43 244 44 245 45 246 46 247 47 248 48 249 49 250 50 251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 27..."
},
{
"input": "100 399",
"output": "201 1 202 2 203 3 204 4 205 5 206 6 207 7 208 8 209 9 210 10 211 11 212 12 213 13 214 14 215 15 216 16 217 17 218 18 219 19 220 20 221 21 222 22 223 23 224 24 225 25 226 26 227 27 228 28 229 29 230 30 231 31 232 32 233 33 234 34 235 35 236 36 237 37 238 38 239 39 240 40 241 41 242 42 243 43 244 44 245 45 246 46 247 47 248 48 249 49 250 50 251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 27..."
},
{
"input": "100 400",
"output": "201 1 202 2 203 3 204 4 205 5 206 6 207 7 208 8 209 9 210 10 211 11 212 12 213 13 214 14 215 15 216 16 217 17 218 18 219 19 220 20 221 21 222 22 223 23 224 24 225 25 226 26 227 27 228 28 229 29 230 30 231 31 232 32 233 33 234 34 235 35 236 36 237 37 238 38 239 39 240 40 241 41 242 42 243 43 244 44 245 45 246 46 247 47 248 48 249 49 250 50 251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 27..."
},
{
"input": "3 9",
"output": "7 1 8 2 9 3 4 5 6"
}
] | 1,572,345,050 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | import math
n,m=map(int,input().split())
i = 1
mas = []
while i<m-1:
if math.ceil(m/2)+i<=m and len(mas)<m:
mas.append(math.ceil(m/2)+i)
if i<=m and len(mas)<m:
mas.append(i)
if math.ceil(m/2)+i+1<=m and len(mas)<m:
mas.append(math.ceil(m/2)+i+1)
if i+1<=m and len(mas)<m:
mas.append(i+1)
i+=2
mas = [str(s) for s in mas]
print(' '.join(mas)) | Title: Seating On Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to *m* (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , *n*-th row left window seat, *n*-th row right window seat.
After occupying all the window seats (for *m*<=><=2*n*) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , *n*-th row left non-window seat, *n*-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , *n*-th row left non-window seat, *n*-th row left window seat, *n*-th row right non-window seat, *n*-th row right window seat.
You are given the values *n* and *m*. Output *m* numbers from 1 to *m*, the order in which the passengers will get off the bus.
Input Specification:
The only line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=4*n*) — the number of pairs of rows and the number of passengers.
Output Specification:
Print *m* distinct integers from 1 to *m* — the order in which the passengers will get off the bus.
Demo Input:
['2 7\n', '9 36\n']
Demo Output:
['5 1 6 2 7 3 4\n', '19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18\n']
Note:
none | ```python
import math
n,m=map(int,input().split())
i = 1
mas = []
while i<m-1:
if math.ceil(m/2)+i<=m and len(mas)<m:
mas.append(math.ceil(m/2)+i)
if i<=m and len(mas)<m:
mas.append(i)
if math.ceil(m/2)+i+1<=m and len(mas)<m:
mas.append(math.ceil(m/2)+i+1)
if i+1<=m and len(mas)<m:
mas.append(i+1)
i+=2
mas = [str(s) for s in mas]
print(' '.join(mas))
``` | 0 |
|
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "4\n82 46 8 44",
"output": "3 1\n4 2"
},
{
"input": "2\n35 50",
"output": "1 2"
},
{
"input": "8\n24 39 49 38 44 64 44 50",
"output": "1 6\n4 8\n2 3\n5 7"
},
{
"input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14",
"output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15"
},
{
"input": "12\n22 83 2 67 55 12 40 93 83 73 12 28",
"output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5"
},
{
"input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43",
"output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7"
},
{
"input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58",
"output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16"
},
{
"input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62",
"output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12"
},
{
"input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76",
"output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3"
},
{
"input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8",
"output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5"
},
{
"input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41",
"output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36"
},
{
"input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55",
"output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12"
},
{
"input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25",
"output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27"
},
{
"input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30",
"output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10"
},
{
"input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39",
"output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32"
},
{
"input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26",
"output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54"
},
{
"input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30",
"output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10"
},
{
"input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18",
"output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34"
},
{
"input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65",
"output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53"
},
{
"input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50",
"output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14"
},
{
"input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57",
"output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7"
},
{
"input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49",
"output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24"
},
{
"input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69",
"output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9"
},
{
"input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57",
"output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20"
},
{
"input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34",
"output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11"
},
{
"input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43",
"output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3"
},
{
"input": "4\n100 100 1 1",
"output": "3 2\n4 1"
},
{
"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": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"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": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "4\n3 4 4 5",
"output": "1 4\n2 3"
},
{
"input": "4\n1 1 2 2",
"output": "1 4\n2 3"
},
{
"input": "4\n1 2 3 4",
"output": "1 4\n2 3"
}
] | 1,633,425,470 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 93 | 20,172,800 | n = int(input())
info = list(map(int, input().split()))
info = [[info[i], i] for i in range(n)]
info.sort()
start = 0
end = n - 1
while start < end:
print(info[start][1] + 1, info[end][1] + 1)
start += 1
end -= 1 | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Output Specification:
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
Demo Input:
['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n']
Demo Output:
['1 3\n6 2\n4 5\n', '1 2\n3 4\n']
Note:
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | ```python
n = int(input())
info = list(map(int, input().split()))
info = [[info[i], i] for i in range(n)]
info.sort()
start = 0
end = n - 1
while start < end:
print(info[start][1] + 1, info[end][1] + 1)
start += 1
end -= 1
``` | 3 |
|
402 | B | Trees in a Row | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a**i*<==<=*k*, where *k* is the number the Queen chose.
Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes? | The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row. | In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions.
If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, print on the corresponding line "- j x".
If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them. | [
"4 1\n1 2 1 5\n",
"4 1\n1 2 3 4\n"
] | [
"2\n+ 3 2\n- 4 1\n",
"0\n"
] | none | 1,000 | [
{
"input": "4 1\n1 2 1 5",
"output": "2\n+ 3 2\n- 4 1"
},
{
"input": "4 1\n1 2 3 4",
"output": "0"
},
{
"input": "50 1\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",
"output": "0"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "0"
},
{
"input": "50 5\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 131 136 141 146 151 156 161 166 755 176 181 186 191 196 201 206 211 216 221 226 231 236 241 246",
"output": "5\n- 1 231\n- 11 614\n- 17 521\n- 20 616\n- 35 584"
},
{
"input": "10 99\n1 100 199 298 397 496 364 694 793 676",
"output": "2\n+ 7 231\n+ 10 216"
},
{
"input": "1 99\n1",
"output": "0"
},
{
"input": "2 99\n1 100",
"output": "0"
},
{
"input": "3 99\n1 100 199",
"output": "0"
},
{
"input": "4 99\n1 100 199 298",
"output": "0"
},
{
"input": "3 99\n295 566 992",
"output": "2\n- 2 172\n- 3 499"
},
{
"input": "2 99\n307 854",
"output": "1\n- 2 448"
},
{
"input": "7 1\n1 1 2 3 4 5 6",
"output": "6\n+ 2 1\n+ 3 1\n+ 4 1\n+ 5 1\n+ 6 1\n+ 7 1"
},
{
"input": "5 1\n1 1 2 3 4",
"output": "4\n+ 2 1\n+ 3 1\n+ 4 1\n+ 5 1"
},
{
"input": "4 2\n1 1 3 5",
"output": "3\n+ 2 2\n+ 3 2\n+ 4 2"
},
{
"input": "4 1\n1 1 2 3",
"output": "3\n+ 2 1\n+ 3 1\n+ 4 1"
},
{
"input": "5 1\n1 1 1 2 3",
"output": "4\n+ 2 1\n+ 3 2\n+ 4 2\n+ 5 2"
},
{
"input": "3 1\n1 1 2",
"output": "2\n+ 2 1\n+ 3 1"
}
] | 1,465,400,787 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 358 | 5,120,000 | def dist(A, B):
res = 0
for i in range(len(A)):
if(A[i] != B[i]):
res += 1
return res
def generate_new(number):
global n, k
R = [0] * n
for i in range(n):
R[i] = number
number += k
return R
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
N = 1009
res = [0] * n
res_dist = N
for i in range(N):
B = generate_new(i)
cur_dist = dist(A, B)
if(cur_dist < res_dist):
res = B
res_dist = cur_dist
print(res_dist)
for i in range(len(A)):
if(A[i] < res[i]):
print('+', i + 1, res[i] - A[i])
elif(A[i] > res[i]):
print('-', i + 1, A[i] - res[i]) | Title: Trees in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a**i*<==<=*k*, where *k* is the number the Queen chose.
Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?
Input Specification:
The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row.
Output Specification:
In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions.
If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, print on the corresponding line "- j x".
If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.
Demo Input:
['4 1\n1 2 1 5\n', '4 1\n1 2 3 4\n']
Demo Output:
['2\n+ 3 2\n- 4 1\n', '0\n']
Note:
none | ```python
def dist(A, B):
res = 0
for i in range(len(A)):
if(A[i] != B[i]):
res += 1
return res
def generate_new(number):
global n, k
R = [0] * n
for i in range(n):
R[i] = number
number += k
return R
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
N = 1009
res = [0] * n
res_dist = N
for i in range(N):
B = generate_new(i)
cur_dist = dist(A, B)
if(cur_dist < res_dist):
res = B
res_dist = cur_dist
print(res_dist)
for i in range(len(A)):
if(A[i] < res[i]):
print('+', i + 1, res[i] - A[i])
elif(A[i] > res[i]):
print('-', i + 1, A[i] - res[i])
``` | 0 |
|
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array. | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82",
"output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0"
},
{
"input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46",
"output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0"
},
{
"input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38",
"output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0"
},
{
"input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37",
"output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37"
},
{
"input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61",
"output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61"
},
{
"input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66",
"output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0"
},
{
"input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82",
"output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0"
},
{
"input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22",
"output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20"
},
{
"input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41",
"output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0"
},
{
"input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935",
"output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0"
},
{
"input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952",
"output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961"
},
{
"input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0",
"output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673"
},
{
"input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0",
"output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182"
},
{
"input": "5\n-1 -2 -3 -4 0",
"output": "1 -1\n2 -4 -3\n2 0 -2"
},
{
"input": "3\n-101 101 0",
"output": "1 -101\n1 101\n1 0"
},
{
"input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000",
"output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000"
},
{
"input": "4\n0 -1 -2 -3",
"output": "1 -1\n2 -3 -2\n1 0"
}
] | 1,633,212,102 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 154 | 6,963,200 | n = int(input())
a = list(map(int, input().split()))
ans1 = []
ans2 = []
ans3 = []
for i in a:
if(i==0):
ans3.append(i)
elif(i>0):
ans2.append(i)
else:
ans1.append(i)
if(len(ans1)%2==0):
x = ans1.pop()
ans3.append(x)
if(len(ans2)==0):
p = ans1.pop()
q = ans1.pop()
ans2.append(p)
ans2.append(q)
print(len(ans1),*ans1)
print(len(ans2),*ans2)
print(len(ans3),*ans3) | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array.
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
Output Specification:
In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
Demo Input:
['3\n-1 2 0\n', '4\n-1 -2 -3 0\n']
Demo Output:
['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
ans1 = []
ans2 = []
ans3 = []
for i in a:
if(i==0):
ans3.append(i)
elif(i>0):
ans2.append(i)
else:
ans1.append(i)
if(len(ans1)%2==0):
x = ans1.pop()
ans3.append(x)
if(len(ans2)==0):
p = ans1.pop()
q = ans1.pop()
ans2.append(p)
ans2.append(q)
print(len(ans1),*ans1)
print(len(ans2),*ans2)
print(len(ans3),*ans3)
``` | 3 |
|
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,693,452,453 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | a=input().split("WUB")
x=""
# for i in range(0,len(a)-2,3):
# if i!="WUB":
# x+=a[i:i+3]
for i in a:
if i!="":
x+=i+" "
print(x)
| 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
a=input().split("WUB")
x=""
# for i in range(0,len(a)-2,3):
# if i!="WUB":
# x+=a[i:i+3]
for i in a:
if i!="":
x+=i+" "
print(x)
``` | 3 |
|
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped. | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 8",
"output": "13"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "24 15",
"output": "36"
},
{
"input": "19 30",
"output": "47"
},
{
"input": "15 31",
"output": "44"
},
{
"input": "14 15",
"output": "27"
},
{
"input": "58 33",
"output": "89"
},
{
"input": "15 25",
"output": "38"
},
{
"input": "59 45",
"output": "102"
},
{
"input": "3 73",
"output": "74"
},
{
"input": "48 1",
"output": "47"
},
{
"input": "100 25",
"output": "122"
},
{
"input": "40 49",
"output": "86"
},
{
"input": "85 73",
"output": "155"
},
{
"input": "29 1",
"output": "28"
},
{
"input": "74 25",
"output": "97"
},
{
"input": "24 57",
"output": "78"
},
{
"input": "23 12",
"output": "33"
},
{
"input": "2 99",
"output": "99"
},
{
"input": "98 2",
"output": "97"
},
{
"input": "2 97",
"output": "97"
},
{
"input": "30 54",
"output": "81"
},
{
"input": "32 53",
"output": "82"
},
{
"input": "32 54",
"output": "84"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 2",
"output": "3"
}
] | 1,622,736,571 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 0 | a,b=map(int,input().split())
ans=0
while(a>0 and b >0):
if(a>b):
a,b=b,a
a=a+1
b=b-2
ans=ans+1
if(a<0 or b<0):
ans=ans-1
break
print(ans)
| Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
Input Specification:
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output Specification:
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
Demo Input:
['3 5\n', '4 4\n']
Demo Output:
['6\n', '5\n']
Note:
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped. | ```python
a,b=map(int,input().split())
ans=0
while(a>0 and b >0):
if(a>b):
a,b=b,a
a=a+1
b=b-2
ans=ans+1
if(a<0 or b<0):
ans=ans-1
break
print(ans)
``` | 3 |
|
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.
Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.
You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD. | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is. | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0 1 0 1",
"output": "5"
},
{
"input": "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0",
"output": "10"
},
{
"input": "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 0 0",
"output": "27"
},
{
"input": "8 1\n1 0 1 1 0 0 1 0",
"output": "4"
},
{
"input": "11 11\n0 1 0 0 1 1 1 0 0 0 0",
"output": "4"
},
{
"input": "19 10\n0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1",
"output": "4"
},
{
"input": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "3"
},
{
"input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "25"
},
{
"input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "24"
},
{
"input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "24"
},
{
"input": "98 70\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 0 0 0 0 0 0 0 0 0 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": "41"
},
{
"input": "99 70\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 1 1 1 1 1 1 1 1 1 1 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": "9"
},
{
"input": "99 60\n0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1",
"output": "34"
},
{
"input": "98 24\n0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 1",
"output": "39"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100 1\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": "2 1\n0 1",
"output": "1"
}
] | 1,672,510,039 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 46 | 0 | n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=sum(x)
p=min(a-1,n-a)
for i in range(1,p+1):
if x[a-1-i]+x[a-1+i]==1:
ans=ans-1
print(ans) | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.
Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.
You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
Input Specification:
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Output Specification:
Print the number of criminals Limak will catch.
Demo Input:
['6 3\n1 1 1 0 1 0\n', '5 2\n0 0 0 1 0\n']
Demo Output:
['3\n', '1\n']
Note:
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is. | ```python
n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=sum(x)
p=min(a-1,n-a)
for i in range(1,p+1):
if x[a-1-i]+x[a-1+i]==1:
ans=ans-1
print(ans)
``` | 3 |
|
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,625,228,685 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 77 | 0 | import array as arr
n = int(input())
#print(type(n))
string = input()
lst = []
#for i in word:
# lst.append(i)
lst = list(string)
flag = 0
arr = [0] * (100)
k = 0
i = 0
while (i < n):
if (lst[i] == 'B'):
flag += 1
while (i < n and lst[i] == 'B'):
arr[k] += 1
i += 1
k += 1
else:
i += 1
print(flag)
i = 0
while (i < flag):
print(arr[i], end = " ")
i += 1
print()
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement. | ```python
import array as arr
n = int(input())
#print(type(n))
string = input()
lst = []
#for i in word:
# lst.append(i)
lst = list(string)
flag = 0
arr = [0] * (100)
k = 0
i = 0
while (i < n):
if (lst[i] == 'B'):
flag += 1
while (i < n and lst[i] == 'B'):
arr[k] += 1
i += 1
k += 1
else:
i += 1
print(flag)
i = 0
while (i < flag):
print(arr[i], end = " ")
i += 1
print()
``` | 3 |
|
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 1,689,357,568 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | x = int(input())
ans=0
while x>0:
ans=ans + x%2
x = x//2
print(ans) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
x = int(input())
ans=0
while x>0:
ans=ans + x%2
x = x//2
print(ans)
``` | 3 |
|
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n500\n500",
"output": "0.5"
},
{
"input": "1000\n1\n1",
"output": "500"
},
{
"input": "1000\n1\n500",
"output": "1.996007984"
},
{
"input": "1000\n500\n1",
"output": "998.003992"
},
{
"input": "1000\n500\n500",
"output": "500"
},
{
"input": "101\n11\n22",
"output": "33.66666667"
},
{
"input": "987\n1\n3",
"output": "246.75"
},
{
"input": "258\n25\n431",
"output": "14.14473684"
},
{
"input": "979\n39\n60",
"output": "385.6666667"
},
{
"input": "538\n479\n416",
"output": "287.9351955"
},
{
"input": "583\n112\n248",
"output": "181.3777778"
},
{
"input": "978\n467\n371",
"output": "545.0190931"
},
{
"input": "980\n322\n193",
"output": "612.7378641"
},
{
"input": "871\n401\n17",
"output": "835.576555"
},
{
"input": "349\n478\n378",
"output": "194.885514"
},
{
"input": "425\n458\n118",
"output": "337.9340278"
},
{
"input": "919\n323\n458",
"output": "380.0729834"
},
{
"input": "188\n59\n126",
"output": "59.95675676"
},
{
"input": "644\n428\n484",
"output": "302.2280702"
},
{
"input": "253\n80\n276",
"output": "56.85393258"
},
{
"input": "745\n152\n417",
"output": "199.0158172"
},
{
"input": "600\n221\n279",
"output": "265.2"
},
{
"input": "690\n499\n430",
"output": "370.6243272"
},
{
"input": "105\n68\n403",
"output": "15.15923567"
},
{
"input": "762\n462\n371",
"output": "422.6218487"
},
{
"input": "903\n460\n362",
"output": "505.3284672"
},
{
"input": "886\n235\n95",
"output": "630.9393939"
},
{
"input": "655\n203\n18",
"output": "601.6515837"
},
{
"input": "718\n29\n375",
"output": "51.53960396"
},
{
"input": "296\n467\n377",
"output": "163.7819905"
},
{
"input": "539\n61\n56",
"output": "281.017094"
},
{
"input": "133\n53\n124",
"output": "39.82485876"
},
{
"input": "998\n224\n65",
"output": "773.5363322"
},
{
"input": "961\n173\n47",
"output": "755.6954545"
},
{
"input": "285\n468\n62",
"output": "251.6603774"
},
{
"input": "496\n326\n429",
"output": "214.1668874"
},
{
"input": "627\n150\n285",
"output": "216.2068966"
},
{
"input": "961\n443\n50",
"output": "863.535497"
},
{
"input": "623\n422\n217",
"output": "411.4334898"
},
{
"input": "678\n295\n29",
"output": "617.3148148"
}
] | 1,532,335,724 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 109 | 0 | n=int(input(''))
a=int(input(''))
b=int(input(''))
d=n/(a+b)
print(d*a)# your code goes here | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
Input Specification:
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Output Specification:
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['100\n50\n50\n', '199\n60\n40\n']
Demo Output:
['50\n', '119.4\n']
Note:
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | ```python
n=int(input(''))
a=int(input(''))
b=int(input(''))
d=n/(a+b)
print(d*a)# your code goes here
``` | 3 |
|
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively. | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"output": "5"
},
{
"input": "9\n2\n4\n1",
"output": "4"
},
{
"input": "9\n2\n2\n1",
"output": "8"
},
{
"input": "9\n10\n10\n1",
"output": "0"
},
{
"input": "10\n2\n2\n1",
"output": "9"
},
{
"input": "1000000000000000000\n2\n10\n9",
"output": "999999999999999995"
},
{
"input": "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000",
"output": "2"
},
{
"input": "10\n1\n9\n8",
"output": "10"
},
{
"input": "10\n8\n8\n7",
"output": "3"
},
{
"input": "10\n5\n5\n1",
"output": "2"
},
{
"input": "29\n3\n3\n1",
"output": "14"
},
{
"input": "45\n9\n9\n8",
"output": "37"
},
{
"input": "45\n9\n9\n1",
"output": "5"
},
{
"input": "100\n10\n10\n9",
"output": "91"
},
{
"input": "179\n10\n9\n1",
"output": "22"
},
{
"input": "179\n2\n2\n1",
"output": "178"
},
{
"input": "179\n179\n179\n1",
"output": "1"
},
{
"input": "179\n59\n59\n58",
"output": "121"
},
{
"input": "500\n250\n250\n1",
"output": "2"
},
{
"input": "500\n1\n250\n1",
"output": "500"
},
{
"input": "501\n500\n500\n499",
"output": "2"
},
{
"input": "501\n450\n52\n1",
"output": "9"
},
{
"input": "501\n300\n301\n100",
"output": "2"
},
{
"input": "500\n179\n10\n1",
"output": "55"
},
{
"input": "1000\n500\n10\n9",
"output": "991"
},
{
"input": "1000\n2\n10\n9",
"output": "995"
},
{
"input": "1001\n1000\n1000\n999",
"output": "2"
},
{
"input": "10000\n10000\n10000\n1",
"output": "1"
},
{
"input": "10000\n10\n5000\n4999",
"output": "5500"
},
{
"input": "1000000000\n999999998\n999999999\n999999998",
"output": "3"
},
{
"input": "1000000000\n50\n50\n49",
"output": "999999951"
},
{
"input": "1000000000\n500\n5000\n4999",
"output": "999995010"
},
{
"input": "1000000000\n51\n100\n98",
"output": "499999952"
},
{
"input": "1000000000\n100\n51\n50",
"output": "999999950"
},
{
"input": "1000000000\n2\n5\n4",
"output": "999999998"
},
{
"input": "1000000000000000000\n999999998000000000\n999999999000000000\n999999998000000000",
"output": "3"
},
{
"input": "1000000000\n2\n2\n1",
"output": "999999999"
},
{
"input": "999999999\n2\n999999998\n1",
"output": "499999999"
},
{
"input": "999999999999999999\n2\n2\n1",
"output": "999999999999999998"
},
{
"input": "999999999999999999\n10\n10\n9",
"output": "999999999999999990"
},
{
"input": "999999999999999999\n999999999999999998\n999999999999999998\n999999999999999997",
"output": "2"
},
{
"input": "999999999999999999\n501\n501\n1",
"output": "1999999999999999"
},
{
"input": "999999999999999999\n2\n50000000000000000\n49999999999999999",
"output": "974999999999999999"
},
{
"input": "999999999999999999\n180\n180\n1",
"output": "5586592178770949"
},
{
"input": "1000000000000000000\n42\n41\n1",
"output": "24999999999999999"
},
{
"input": "1000000000000000000\n41\n40\n1",
"output": "25641025641025641"
},
{
"input": "100000000000000000\n79\n100\n25",
"output": "1333333333333333"
},
{
"input": "1\n100\n5\n4",
"output": "0"
},
{
"input": "1000000000000000000\n1000000000000000000\n10000000\n9999999",
"output": "999999999990000001"
},
{
"input": "999999999999999999\n999999999000000000\n900000000000000000\n899999999999999999",
"output": "100000000000000000"
},
{
"input": "13\n10\n15\n11",
"output": "1"
},
{
"input": "1\n1000\n5\n4",
"output": "0"
},
{
"input": "10\n100\n10\n1",
"output": "1"
},
{
"input": "3\n2\n100000\n99999",
"output": "1"
},
{
"input": "4\n2\n4\n2",
"output": "2"
},
{
"input": "5\n3\n6\n4",
"output": "1"
},
{
"input": "1\n7\n65\n49",
"output": "0"
},
{
"input": "10\n20\n100\n99",
"output": "0"
},
{
"input": "10000000000\n10000000000\n9000000000\n8999999999",
"output": "1000000001"
},
{
"input": "90\n30\n101\n100",
"output": "3"
},
{
"input": "999999999999999\n5\n500000000000000\n499999999999999",
"output": "599999999999999"
},
{
"input": "1000000000000000000\n1000000000000000000\n1000000000\n999999999",
"output": "999999999000000001"
},
{
"input": "1\n1000000000000000000\n1000000000\n999999999",
"output": "0"
},
{
"input": "100000000000000000\n100000000000000000\n1000000000\n999999999",
"output": "99999999000000001"
},
{
"input": "100000000000000009\n100\n1000000000000000\n999999999999999",
"output": "99010000000000009"
},
{
"input": "10\n20\n10\n9",
"output": "1"
},
{
"input": "10\n4\n14\n13",
"output": "2"
},
{
"input": "11\n3\n9\n7",
"output": "4"
},
{
"input": "1000000000\n5\n7\n4",
"output": "333333332"
},
{
"input": "12155\n1943\n28717\n24074",
"output": "6"
},
{
"input": "1000000000000000000\n10\n20\n5",
"output": "100000000000000000"
},
{
"input": "98\n33\n440\n314",
"output": "2"
},
{
"input": "1070252292\n57449678\n237309920\n221182550",
"output": "56"
},
{
"input": "100\n3\n102\n101",
"output": "33"
},
{
"input": "100000000000000000\n100000000000000001\n1000000000000000\n999999999999999",
"output": "99000000000000001"
},
{
"input": "66249876257975628\n302307316\n406102416\n182373516",
"output": "296116756"
},
{
"input": "10\n5\n10\n1",
"output": "2"
},
{
"input": "1000000000000000000\n10\n1000000000\n999999998",
"output": "499999999600000000"
}
] | 1,455,660,440 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | n=int(input())
a=int(input())
b=int(input())
c=int(input())
if a<=b-c:
print(int(n/a))
else:
l=int((n-c)/(b-c))*(b-c)
if n-l*(b-c)<=a:
print(l)
else:
print(l+int((n-l*(b-c))/a))
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Output Specification:
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
Demo Input:
['10\n11\n9\n8\n', '10\n5\n6\n1\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | ```python
n=int(input())
a=int(input())
b=int(input())
c=int(input())
if a<=b-c:
print(int(n/a))
else:
l=int((n-c)/(b-c))*(b-c)
if n-l*(b-c)<=a:
print(l)
else:
print(l+int((n-l*(b-c))/a))
``` | 0 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1"
}
] | 1,677,867,634 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n = int(input())
indexes = list(map(int, input().split()))
str = ""
for i in range(1, n + 1):
print(indexes.index(i) + 1, end = ' ') | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
n = int(input())
indexes = list(map(int, input().split()))
str = ""
for i in range(1, n + 1):
print(indexes.index(i) + 1, end = ' ')
``` | 3 |
|
808 | D | Array Division | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"implementation"
] | null | null | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position? | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | [
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | 0 | [
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4 7 10 7 5 5 1",
"output": "NO"
},
{
"input": "8\n9 5 5 10 4 9 5 8",
"output": "NO"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "YES"
},
{
"input": "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8",
"output": "NO"
},
{
"input": "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13",
"output": "NO"
},
{
"input": "20\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6",
"output": "NO"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14",
"output": "YES"
},
{
"input": "100\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53",
"output": "NO"
},
{
"input": "100\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25",
"output": "NO"
},
{
"input": "100\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19",
"output": "NO"
},
{
"input": "100\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80",
"output": "NO"
},
{
"input": "6\n1 4 3 100 100 6",
"output": "YES"
},
{
"input": "6\n6 100 100 3 4 1",
"output": "YES"
},
{
"input": "6\n4 2 3 7 1 1",
"output": "YES"
},
{
"input": "4\n6 1 4 5",
"output": "NO"
},
{
"input": "3\n228 114 114",
"output": "YES"
},
{
"input": "3\n229 232 444",
"output": "NO"
},
{
"input": "3\n322 324 555",
"output": "NO"
},
{
"input": "3\n69 34 5",
"output": "NO"
},
{
"input": "6\n5 4 1 2 2 2",
"output": "YES"
},
{
"input": "3\n545 237 546",
"output": "NO"
},
{
"input": "5\n2 3 1 1 1",
"output": "YES"
},
{
"input": "6\n2 2 10 2 2 2",
"output": "YES"
},
{
"input": "5\n5 4 6 5 6",
"output": "NO"
},
{
"input": "5\n6 1 1 1 1",
"output": "NO"
},
{
"input": "2\n1 3",
"output": "NO"
},
{
"input": "5\n5 2 2 3 4",
"output": "YES"
},
{
"input": "2\n2 2",
"output": "YES"
},
{
"input": "5\n1 2 6 1 2",
"output": "YES"
},
{
"input": "5\n1 1 8 5 1",
"output": "YES"
},
{
"input": "10\n73 67 16 51 56 71 37 49 90 6",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "5\n8 2 7 5 4",
"output": "YES"
},
{
"input": "1\n2",
"output": "NO"
},
{
"input": "16\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2",
"output": "YES"
},
{
"input": "4\n8 2 2 4",
"output": "YES"
},
{
"input": "19\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3",
"output": "NO"
},
{
"input": "11\n7 2 1 8 8 2 4 10 8 7 1",
"output": "YES"
},
{
"input": "6\n10 20 30 40 99 1",
"output": "YES"
},
{
"input": "10\n3 7 9 2 10 1 9 6 4 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "2\n9 3",
"output": "NO"
},
{
"input": "7\n1 2 3 12 1 2 3",
"output": "YES"
},
{
"input": "6\n2 4 4 5 8 5",
"output": "YES"
},
{
"input": "18\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4",
"output": "YES"
},
{
"input": "20\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9",
"output": "NO"
},
{
"input": "12\n3 8 10 2 4 4 6 9 5 10 10 3",
"output": "YES"
},
{
"input": "11\n9 2 7 7 7 3 7 5 4 10 7",
"output": "NO"
},
{
"input": "5\n1 1 4 1 1",
"output": "YES"
},
{
"input": "2\n4 4",
"output": "YES"
},
{
"input": "2\n7 1",
"output": "NO"
},
{
"input": "5\n10 5 6 7 6",
"output": "YES"
},
{
"input": "11\n4 3 10 3 7 8 4 9 2 1 1",
"output": "YES"
},
{
"input": "6\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "NO"
},
{
"input": "8\n1 5 6 8 3 1 7 3",
"output": "YES"
},
{
"input": "20\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8",
"output": "YES"
},
{
"input": "11\n2 4 8 3 4 7 9 10 5 3 3",
"output": "YES"
},
{
"input": "7\n6 4 2 24 6 4 2",
"output": "YES"
},
{
"input": "17\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5",
"output": "NO"
},
{
"input": "7\n7 10 1 2 6 2 2",
"output": "NO"
},
{
"input": "5\n10 10 40 10 10",
"output": "YES"
},
{
"input": "3\n4 3 13",
"output": "NO"
},
{
"input": "5\n5 2 10 2 1",
"output": "YES"
},
{
"input": "7\n7 4 5 62 20 20 6",
"output": "YES"
},
{
"input": "6\n1 5 2 20 10 2",
"output": "YES"
},
{
"input": "2\n5 6",
"output": "NO"
},
{
"input": "14\n5 2 9 7 5 8 3 2 2 4 9 1 3 10",
"output": "YES"
},
{
"input": "5\n1 2 3 4 2",
"output": "YES"
},
{
"input": "5\n2 2 2 5 5",
"output": "NO"
},
{
"input": "11\n1 1 1 1 1 10 1 1 1 1 1",
"output": "YES"
},
{
"input": "9\n8 4 13 19 11 1 8 2 8",
"output": "YES"
},
{
"input": "6\n14 16 14 14 15 11",
"output": "YES"
},
{
"input": "9\n14 19 1 13 11 3 1 1 7",
"output": "YES"
},
{
"input": "6\n16 13 3 7 4 15",
"output": "YES"
},
{
"input": "4\n11 7 12 14",
"output": "NO"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "5\n2 1 3 6 4",
"output": "YES"
},
{
"input": "5\n3 4 8 11 2",
"output": "YES"
},
{
"input": "5\n1 2 10 3 4",
"output": "YES"
},
{
"input": "6\n8 15 12 14 15 4",
"output": "YES"
},
{
"input": "5\n1 2 4 4 5",
"output": "YES"
},
{
"input": "3\n2 4 2",
"output": "YES"
},
{
"input": "5\n2 3 1 6 4",
"output": "YES"
},
{
"input": "7\n1 2 3 12 3 2 1",
"output": "YES"
},
{
"input": "3\n3 4 13",
"output": "NO"
},
{
"input": "6\n1 1 1 1 1000000000 1000000000",
"output": "YES"
},
{
"input": "6\n19 6 5 13 6 13",
"output": "YES"
},
{
"input": "8\n2 2 2 5 1 2 3 3",
"output": "YES"
}
] | 1,594,197,959 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 11 | 155 | 21,196,800 | n=int(input())
z=list(map(int,input().split()))
s=sum(z)
c=s;f=1
for i in range(0,n):
c-=z[i]
if c-(s/2) in z[i+1:] :
print("YES")
f=0
break
if f :
print("NO")
| Title: Array Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Output Specification:
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
Demo Input:
['3\n1 3 2\n', '5\n1 2 3 4 5\n', '5\n2 2 3 4 5\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | ```python
n=int(input())
z=list(map(int,input().split()))
s=sum(z)
c=s;f=1
for i in range(0,n):
c-=z[i]
if c-(s/2) in z[i+1:] :
print("YES")
f=0
break
if f :
print("NO")
``` | 0 |
|
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 1,655,753,722 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 186 | 1,331,200 | def flag():
for i in range(n):
for j in range(m):
if l[i][j]!=l[i][0]:
return False
for i in range(1,n):
if l[i][0]==l[i-1][0]:
return False
return True
n,m=map(int,input().split())
l=[]
for i in range(n):
l.append(input())
if flag():
print("YES")
else:
print("NO") | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input Specification:
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output Specification:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Demo Input:
['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
def flag():
for i in range(n):
for j in range(m):
if l[i][j]!=l[i][0]:
return False
for i in range(1,n):
if l[i][0]==l[i-1][0]:
return False
return True
n,m=map(int,input().split())
l=[]
for i in range(n):
l.append(input())
if flag():
print("YES")
else:
print("NO")
``` | 3.943582 |
358 | B | Dima and Text Messages | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3*word*1<3*word*2<3 ... *word**n*<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. | In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. | [
"3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n"
] | [
"yes\n",
"no\n"
] | Please note that Dima got a good old kick in the pants for the second sample from the statement. | 1,000 | [
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3",
"output": "yes"
},
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3",
"output": "yes"
},
{
"input": "4\na\nb\nc\nd\n<3a<3b<3c<3d",
"output": "no"
},
{
"input": "4\na\nb\nc\nd\na<3b<3c<3d<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<3you<3",
"output": "yes"
},
{
"input": "1\na\na",
"output": "no"
},
{
"input": "1\na\n<3a<3b",
"output": "yes"
},
{
"input": "1\naa\n<3a<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww",
"output": "yes"
},
{
"input": "3\ni\nlove\nyou\n<3ilove<23you<3",
"output": "no"
},
{
"input": "2\na\ni\n<3ai<3",
"output": "no"
}
] | 1,543,031,046 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | ls,ts='<','3'
def ch(s,f,l):
dl=s.find(ls)
dt=s.find(ts)
if dt!=-1 and dl!=-1 and dl<dt:
return 1
else:
return 0
def cw(s,w,f):
l=s.find(w,f)
if l!=-1 and ch(s,f,l):
return 1,l
else:
return 0,0
def cg(s,v):
f=0
for c in v:
b,f=cw(s,c,f)
if not b:
return 0
return 1
n=int(input())
v=[]
for c in range(n):
v.append(input())
s=input()
rs='yes' if cg(s,v) else 'no'
print(rs) | Title: Dima and Text Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3*word*1<3*word*2<3 ... *word**n*<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
Output Specification:
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
Demo Input:
['3\ni\nlove\nyou\n<3i<3love<23you<3\n', '7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n']
Demo Output:
['yes\n', 'no\n']
Note:
Please note that Dima got a good old kick in the pants for the second sample from the statement. | ```python
ls,ts='<','3'
def ch(s,f,l):
dl=s.find(ls)
dt=s.find(ts)
if dt!=-1 and dl!=-1 and dl<dt:
return 1
else:
return 0
def cw(s,w,f):
l=s.find(w,f)
if l!=-1 and ch(s,f,l):
return 1,l
else:
return 0,0
def cg(s,v):
f=0
for c in v:
b,f=cw(s,c,f)
if not b:
return 0
return 1
n=int(input())
v=[]
for c in range(n):
v.append(input())
s=input()
rs='yes' if cg(s,v) else 'no'
print(rs)
``` | 0 |
|
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "2",
"output": "1 2"
},
{
"input": "3",
"output": "1 3"
},
{
"input": "4",
"output": "2 2"
},
{
"input": "6",
"output": "2 3"
},
{
"input": "7",
"output": "1 7"
},
{
"input": "9",
"output": "3 3"
},
{
"input": "10",
"output": "2 5"
},
{
"input": "11",
"output": "1 11"
},
{
"input": "12",
"output": "3 4"
},
{
"input": "15",
"output": "3 5"
},
{
"input": "100",
"output": "10 10"
},
{
"input": "101",
"output": "1 101"
},
{
"input": "169",
"output": "13 13"
},
{
"input": "179",
"output": "1 179"
},
{
"input": "190",
"output": "10 19"
},
{
"input": "1000",
"output": "25 40"
},
{
"input": "10000",
"output": "100 100"
},
{
"input": "10001",
"output": "73 137"
},
{
"input": "100000",
"output": "250 400"
},
{
"input": "100001",
"output": "11 9091"
},
{
"input": "1000000",
"output": "1000 1000"
},
{
"input": "999983",
"output": "1 999983"
},
{
"input": "524288",
"output": "512 1024"
},
{
"input": "954493",
"output": "971 983"
},
{
"input": "966289",
"output": "983 983"
},
{
"input": "944663",
"output": "961 983"
},
{
"input": "912673",
"output": "97 9409"
},
{
"input": "732641",
"output": "679 1079"
},
{
"input": "232897",
"output": "343 679"
},
{
"input": "16807",
"output": "49 343"
},
{
"input": "999958",
"output": "2 499979"
},
{
"input": "990151",
"output": "1 990151"
},
{
"input": "997002",
"output": "998 999"
},
{
"input": "20",
"output": "4 5"
},
{
"input": "20261",
"output": "1 20261"
},
{
"input": "999123",
"output": "3 333041"
},
{
"input": "901841",
"output": "1 901841"
}
] | 1,488,263,736 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 249 | 4,608,000 | def solve():
global a,b,n
now= 1e9
for i in range(1,n+1):
if (n%i==0):
if (i>n//i):
break
a= i
b= n//i
n= int(input())
solve()
print(a,b)
| Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Output Specification:
Print two integers — the number of rows and columns on the display.
Demo Input:
['8\n', '64\n', '5\n', '999999\n']
Demo Output:
['2 4\n', '8 8\n', '1 5\n', '999 1001\n']
Note:
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | ```python
def solve():
global a,b,n
now= 1e9
for i in range(1,n+1):
if (n%i==0):
if (i>n//i):
break
a= i
b= n//i
n= int(input())
solve()
print(a,b)
``` | 3 |
|
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 1,660,409,561 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 61 | 124 | 0 | n = int(input())
arr = list(map (int, input().split()))
# n = 7
# arr = [5,1,0]
biceps,chest,back = 0,0,0
i = 0
for itr in range(len(arr)) :
if i == 0 :
chest+=arr[itr]
if i==1 :
biceps +=arr[itr]
if i == 2 :
back += arr[itr]
i+=1
i = i%3
if biceps > chest and biceps > back :
print("biceps")
elif chest > biceps and chest > back :
print("chest")
else:
print("back") | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Output Specification:
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Demo Input:
['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n']
Demo Output:
['biceps\n', 'back\n', 'chest\n']
Note:
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | ```python
n = int(input())
arr = list(map (int, input().split()))
# n = 7
# arr = [5,1,0]
biceps,chest,back = 0,0,0
i = 0
for itr in range(len(arr)) :
if i == 0 :
chest+=arr[itr]
if i==1 :
biceps +=arr[itr]
if i == 2 :
back += arr[itr]
i+=1
i = i%3
if biceps > chest and biceps > back :
print("biceps")
elif chest > biceps and chest > back :
print("chest")
else:
print("back")
``` | 3 |
|
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get? | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output": "2"
},
{
"input": "5 1\nFACJT",
"output": "1"
},
{
"input": "5 5\nMJDIJ",
"output": "7"
},
{
"input": "15 5\nAZBIPTOFTJCJJIK",
"output": "13"
},
{
"input": "100 1\nEVEEVEEEGGECFEHEFVFVFHVHEEEEEFCVEEEEEEVFVEEVEEHEEVEFEVVEFEEEFEVECEHGHEEFGEEVCEECCECEFHEVEEEEEEGEEHVH",
"output": "1"
},
{
"input": "100 15\nKKTFFUTFCKUIKKKKFIFFKTUKUUKUKKIKKKTIFKTKUCFFKKKIIKKKKKKTFKFKKIRKKKFKUUKIKUUUFFKKKKTUZKITUIKKIKUKKTIK",
"output": "225"
},
{
"input": "100 50\nYYIYYAAAIEAAYAYAEAIIIAAEAAYEAEYYYIAEYAYAYYAAAIAYAEAAYAYYIYAAYYAAAAAAIYYYAAYAAEAAYAIEIYIYAYAYAYIIAAEY",
"output": "1972"
},
{
"input": "100 90\nFAFAOOAOOAFAOTFAFAFFATAAAOFAAOAFBAAAFBOAOFFFOAOAFAPFOFAOFAAFOAAAAFAAFOFAAOFPPAAOOAAOOFFOFFFOFAOTOFAF",
"output": "2828"
},
{
"input": "100 99\nBFFBBFBFBQFFFFFQBFFBFFBQFBFQFBBFQFFFBFFFBFQFQFBFFBBFYQFBFFFFFFFBQQFQBFBQBQFFFBQQFFFBQFYFBFBFFFBBBQQY",
"output": "3713"
},
{
"input": "100 100\nMQSBDAJABILIBCUEOWGWCEXMUTEYQKAIWGINXVQEOFDUBSVULROQHQRZZAALVQFEFRAAAYUIMGCAFQGIAEFBETRECGSFQJNXHHDN",
"output": "514"
},
{
"input": "100 50\nBMYIXQSJNHGFVFPJBIOBXIKSFNUFPVODCUBQYSIIQNVNXXCWXWRHKFEUPPIIDDGRDBJLZDCBMNJMYRMWFIHOSTDJJHXHPNRKWNFD",
"output": "328"
},
{
"input": "100 50\nENFNEMLJEMDMFMNNGNIMNINALGLLLAEMENEMNLMMIEIJNAINBJEJMFJLLIMINELGFLAIAMJMHMGNLIEFJIEEFEFGLLLDLMEAEIMM",
"output": "748"
}
] | 1,623,036,021 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 124 | 102,400 |
n,k = map(int,input().split())
s = input()
from collections import Counter
c = Counter(s)
# print(c)
res = 0
e = sorted(list(c.values()))
e = e[::-1]
# print(e)
while k!=0:
for i in e:
if i<=k:
res+=i*i
# print(res)
k-=i
# print(k)
if k<min(e):
break
if k!=0:
res+=k
print(res) | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
Output Specification:
Print a single integer – the answer to the problem.
Demo Input:
['15 10\nDZFDFZDFDDDDDDF\n', '6 4\nYJSNPI\n']
Demo Output:
['82\n', '4\n']
Note:
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | ```python
n,k = map(int,input().split())
s = input()
from collections import Counter
c = Counter(s)
# print(c)
res = 0
e = sorted(list(c.values()))
e = e[::-1]
# print(e)
while k!=0:
for i in e:
if i<=k:
res+=i*i
# print(res)
k-=i
# print(k)
if k<min(e):
break
if k!=0:
res+=k
print(res)
``` | 0 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,696,955,346 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | moves = [1,2,3,4,5]
num = int(input())
cnt=0
indx=4
while num!=0 and indx>=0:
if num-moves[indx]>0:
cnt+=1
num=num-moves[indx]
else:
indx=indx-1
print(cnt) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
moves = [1,2,3,4,5]
num = int(input())
cnt=0
indx=4
while num!=0 and indx>=0:
if num-moves[indx]>0:
cnt+=1
num=num-moves[indx]
else:
indx=indx-1
print(cnt)
``` | 0 |
|
369 | C | Valera and Elections | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired.
There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located.
Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city.
Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road.
It's guaranteed that the graph structure of the city is a tree. | In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them. | [
"5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n",
"5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n",
"5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n"
] | [
"1\n5 \n",
"1\n3 \n",
"4\n5 4 3 2 \n"
] | none | 1,500 | [
{
"input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2",
"output": "1\n5 "
},
{
"input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1",
"output": "1\n3 "
},
{
"input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2",
"output": "4\n5 4 3 2 "
},
{
"input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2",
"output": "1\n2 "
},
{
"input": "2\n1 2 1",
"output": "0"
},
{
"input": "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2",
"output": "3\n8 6 3 "
},
{
"input": "2\n2 1 1",
"output": "0"
},
{
"input": "2\n1 2 2",
"output": "1\n2 "
},
{
"input": "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1",
"output": "0"
},
{
"input": "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2",
"output": "2\n5 2 "
},
{
"input": "10\n1 9 1\n3 2 2\n1 2 2\n4 7 2\n3 5 2\n4 3 2\n10 3 2\n7 8 2\n3 6 1",
"output": "3\n8 10 5 "
},
{
"input": "10\n7 9 2\n2 6 2\n7 4 1\n5 4 2\n3 2 1\n8 5 2\n4 3 2\n7 10 1\n1 2 2",
"output": "3\n9 8 6 "
},
{
"input": "10\n3 9 1\n2 10 2\n1 7 1\n3 4 1\n7 8 2\n1 2 1\n5 3 1\n5 6 2\n2 3 2",
"output": "3\n6 10 8 "
},
{
"input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 1\n7 5 1\n6 4 1\n5 3 1\n4 2 1",
"output": "2\n7 8 "
},
{
"input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 2\n7 5 2\n6 4 2\n5 3 2\n4 2 2",
"output": "2\n3 2 "
},
{
"input": "4\n1 2 2\n2 3 1\n2 4 2",
"output": "1\n4 "
}
] | 1,684,342,189 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 436 | 74,137,600 | # compiler on CodeForces: PyPy 3 64bit
import sys
from collections import defaultdict
input = lambda: sys.stdin.readline()[:-1]
print = lambda *args: sys.stdout.write(' '.join(map(str, args)) + '\n')
graph = defaultdict(dict)
n = int(input())
for _ in range(n - 1):
x, y, t = [int(e) for e in input().split()]
graph[x][y] = t
graph[y][x] = t
q = [1]
parent = {}
childs = defaultdict(list)
used = set()
while q:
q_new = []
for a in q:
used.add(a)
for b in graph[a]:
if b in used:
continue
childs[a].append(b)
parent[b] = a
q_new.append(b)
q = q_new[:]
while True:
leaves = []
for k in parent:
if k not in childs:
leaves.append(k)
leaves_new = []
for k in leaves:
p = parent[k]
if graph[k][p] == 2:
leaves_new.append(k)
else:
parent.pop(k)
if len(leaves) == len(leaves_new):
break
print(len(leaves))
print(*leaves)
| Title: Valera and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired.
There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located.
Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city.
Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road.
It's guaranteed that the graph structure of the city is a tree.
Output Specification:
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.
Demo Input:
['5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n', '5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n', '5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n']
Demo Output:
['1\n5 \n', '1\n3 \n', '4\n5 4 3 2 \n']
Note:
none | ```python
# compiler on CodeForces: PyPy 3 64bit
import sys
from collections import defaultdict
input = lambda: sys.stdin.readline()[:-1]
print = lambda *args: sys.stdout.write(' '.join(map(str, args)) + '\n')
graph = defaultdict(dict)
n = int(input())
for _ in range(n - 1):
x, y, t = [int(e) for e in input().split()]
graph[x][y] = t
graph[y][x] = t
q = [1]
parent = {}
childs = defaultdict(list)
used = set()
while q:
q_new = []
for a in q:
used.add(a)
for b in graph[a]:
if b in used:
continue
childs[a].append(b)
parent[b] = a
q_new.append(b)
q = q_new[:]
while True:
leaves = []
for k in parent:
if k not in childs:
leaves.append(k)
leaves_new = []
for k in leaves:
p = parent[k]
if graph[k][p] == 2:
leaves_new.append(k)
else:
parent.pop(k)
if len(leaves) == len(leaves_new):
break
print(len(leaves))
print(*leaves)
``` | 0 |
|
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '>', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '<'. If there is no such position, in other words if *i*<=-<=1<=<<=1 or *i*<=+<=1<=><=*n*, the ball falls from the game field.
Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input": "1\n<",
"output": "1"
},
{
"input": "2\n<>",
"output": "2"
},
{
"input": "3\n<>>",
"output": "3"
},
{
"input": "3\n><>",
"output": "1"
},
{
"input": "2\n><",
"output": "0"
},
{
"input": "2\n>>",
"output": "2"
},
{
"input": "2\n<<",
"output": "2"
},
{
"input": "1\n>",
"output": "1"
},
{
"input": "3\n>><",
"output": "0"
},
{
"input": "3\n>>>",
"output": "3"
},
{
"input": "3\n<><",
"output": "1"
},
{
"input": "10\n<<<><<<>>>",
"output": "6"
},
{
"input": "20\n><><<><<<>>>>>>>>>>>",
"output": "11"
},
{
"input": "20\n<<<<<<<<<<><<<<>>>>>",
"output": "15"
},
{
"input": "50\n<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>",
"output": "50"
},
{
"input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>",
"output": "49"
},
{
"input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><",
"output": "50"
},
{
"input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
"output": "100"
},
{
"input": "100\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
"output": "100"
},
{
"input": "12\n<<>><<>><<>>",
"output": "4"
},
{
"input": "6\n<<><>>",
"output": "4"
},
{
"input": "6\n><>>>>",
"output": "4"
},
{
"input": "8\n>>>><<<>",
"output": "1"
},
{
"input": "4\n<><>",
"output": "2"
},
{
"input": "4\n><><",
"output": "0"
},
{
"input": "7\n<<>>><>",
"output": "3"
},
{
"input": "10\n><><>>>>>>",
"output": "6"
},
{
"input": "5\n<><>>",
"output": "3"
},
{
"input": "12\n<><<<<>>>>>>",
"output": "7"
},
{
"input": "6\n<>><<>",
"output": "2"
},
{
"input": "6\n>>><>>",
"output": "2"
},
{
"input": "10\n><><>>>><>",
"output": "1"
},
{
"input": "5\n><>>>",
"output": "3"
},
{
"input": "5\n<<><>",
"output": "3"
},
{
"input": "5\n<><<<",
"output": "1"
},
{
"input": "4\n<><<",
"output": "1"
},
{
"input": "8\n<<>><<>>",
"output": "4"
},
{
"input": "7\n<<><>>>",
"output": "5"
},
{
"input": "5\n><<>>",
"output": "2"
},
{
"input": "10\n<<<<<>>>>>",
"output": "10"
},
{
"input": "6\n><<<<<",
"output": "0"
},
{
"input": "8\n<<><><>>",
"output": "4"
},
{
"input": "10\n<<<<><<<><",
"output": "4"
},
{
"input": "12\n<<<>>>><<>>>",
"output": "6"
},
{
"input": "4\n><>>",
"output": "2"
},
{
"input": "11\n<<><<>><<>>",
"output": "4"
}
] | 1,503,451,981 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 61 | 2,560,000 | ##n = int(input())
##a = list(map(int, input().split()))
##print(" ".join(map(str, res)))
n = int(input())
s = list(input())
def go(p, vis):
if p < 0 or p >= n:
return -1
if vis[p] != 0:
return vis[p]
vis[p] = 1
if s[p] == '<':
res = go(p-1, vis)
if s[p] == '>':
res = go(p+1, vis)
vis[p] = res
return res
vis = [0]*n
for p in range(n):
if vis[p] == 0:
go(p, vis)
res = 0
for p in range(n):
if vis[p] == -1:
res += 1
print(res)
| Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '>', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '<'. If there is no such position, in other words if *i*<=-<=1<=<<=1 or *i*<=+<=1<=><=*n*, the ball falls from the game field.
Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper.
Output Specification:
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
Demo Input:
['4\n<<><\n', '5\n>>>>>\n', '4\n>><<\n']
Demo Output:
['2', '5', '0']
Note:
In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | ```python
##n = int(input())
##a = list(map(int, input().split()))
##print(" ".join(map(str, res)))
n = int(input())
s = list(input())
def go(p, vis):
if p < 0 or p >= n:
return -1
if vis[p] != 0:
return vis[p]
vis[p] = 1
if s[p] == '<':
res = go(p-1, vis)
if s[p] == '>':
res = go(p+1, vis)
vis[p] = res
return res
vis = [0]*n
for p in range(n):
if vis[p] == 0:
go(p, vis)
res = 0
for p in range(n):
if vis[p] == -1:
res += 1
print(res)
``` | -1 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,645,890,663 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 154 | 0 | t=int(input())
d={}
for i in range(t):
s=input().strip()
d.setdefault(s,0)
d[s]+=1
print(len(d))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
t=int(input())
d={}
for i in range(t):
s=input().strip()
d.setdefault(s,0)
d[s]+=1
print(len(d))
``` | 3.9615 |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"input": "1 1\n5",
"output": "1 1"
},
{
"input": "10 4\n1 1 2 2 3 3 4 4 4 4",
"output": "2 7"
},
{
"input": "4 2\n3 3 4 3",
"output": "2 3"
},
{
"input": "4 3\n4 4 4 2",
"output": "-1 -1"
},
{
"input": "10 5\n15 17 2 13 3 16 4 5 9 12",
"output": "1 5"
},
{
"input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148",
"output": "1 13"
},
{
"input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796",
"output": "-1 -1"
},
{
"input": "8 5\n1 2 1 1 2 3 4 5",
"output": "4 8"
},
{
"input": "7 3\n2 1 2 2 1 2 3",
"output": "5 7"
},
{
"input": "6 3\n1 3 1 1 4 5",
"output": "2 5"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2 5"
},
{
"input": "9 3\n1 2 1 2 1 2 2 3 1",
"output": "5 8"
},
{
"input": "4 3\n1 2 1 3",
"output": "2 4"
},
{
"input": "5 3\n1 3 1 3 4",
"output": "3 5"
},
{
"input": "6 3\n1 3 3 1 4 4",
"output": "3 5"
},
{
"input": "5 3\n1 2 1 2 3",
"output": "3 5"
},
{
"input": "8 4\n1 2 3 2 1 2 3 4",
"output": "5 8"
},
{
"input": "10 4\n1 2 3 1 2 3 4 3 2 1",
"output": "4 7"
},
{
"input": "10 3\n1 1 1 2 1 2 3 3 3 4",
"output": "5 7"
},
{
"input": "10 3\n1 1 2 1 2 2 3 4 5 6",
"output": "4 7"
}
] | 1,629,613,413 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 6,963,200 | def array(n, k, arr):
if n == 1:
if k == 1:
return 1, 1
else:
return -1, -1
l = 0
r = 1
cnt = 1
found_l = False
my_dict = {}
my_dict[arr[0]] = 1
while r < n:
if arr[l] != arr[r]:
found_l = True
else:
if not found_l:
l = r
if my_dict.get(arr[r]) is None:
my_dict[arr[r]] = 1
cnt += 1
if cnt == k:
return l + 1, r + 1
r += 1
return -1, -1
first_line_input = list(map(int, input().split()))
A = list(map(int, input().split()))
N = first_line_input[0]
K = first_line_input[1]
l, r = array(N, K, A)
print("%d %d" % (l, r))
| Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
Input Specification:
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
Demo Input:
['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n']
Demo Output:
['1 2\n', '2 5\n', '-1 -1\n']
Note:
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | ```python
def array(n, k, arr):
if n == 1:
if k == 1:
return 1, 1
else:
return -1, -1
l = 0
r = 1
cnt = 1
found_l = False
my_dict = {}
my_dict[arr[0]] = 1
while r < n:
if arr[l] != arr[r]:
found_l = True
else:
if not found_l:
l = r
if my_dict.get(arr[r]) is None:
my_dict[arr[r]] = 1
cnt += 1
if cnt == k:
return l + 1, r + 1
r += 1
return -1, -1
first_line_input = list(map(int, input().split()))
A = list(map(int, input().split()))
N = first_line_input[0]
K = first_line_input[1]
l, r = array(N, K, A)
print("%d %d" % (l, r))
``` | 0 |
|
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* and so on. Thus, the bus moves from *x*<==<=0 to *x*<==<=*a* and back. Moving from the point *x*<==<=0 to *x*<==<=*a* or from the point *x*<==<=*a* to *x*<==<=0 is called a bus journey. In total, the bus must make *k* journeys.
The petrol tank of the bus can hold *b* liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point *x*<==<=*f*. This point is between points *x*<==<=0 and *x*<==<=*a*. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain *b* liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point *x*<==<=*f* to make *k* journeys? The first journey starts in the point *x*<==<=0. | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling. | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
"input": "2 1 1 1",
"output": "1"
},
{
"input": "1000000 51923215 2302 10000",
"output": "199"
},
{
"input": "10 11 3 2",
"output": "-1"
},
{
"input": "20 50 10 25",
"output": "11"
},
{
"input": "10 10 5 20",
"output": "20"
},
{
"input": "15 65 5 50",
"output": "12"
},
{
"input": "10 19 1 5",
"output": "3"
},
{
"input": "10 19 9 5",
"output": "3"
},
{
"input": "23 46 12 2",
"output": "0"
},
{
"input": "23 46 12 3",
"output": "1"
},
{
"input": "20 20 19 1",
"output": "0"
},
{
"input": "20 23 17 2",
"output": "1"
},
{
"input": "100 70 50 1",
"output": "1"
},
{
"input": "100 70 70 2",
"output": "2"
},
{
"input": "140 480 139 40",
"output": "18"
},
{
"input": "1000000 1000000000 1 1000",
"output": "0"
},
{
"input": "100000 1000000 50000 1000",
"output": "100"
},
{
"input": "1000000 1000000 500000 1000",
"output": "1000"
},
{
"input": "1000000 1000000 500000 10000",
"output": "10000"
},
{
"input": "1000000 2500000 500000 9999",
"output": "4998"
},
{
"input": "1000000 1500000 500000 9999",
"output": "9997"
},
{
"input": "1000000 1500000 500000 10000",
"output": "9998"
},
{
"input": "1000000 1 1 1",
"output": "-1"
},
{
"input": "2 1000000000 1 1",
"output": "0"
},
{
"input": "1000000 1000000000 1 1",
"output": "0"
},
{
"input": "1000000 1 999999 1",
"output": "-1"
},
{
"input": "1000000 1000000000 999999 1",
"output": "0"
},
{
"input": "2 1 1 10000",
"output": "-1"
},
{
"input": "1000000 1 1 10000",
"output": "-1"
},
{
"input": "1000000 1000000000 1 10000",
"output": "10"
},
{
"input": "1000000 1 999999 10000",
"output": "-1"
},
{
"input": "2 1000000000 1 10000",
"output": "0"
},
{
"input": "1000000 1000000000 999999 10000",
"output": "10"
},
{
"input": "10000 78393 3000 9999",
"output": "1428"
},
{
"input": "1000000 8839233 302200 9999",
"output": "1249"
},
{
"input": "900005 3333333 210000 9999",
"output": "3332"
},
{
"input": "6 7 4 2",
"output": "2"
},
{
"input": "3 1 2 1",
"output": "-1"
},
{
"input": "150 100 1 1",
"output": "-1"
},
{
"input": "10 5 6 1",
"output": "-1"
},
{
"input": "51 81 36 38",
"output": "36"
},
{
"input": "100 159 80 2",
"output": "1"
}
] | 1,539,445,295 | 1,895 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | a,b,f,k=map(int,input().split())
tank=b-f
if(2*(a-f)>b or 2*f>b or f>b):
print(-1)
else:
ans=0
for i in range(k-1):
if(i%2==0):
if(tank<2*(a-f)):
tank=b-2*(a-f)
ans+=1
else:
tank-=2*(a-f)
else:
if(tank<2*f):
tank=b-2*(f)
ans+=1
else:
tank-=2*f
if(k%2==0):
if(tank<f):
ans+=1
else:
if(tank<a-f):
ans+=1
print(ans)
| Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* and so on. Thus, the bus moves from *x*<==<=0 to *x*<==<=*a* and back. Moving from the point *x*<==<=0 to *x*<==<=*a* or from the point *x*<==<=*a* to *x*<==<=0 is called a bus journey. In total, the bus must make *k* journeys.
The petrol tank of the bus can hold *b* liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point *x*<==<=*f*. This point is between points *x*<==<=0 and *x*<==<=*a*. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain *b* liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point *x*<==<=*f* to make *k* journeys? The first journey starts in the point *x*<==<=0.
Input Specification:
The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
Output Specification:
Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1.
Demo Input:
['6 9 2 4\n', '6 10 2 4\n', '6 5 4 3\n']
Demo Output:
['4\n', '2\n', '-1\n']
Note:
In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling. | ```python
a,b,f,k=map(int,input().split())
tank=b-f
if(2*(a-f)>b or 2*f>b or f>b):
print(-1)
else:
ans=0
for i in range(k-1):
if(i%2==0):
if(tank<2*(a-f)):
tank=b-2*(a-f)
ans+=1
else:
tank-=2*(a-f)
else:
if(tank<2*f):
tank=b-2*(f)
ans+=1
else:
tank-=2*f
if(k%2==0):
if(tank<f):
ans+=1
else:
if(tank<a-f):
ans+=1
print(ans)
``` | 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,685,641,434 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def find(n, x, y):
return n - x
| 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
def find(n, x, y):
return n - x
``` | 0 |
|
190 | D | Non-Secret Cypher | PROGRAMMING | 1,900 | [
"two pointers"
] | null | null | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*). | The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 2\n1 2 1 2\n",
"5 3\n1 2 1 1 3\n",
"3 1\n1 1 1\n"
] | [
"3",
"2",
"6"
] | In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | 2,000 | [
{
"input": "4 2\n1 2 1 2",
"output": "3"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10",
"output": "131"
},
{
"input": "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3 1 1 3 1 1 1 1 2 1 1 6 3 2 1 1 1 1 2 2 3 2 1 1 1 2 1 4 2 1 2 3 2 1 1 1 1 2 4 3 4 2 5 1 1 2 1",
"output": "1882"
},
{
"input": "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 79919 76826 79919 79919 76826 76826 46132 76826 40347 79919 46132 76826 83599 79919 79919 46132 46132 46132 83599 83599 79919 46132 83599 93821 76826 81314 79919 79919 83599 76826 76826 76826 76826 46132 76826 46132 79919 76826 83599 79919 40347 76826 46132 46132 93821 76826 79919 46132 83599 93821 46132 46132",
"output": "1356"
},
{
"input": "6 3\n6 6 4 4 6 2",
"output": "2"
},
{
"input": "100 1\n5 2 5 1 1 4 1 5 4 5 5 5 4 4 1 3 2 3 1 5 1 4 2 4 5 5 5 2 1 3 2 5 5 4 2 1 3 2 2 2 4 4 4 2 1 1 5 4 2 5 3 4 5 5 5 3 1 3 5 4 1 4 5 2 3 2 5 3 5 1 4 2 2 3 2 4 4 3 2 3 5 3 1 3 4 1 5 4 2 5 4 3 1 4 3 2 1 5 2 5",
"output": "5050"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "2 1\n42 1000000000",
"output": "3"
},
{
"input": "2 2\n193 193",
"output": "1"
},
{
"input": "2 2\n97 197",
"output": "0"
}
] | 1,677,961,032 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 42,496,000 | from typing import List, Dict
# https://codeforces.com/problemset/problem/190/D?locale=en
class Occurence:
def __init__(self, num: int, occ: int = 1):
self.num = num
self.occ = occ
def increment(self):
self.occ += 1
def decrement(self):
self.occ -= 1
class PrioritySet:
def __init__(self):
self.numToPositionInQueue: Dict[int, int] = {}
self.occurences: List[Occurence] = []
def insert(self, num: int):
position = self.numToPositionInQueue.get(num)
if position is None:
position = len(self.occurences)
self.occurences.append(Occurence(num))
self.numToPositionInQueue[num] = position
else:
self.occurences[position].increment()
self.__balance(position)
def remove(self, num):
position = self.numToPositionInQueue.get(num)
if position is not None:
self.occurences[position].decrement()
self.__balance(position)
def getMaxOccurrence(self):
return self.occurences[0].occ
def __balance(self, position):
while position > 0 and self.occurences[position//2].occ < self.occurences[position].occ:
parentIndex = position//2
parent = self.occurences[parentIndex]
child = self.occurences[position]
self.numToPositionInQueue[parent.num] = position
self.occurences[position] = parent
self.numToPositionInQueue[child.num] = parentIndex
self.occurences[parentIndex] = child
position = parentIndex
def main():
n, k = map(int, input().split())
aStr = input().split()
a = [None] * n
subarraysCount = 0
prioritySet = PrioritySet()
for i in range(n):
a[i] = int(aStr[i])
i, j = 0, 0
insert = True
while j < n and i <= j:
if insert:
prioritySet.insert(a[j])
if prioritySet.getMaxOccurrence() == k:
subarraysCount += n-j
prioritySet.remove(a[i])
i += 1
insert = i > j
if insert:
j += 1
else:
j += 1
insert = True
print(subarraysCount)
main() | Title: Non-Secret Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*).
Input Specification:
The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['4 2\n1 2 1 2\n', '5 3\n1 2 1 1 3\n', '3 1\n1 1 1\n']
Demo Output:
['3', '2', '6']
Note:
In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | ```python
from typing import List, Dict
# https://codeforces.com/problemset/problem/190/D?locale=en
class Occurence:
def __init__(self, num: int, occ: int = 1):
self.num = num
self.occ = occ
def increment(self):
self.occ += 1
def decrement(self):
self.occ -= 1
class PrioritySet:
def __init__(self):
self.numToPositionInQueue: Dict[int, int] = {}
self.occurences: List[Occurence] = []
def insert(self, num: int):
position = self.numToPositionInQueue.get(num)
if position is None:
position = len(self.occurences)
self.occurences.append(Occurence(num))
self.numToPositionInQueue[num] = position
else:
self.occurences[position].increment()
self.__balance(position)
def remove(self, num):
position = self.numToPositionInQueue.get(num)
if position is not None:
self.occurences[position].decrement()
self.__balance(position)
def getMaxOccurrence(self):
return self.occurences[0].occ
def __balance(self, position):
while position > 0 and self.occurences[position//2].occ < self.occurences[position].occ:
parentIndex = position//2
parent = self.occurences[parentIndex]
child = self.occurences[position]
self.numToPositionInQueue[parent.num] = position
self.occurences[position] = parent
self.numToPositionInQueue[child.num] = parentIndex
self.occurences[parentIndex] = child
position = parentIndex
def main():
n, k = map(int, input().split())
aStr = input().split()
a = [None] * n
subarraysCount = 0
prioritySet = PrioritySet()
for i in range(n):
a[i] = int(aStr[i])
i, j = 0, 0
insert = True
while j < n and i <= j:
if insert:
prioritySet.insert(a[j])
if prioritySet.getMaxOccurrence() == k:
subarraysCount += n-j
prioritySet.remove(a[i])
i += 1
insert = i > j
if insert:
j += 1
else:
j += 1
insert = True
print(subarraysCount)
main()
``` | 0 |
|
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"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": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 1,627,313,900 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 6,963,200 | import sys
n = int(input())
inp = [int(x) for x in input().split()]
inp.sort(reverse=True)
min = sys.maxsize
if len(inp) == 2:
min = inp[0]-inp[1]
else:
for i in range(n-1):
if inp[i]-inp[i+1] < min:
min = inp[i]-inp[i+1]
print(min*n)
| Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the required minimal sum.
Demo Input:
['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n']
Demo Output:
['2\n', '6\n', '12\n', '15\n']
Note:
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | ```python
import sys
n = int(input())
inp = [int(x) for x in input().split()]
inp.sort(reverse=True)
min = sys.maxsize
if len(inp) == 2:
min = inp[0]-inp[1]
else:
for i in range(n-1):
if inp[i]-inp[i+1] < min:
min = inp[i]-inp[i+1]
print(min*n)
``` | 0 |
|
165 | B | Burning Midnight Oil | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ...
The expression is regarded as the integral part from dividing number *a* by number *b*.
The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.
Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep. | The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. | Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. | [
"7 2\n",
"59 9\n"
] | [
"4\n",
"54\n"
] | In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59. | 1,000 | [
{
"input": "7 2",
"output": "4"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "1 9",
"output": "1"
},
{
"input": "11 2",
"output": "7"
},
{
"input": "747 2",
"output": "376"
},
{
"input": "6578 2",
"output": "3293"
},
{
"input": "37212 2",
"output": "18609"
},
{
"input": "12357 2",
"output": "6181"
},
{
"input": "7998332 2",
"output": "3999172"
},
{
"input": "86275251 2",
"output": "43137632"
},
{
"input": "75584551 2",
"output": "37792280"
},
{
"input": "6 3",
"output": "5"
},
{
"input": "43 4",
"output": "33"
},
{
"input": "811 3",
"output": "543"
},
{
"input": "3410 4",
"output": "2560"
},
{
"input": "21341 4",
"output": "16009"
},
{
"input": "696485 4",
"output": "522368"
},
{
"input": "8856748 3",
"output": "5904504"
},
{
"input": "2959379 4",
"output": "2219538"
},
{
"input": "831410263 3",
"output": "554273516"
},
{
"input": "2 5",
"output": "2"
},
{
"input": "19 6",
"output": "17"
},
{
"input": "715 7",
"output": "615"
},
{
"input": "9122 5",
"output": "7300"
},
{
"input": "89117 6",
"output": "74268"
},
{
"input": "689973 7",
"output": "591408"
},
{
"input": "3024524 5",
"output": "2419624"
},
{
"input": "67127156 6",
"output": "55939302"
},
{
"input": "412262167 7",
"output": "353367574"
},
{
"input": "6 8",
"output": "6"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "246 10",
"output": "222"
},
{
"input": "5314 8",
"output": "4651"
},
{
"input": "15309 9",
"output": "13609"
},
{
"input": "35648 10",
"output": "32085"
},
{
"input": "3018012 8",
"output": "2640764"
},
{
"input": "92153348 9",
"output": "81914089"
},
{
"input": "177583558 10",
"output": "159825206"
},
{
"input": "1000000000 2",
"output": "500000008"
},
{
"input": "1000000000 3",
"output": "666666672"
},
{
"input": "1000000000 4",
"output": "750000005"
},
{
"input": "1000000000 5",
"output": "800000003"
},
{
"input": "1000000000 6",
"output": "833333338"
},
{
"input": "1000000000 7",
"output": "857142861"
},
{
"input": "1000000000 8",
"output": "875000004"
},
{
"input": "1000000000 9",
"output": "888888894"
},
{
"input": "1000000000 10",
"output": "900000001"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 10",
"output": "2"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "6 8",
"output": "6"
},
{
"input": "987862820 9",
"output": "878100288"
},
{
"input": "979591791 9",
"output": "870748262"
},
{
"input": "948889213 9",
"output": "843457081"
},
{
"input": "8 9",
"output": "8"
},
{
"input": "999999999 10",
"output": "900000000"
}
] | 1,660,942,127 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | import math
n, k = map(int, input().split())
u = n
l = k
for i in range(10):
mid = (u+l)//2
sol = 0
for i in range(k+1):
sol += math.floor(mid/k**i)
if sol > n:
u = mid
elif sol < n:
l = mid + 1
else:
l = u = mid
print(u)
| Title: Burning Midnight Oil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ...
The expression is regarded as the integral part from dividing number *a* by number *b*.
The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.
Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep.
Input Specification:
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10.
Output Specification:
Print the only integer — the minimum value of *v* that lets Vasya write the program in one night.
Demo Input:
['7 2\n', '59 9\n']
Demo Output:
['4\n', '54\n']
Note:
In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59. | ```python
import math
n, k = map(int, input().split())
u = n
l = k
for i in range(10):
mid = (u+l)//2
sol = 0
for i in range(k+1):
sol += math.floor(mid/k**i)
if sol > n:
u = mid
elif sol < n:
l = mid + 1
else:
l = u = mid
print(u)
``` | 0 |
|
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,696,687,823 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | a, b = map(int, input().split())
# Initialize counters for the three outcomes.
first_player_wins = 0
draw = 0
second_player_wins = 0
# Iterate through all possible outcomes when rolling a die (1 to 6).
for x in range(1, 7):
# Calculate the absolute differences between x and the two chosen numbers.
diff_a = abs(a - x)
diff_b = abs(b - x)
# Determine the outcome and update the corresponding counter.
if diff_a < diff_b:
first_player_wins += 1
elif diff_b < diff_a:
second_player_wins += 1
else:
draw += 1
# Print the results.
print(first_player_wins, draw, second_player_wins)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
a, b = map(int, input().split())
# Initialize counters for the three outcomes.
first_player_wins = 0
draw = 0
second_player_wins = 0
# Iterate through all possible outcomes when rolling a die (1 to 6).
for x in range(1, 7):
# Calculate the absolute differences between x and the two chosen numbers.
diff_a = abs(a - x)
diff_b = abs(b - x)
# Determine the outcome and update the corresponding counter.
if diff_a < diff_b:
first_player_wins += 1
elif diff_b < diff_a:
second_player_wins += 1
else:
draw += 1
# Print the results.
print(first_player_wins, draw, second_player_wins)
``` | 3 |
|
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 1,601,464,055 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 249 | 6,348,800 | from collections import defaultdict
def sexy(a,b):
if len(a)>len(b):
return b
else:
return a
n,m= map(int,input().split())
x=defaultdict(lambda:'z'*26)
for i in range(m):
a,b =input().split()
x[a] = b
y=input().split()
for i in y:
print(sexy(i,x[i]),end=" ")
print() | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input Specification:
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output Specification:
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Demo Input:
['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n']
Demo Output:
['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n']
Note:
none | ```python
from collections import defaultdict
def sexy(a,b):
if len(a)>len(b):
return b
else:
return a
n,m= map(int,input().split())
x=defaultdict(lambda:'z'*26)
for i in range(m):
a,b =input().split()
x[a] = b
y=input().split()
for i in y:
print(sexy(i,x[i]),end=" ")
print()
``` | 3 |
|
73 | A | The Elder Trolls IV: Oblivon | PROGRAMMING | 1,600 | [
"greedy",
"math"
] | A. The Elder Trolls IV: Oblivon | 2 | 256 | Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many!
Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=×<=*y*<=×<=*z*, consisting of undestructable cells 1<=×<=1<=×<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value.
All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut.
Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times.
Vasya's character uses absolutely thin sword with infinite length. | The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109). | Output the only number — the answer for the problem.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"2 2 2 3\n",
"2 2 2 1\n"
] | [
"8",
"2"
] | In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two. | 500 | [
{
"input": "2 2 2 3",
"output": "8"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 3 3",
"output": "6"
},
{
"input": "20 4 5 12",
"output": "120"
},
{
"input": "100 500 100500 1000000000",
"output": "5025000000"
},
{
"input": "2 5 5 9",
"output": "50"
},
{
"input": "11 1 11 11",
"output": "42"
},
{
"input": "100500 5000 500 100000000",
"output": "251250000000"
},
{
"input": "2 2 2 0",
"output": "1"
},
{
"input": "1000000 1000000 1000000 2444441",
"output": "540974149875309150"
},
{
"input": "1000000 1000000 1000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000 1000000 1000000 2999996",
"output": "999999000000000000"
},
{
"input": "1000000 1000000 1000000 2999997",
"output": "1000000000000000000"
},
{
"input": "999999 1000000 999997 999999999",
"output": "999996000003000000"
},
{
"input": "500000 1000000 750000 100000",
"output": "37040370459260"
},
{
"input": "999999 1 999998 1333333",
"output": "444445555556"
},
{
"input": "500000 10000 1000000 29998",
"output": "1000100000000"
},
{
"input": "10000 500000 1000000 29999",
"output": "1000200010000"
},
{
"input": "10000 1000000 500000 29996",
"output": "999900000000"
},
{
"input": "999999 123456 987654 0",
"output": "1"
},
{
"input": "1 1 1 0",
"output": "1"
},
{
"input": "219482 801483 941695 280976",
"output": "821595067700400"
},
{
"input": "808994 288453 204353 580644",
"output": "7250580779648149"
},
{
"input": "428676 64403 677407 626161",
"output": "5081000961597840"
},
{
"input": "559002 326875 150818 157621",
"output": "145045169133102"
},
{
"input": "178008 590076 624581 201286",
"output": "302062187173952"
},
{
"input": "797745 854005 98703 735186",
"output": "9996502351557447"
},
{
"input": "418223 118667 573175 776998",
"output": "12857677898465963"
},
{
"input": "39436 384053 48008 313346",
"output": "427693170156640"
},
{
"input": "661377 149342 523189 353305",
"output": "1633415415004970"
},
{
"input": "781081 414037 495753 892089",
"output": "26294515330164544"
},
{
"input": "402353 679460 969495 930195",
"output": "29810031851367496"
},
{
"input": "593408 709898 624186 915570",
"output": "28425961712082871"
},
{
"input": "1000 988 1000000 3000",
"output": "1002820000"
},
{
"input": "91839 2 3 50",
"output": "288"
},
{
"input": "999900 999990 4 129",
"output": "16384"
},
{
"input": "1024 100000 4 13",
"output": "144"
},
{
"input": "1000000 1000000 1000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1 1000000 1 1000000000",
"output": "1000000"
},
{
"input": "2 1000 1000000 1000000000",
"output": "2000000000"
},
{
"input": "999999 2 1000000 1000000000",
"output": "1999998000000"
},
{
"input": "1000 1 1 1",
"output": "2"
},
{
"input": "1000 1 1 998",
"output": "999"
},
{
"input": "1000 1 1 1000",
"output": "1000"
},
{
"input": "33334 66667 1000000 100000",
"output": "37040370459260"
},
{
"input": "1 1000000 2 23123",
"output": "46246"
}
] | 1,517,429,264 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 5,632,000 | l = input().split(' ')
x = int(l[0])
y = int(l[1])
z = int(l[2])
k = int(l[3])
w = (x+y+z)-3
resp = 1
while w>0 and k>0:
resp *= 2
w -= 1
k -= 1
print(resp) | Title: The Elder Trolls IV: Oblivon
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many!
Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=×<=*y*<=×<=*z*, consisting of undestructable cells 1<=×<=1<=×<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value.
All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut.
Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times.
Vasya's character uses absolutely thin sword with infinite length.
Input Specification:
The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109).
Output Specification:
Output the only number — the answer for the problem.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Demo Input:
['2 2 2 3\n', '2 2 2 1\n']
Demo Output:
['8', '2']
Note:
In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two. | ```python
l = input().split(' ')
x = int(l[0])
y = int(l[1])
z = int(l[2])
k = int(l[3])
w = (x+y+z)-3
resp = 1
while w>0 and k>0:
resp *= 2
w -= 1
k -= 1
print(resp)
``` | 0 |
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.
You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it. | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "7\n.laceon",
"output": "glaceon"
},
{
"input": "7\n..lveon",
"output": "sylveon"
},
{
"input": "7\n.l.ceon",
"output": "glaceon"
},
{
"input": "7\n..areon",
"output": "flareon"
}
] | 1,500,557,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 62 | 5,120,000 | import re
pokemons = ['vaporeon', 'jolteon', 'flareon', 'espeon', 'umbreon', 'leafeon', 'glaceon', 'sylveon']
int(input())
pattern = input()
for word in pokemons:
if re.match(pattern, word):
print(word)
| Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.
You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.
Input Specification:
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Output Specification:
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
Demo Input:
['7\nj......\n', '7\n...feon\n', '7\n.l.r.o.\n']
Demo Output:
['jolteon\n', 'leafeon\n', 'flareon\n']
Note:
Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | ```python
import re
pokemons = ['vaporeon', 'jolteon', 'flareon', 'espeon', 'umbreon', 'leafeon', 'glaceon', 'sylveon']
int(input())
pattern = input()
for word in pokemons:
if re.match(pattern, word):
print(word)
``` | 0 |
|
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111",
"output": "10"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "8\n10101010",
"output": "10000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "3\n111",
"output": "1"
},
{
"input": "5\n11100",
"output": "100"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "3\n110",
"output": "10"
},
{
"input": "50\n10010010000000000000000000000000000000001000000000",
"output": "10000000000000000000000000000000000000000000000"
}
] | 1,681,974,484 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 77 | 0 | input()
s=input()
print(s[0]+'0'*s[1:].count('0'))
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Output Specification:
Print one string — the minimum correct string that you can obtain from the given one.
Demo Input:
['4\n1001\n', '1\n1\n']
Demo Output:
['100\n', '1\n']
Note:
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | ```python
input()
s=input()
print(s[0]+'0'*s[1:].count('0'))
``` | 3 |
|
166 | A | Rank List | PROGRAMMING | 1,100 | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*t**b*.
It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place.
Your task is to count what number of teams from the given list shared the *k*-th place. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
- 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1
The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | 500 | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2",
"output": "1"
},
{
"input": "3 2\n3 3\n3 3\n3 3",
"output": "3"
},
{
"input": "4 3\n10 3\n6 10\n5 2\n5 2",
"output": "2"
},
{
"input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3",
"output": "3"
},
{
"input": "3 1\n2 1\n1 1\n1 2",
"output": "1"
},
{
"input": "1 1\n28 28",
"output": "1"
},
{
"input": "2 2\n1 2\n1 2",
"output": "2"
},
{
"input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5",
"output": "1"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8",
"output": "1"
},
{
"input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10",
"output": "1"
},
{
"input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "50"
},
{
"input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2",
"output": "13"
},
{
"input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2",
"output": "5"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3",
"output": "1"
},
{
"input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2",
"output": "1"
},
{
"input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6",
"output": "1"
},
{
"input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1",
"output": "3"
},
{
"input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "20"
},
{
"input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2",
"output": "6"
},
{
"input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "30"
},
{
"input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1",
"output": "13"
},
{
"input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1",
"output": "5"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3",
"output": "1"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8",
"output": "1"
},
{
"input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14",
"output": "1"
},
{
"input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30",
"output": "2"
},
{
"input": "2 1\n50 50\n50 50",
"output": "2"
},
{
"input": "2 2\n50 50\n50 50",
"output": "2"
},
{
"input": "2 1\n50 50\n50 49",
"output": "1"
},
{
"input": "2 2\n50 50\n50 49",
"output": "1"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50",
"output": "50"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50",
"output": "1"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49",
"output": "49"
},
{
"input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4",
"output": "1"
},
{
"input": "4 3\n1 1\n1 2\n2 1\n2 2",
"output": "1"
},
{
"input": "4 2\n1 2\n1 3\n1 5\n1 2",
"output": "2"
},
{
"input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3",
"output": "1"
},
{
"input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1",
"output": "2"
},
{
"input": "3 1\n1 1\n1 2\n1 3",
"output": "1"
},
{
"input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4",
"output": "4"
},
{
"input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5",
"output": "2"
},
{
"input": "4 1\n1 1\n1 1\n1 2\n1 3",
"output": "2"
}
] | 1,693,841,945 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 12 | 124 | 0 | n, k = map(int, input().split())
l = []
for x in range (n):
p, t = map(int, input().split())
l.append((p,t))
l.sort(reverse = True)
print(l.count(l[k-1])) | Title: Rank List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*t**b*.
It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place.
Your task is to count what number of teams from the given list shared the *k*-th place.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
Output Specification:
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
Demo Input:
['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n']
Demo Output:
['3\n', '4\n']
Note:
The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
- 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1
The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | ```python
n, k = map(int, input().split())
l = []
for x in range (n):
p, t = map(int, input().split())
l.append((p,t))
l.sort(reverse = True)
print(l.count(l[k-1]))
``` | 0 |
|
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
"output": "18"
},
{
"input": "z\na",
"output": "2"
},
{
"input": "ama\nsama",
"output": "1"
},
{
"input": "aaabc\nbc",
"output": "3"
},
{
"input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa",
"output": "32"
},
{
"input": "ahmedaly\naly",
"output": "5"
},
{
"input": "aa\na",
"output": "1"
},
{
"input": "aa\nba",
"output": "2"
},
{
"input": "cccba\nba",
"output": "3"
},
{
"input": "a\nab",
"output": "3"
},
{
"input": "dadc\ndddc",
"output": "4"
},
{
"input": "aacaaab\nb",
"output": "6"
},
{
"input": "dddc\ncdcde",
"output": "9"
},
{
"input": "bbdab\ndab",
"output": "2"
},
{
"input": "a\naa",
"output": "1"
},
{
"input": "aa\nab",
"output": "4"
},
{
"input": "codeforces\nces",
"output": "7"
}
] | 1,640,061,724 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 186 | 716,800 | a = input()
b = input()
w = 0
while True:
i = len(a) - w - 1
j = len(b) - w - 1
if i >= 0 and j >= 0 and a[i] == b[j]:
w += 1
else:
break
print(len(a) + len(b) - 2 * w) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
Input Specification:
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output Specification:
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
Demo Input:
['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n']
Demo Output:
['2\n', '9\n', '7\n', '1\n']
Note:
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | ```python
a = input()
b = input()
w = 0
while True:
i = len(a) - w - 1
j = len(b) - w - 1
if i >= 0 and j >= 0 and a[i] == b[j]:
w += 1
else:
break
print(len(a) + len(b) - 2 * w)
``` | 3 |
|
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach *x*. | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"input": "999961559",
"output": "44721"
},
{
"input": "-488979819",
"output": "31273"
},
{
"input": "-865918189",
"output": "41617"
},
{
"input": "-278253406",
"output": "23591"
},
{
"input": "-87275307",
"output": "13213"
},
{
"input": "103702792",
"output": "14403"
},
{
"input": "294680891",
"output": "24277"
},
{
"input": "485658989",
"output": "31166"
},
{
"input": "676637088",
"output": "36787"
},
{
"input": "867615187",
"output": "41657"
},
{
"input": "-941406715",
"output": "43393"
},
{
"input": "-897912263",
"output": "42377"
},
{
"input": "-706934164",
"output": "37603"
},
{
"input": "-790244010",
"output": "39755"
},
{
"input": "16417015",
"output": "5730"
},
{
"input": "823078041",
"output": "40573"
},
{
"input": "-517744582",
"output": "32179"
},
{
"input": "288916443",
"output": "24038"
},
{
"input": "-904422532",
"output": "42531"
},
{
"input": "-245245154",
"output": "22147"
},
{
"input": "561415872",
"output": "33511"
},
{
"input": "-779406751",
"output": "39482"
},
{
"input": "27254274",
"output": "7383"
},
{
"input": "845249034",
"output": "41116"
}
] | 1,643,451,912 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a = int(input())
s=0
while i < a:
s = s + 1
if i < a:
i = i + s
print (s) | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach *x*.
Input Specification:
The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109).
Output Specification:
Output the minimal number of jumps that Jack requires to reach *x*.
Demo Input:
['2\n', '6\n', '0\n']
Demo Output:
['3\n', '3\n', '0\n']
Note:
none | ```python
a = int(input())
s=0
while i < a:
s = s + 1
if i < a:
i = i + s
print (s)
``` | -1 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task. | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": ".g.g.d.v.q"
},
{
"input": "pumesz",
"output": ".p.m.s.z"
},
{
"input": "g",
"output": ".g"
},
{
"input": "zjuotps",
"output": ".z.j.t.p.s"
},
{
"input": "jzbwuehe",
"output": ".j.z.b.w.h"
},
{
"input": "tnkgwuugu",
"output": ".t.n.k.g.w.g"
},
{
"input": "kincenvizh",
"output": ".k.n.c.n.v.z.h"
},
{
"input": "xattxjenual",
"output": ".x.t.t.x.j.n.l"
},
{
"input": "ktajqhpqsvhw",
"output": ".k.t.j.q.h.p.q.s.v.h.w"
},
{
"input": "xnhcigytnqcmy",
"output": ".x.n.h.c.g.t.n.q.c.m"
},
{
"input": "jfmtbejyilxcec",
"output": ".j.f.m.t.b.j.l.x.c.c"
},
{
"input": "D",
"output": ".d"
},
{
"input": "ab",
"output": ".b"
},
{
"input": "Ab",
"output": ".b"
},
{
"input": "aB",
"output": ".b"
},
{
"input": "AB",
"output": ".b"
},
{
"input": "ba",
"output": ".b"
},
{
"input": "bA",
"output": ".b"
},
{
"input": "Ba",
"output": ".b"
},
{
"input": "BA",
"output": ".b"
},
{
"input": "aab",
"output": ".b"
},
{
"input": "baa",
"output": ".b"
},
{
"input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM",
"output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m"
},
{
"input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN",
"output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n"
},
{
"input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ",
"output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j"
},
{
"input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea",
"output": ".w.z.t.c.v.v.v.v.z.v"
},
{
"input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl",
"output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l"
},
{
"input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg",
"output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g"
},
{
"input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ",
"output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q"
},
{
"input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg",
"output": ".l.t.g.m.g"
},
{
"input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy",
"output": ".k.z.d.x.f"
},
{
"input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ",
"output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q"
},
{
"input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY",
"output": ".m.r.c.g.p"
},
{
"input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx",
"output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x"
},
{
"input": "YB",
"output": ".b"
},
{
"input": "fly",
"output": ".f.l"
},
{
"input": "YyyYYYyyYxdwdawdDAWDdaddYYYY",
"output": ".x.d.w.d.w.d.d.w.d.d.d.d"
}
] | 1,693,499,234 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | def StringTask(s):
vowels = "AEIOUYaeiouy"
result = []
for char in s:
if char not in vowels:
result.append('.')
result.append(char.lower())
return ''.join(result)
s = input()
res = StringTask(s)
print(res)
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
Input Specification:
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Output Specification:
Print the resulting string. It is guaranteed that this string is not empty.
Demo Input:
['tour\n', 'Codeforces\n', 'aBAcAba\n']
Demo Output:
['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n']
Note:
none | ```python
def StringTask(s):
vowels = "AEIOUYaeiouy"
result = []
for char in s:
if char not in vowels:
result.append('.')
result.append(char.lower())
return ''.join(result)
s = input()
res = StringTask(s)
print(res)
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,574,341,039 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 0 | n=int(input())
result=[0,0,0]
for i in range(n):
force=input().split()
result[0]+=int(force[0])
result[1]+=int(force[1])
result[2]+=int(force[2])
print(result)
if result[0]==0 and result[1]==0 and result[2]==0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n=int(input())
result=[0,0,0]
for i in range(n):
force=input().split()
result[0]+=int(force[0])
result[1]+=int(force[1])
result[2]+=int(force[2])
print(result)
if result[0]==0 and result[1]==0 and result[2]==0:
print('YES')
else:
print('NO')
``` | 0 |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball? | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n0",
"output": "1"
},
{
"input": "2\n0",
"output": "1"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "4\n0",
"output": "2"
},
{
"input": "4\n1",
"output": "0"
},
{
"input": "5\n0",
"output": "0"
},
{
"input": "5\n1",
"output": "2"
},
{
"input": "5\n2",
"output": "1"
},
{
"input": "6\n0",
"output": "0"
},
{
"input": "6\n1",
"output": "1"
},
{
"input": "6\n2",
"output": "2"
},
{
"input": "7\n0",
"output": "1"
},
{
"input": "7\n1",
"output": "0"
},
{
"input": "7\n2",
"output": "2"
},
{
"input": "100000\n0",
"output": "2"
},
{
"input": "100000\n1",
"output": "0"
},
{
"input": "100000\n2",
"output": "1"
},
{
"input": "99999\n1",
"output": "1"
},
{
"input": "99998\n1",
"output": "2"
},
{
"input": "99997\n1",
"output": "0"
},
{
"input": "99996\n1",
"output": "1"
},
{
"input": "99995\n1",
"output": "2"
},
{
"input": "1999999995\n0",
"output": "2"
},
{
"input": "1999999995\n1",
"output": "1"
},
{
"input": "1999999995\n2",
"output": "0"
},
{
"input": "1999999996\n0",
"output": "2"
},
{
"input": "1999999996\n1",
"output": "0"
},
{
"input": "1999999996\n2",
"output": "1"
},
{
"input": "1999999997\n0",
"output": "0"
},
{
"input": "1999999997\n1",
"output": "2"
},
{
"input": "1999999997\n2",
"output": "1"
},
{
"input": "1999999998\n0",
"output": "0"
},
{
"input": "1999999998\n1",
"output": "1"
},
{
"input": "1999999998\n2",
"output": "2"
},
{
"input": "1999999999\n0",
"output": "1"
},
{
"input": "1999999999\n1",
"output": "0"
},
{
"input": "1999999999\n2",
"output": "2"
},
{
"input": "2000000000\n1",
"output": "2"
},
{
"input": "2000000000\n2",
"output": "0"
},
{
"input": "1234567890\n0",
"output": "0"
},
{
"input": "1234567890\n1",
"output": "1"
},
{
"input": "1234567890\n2",
"output": "2"
},
{
"input": "123456789\n0",
"output": "2"
},
{
"input": "123456789\n1",
"output": "1"
},
{
"input": "123456789\n2",
"output": "0"
},
{
"input": "123456790\n0",
"output": "2"
},
{
"input": "12\n2",
"output": "2"
},
{
"input": "32\n1",
"output": "2"
},
{
"input": "20\n2",
"output": "0"
},
{
"input": "10\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "76994383\n1",
"output": "0"
},
{
"input": "25\n2",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "12\n0",
"output": "0"
},
{
"input": "150\n2",
"output": "2"
},
{
"input": "15\n0",
"output": "2"
},
{
"input": "21\n2",
"output": "0"
},
{
"input": "18\n2",
"output": "2"
},
{
"input": "8\n2",
"output": "0"
},
{
"input": "10\n0",
"output": "2"
},
{
"input": "16\n0",
"output": "2"
}
] | 1,488,453,343 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 62 | 4,608,000 | n=int(input())
n%=6
a=[0,1,2]
for i in range(n):
if i%2==0:
a[0],a[1]=a[1],a[0]
else:
a[1],a[2]=a[2],a[1]
print(a[int(input())]) | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball?
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Output Specification:
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Demo Input:
['4\n2\n', '1\n1\n']
Demo Output:
['1\n', '0\n']
Note:
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | ```python
n=int(input())
n%=6
a=[0,1,2]
for i in range(n):
if i%2==0:
a[0],a[1]=a[1],a[0]
else:
a[1],a[2]=a[2],a[1]
print(a[int(input())])
``` | 3 |
|
475 | B | Strongly Connected City | PROGRAMMING | 1,400 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern. | The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east. | If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". | [
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] | [
"NO\n",
"YES\n"
] | The figure above shows street directions in the second sample test case. | 1,000 | [
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>><\n^v^v",
"output": "YES"
},
{
"input": "3 8\n>><\nv^^^^^^^",
"output": "NO"
},
{
"input": "7 2\n<><<<<>\n^^",
"output": "NO"
},
{
"input": "4 5\n><<<\n^^^^v",
"output": "YES"
},
{
"input": "2 20\n><\n^v^^v^^v^^^v^vv^vv^^",
"output": "NO"
},
{
"input": "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^",
"output": "YES"
},
{
"input": "20 2\n<><<><<>><<<>><><<<<\n^^",
"output": "NO"
},
{
"input": "20 2\n><>><>><>><<<><<><><\n^v",
"output": "YES"
},
{
"input": "11 12\n><<<><><<>>\nvv^^^^vvvvv^",
"output": "NO"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "16 11\n<<<<>><><<<<<><<\nvv^v^vvvv^v",
"output": "NO"
},
{
"input": "14 7\n><<<<>>>>>>><<\nvv^^^vv",
"output": "NO"
},
{
"input": "5 14\n<<><>\nv^vv^^vv^v^^^v",
"output": "NO"
},
{
"input": "8 18\n>>>><>>>\nv^vv^v^^^^^vvv^^vv",
"output": "NO"
},
{
"input": "18 18\n<<><>><<>><>><><<<\n^^v^v^vvvv^v^vv^vv",
"output": "NO"
},
{
"input": "4 18\n<<<>\n^^^^^vv^vv^^vv^v^v",
"output": "NO"
},
{
"input": "19 18\n><><>>><<<<<>>><<<>\n^^v^^v^^v^vv^v^vvv",
"output": "NO"
},
{
"input": "14 20\n<<<><><<>><><<\nvvvvvvv^v^vvvv^^^vv^",
"output": "NO"
},
{
"input": "18 18\n><>>><<<>><><>>>><\nvv^^^^v^v^^^^v^v^^",
"output": "NO"
},
{
"input": "8 18\n<><<<>>>\n^^^^^^v^^^vv^^vvvv",
"output": "NO"
},
{
"input": "11 12\n><><><<><><\n^^v^^^^^^^^v",
"output": "YES"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "16 11\n>><<><<<<>>><><<\n^^^^vvvv^vv",
"output": "YES"
},
{
"input": "14 7\n<><><<<>>>><>>\nvv^^v^^",
"output": "YES"
},
{
"input": "5 14\n>>>><\n^v^v^^^vv^vv^v",
"output": "YES"
},
{
"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^",
"output": "YES"
},
{
"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v",
"output": "YES"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "19 18\n>>>><><<>>><<<><<<<\n^v^^^^vv^^v^^^^v^v",
"output": "YES"
},
{
"input": "14 20\n<>><<<><<>>>>>\nvv^^v^^^^v^^vv^^vvv^",
"output": "YES"
},
{
"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v",
"output": "YES"
},
{
"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^",
"output": "YES"
},
{
"input": "20 19\n<><>>>>><<<<<><<>>>>\nv^vv^^vvvvvv^vvvv^v",
"output": "NO"
},
{
"input": "20 19\n<<<><<<>><<<>><><><>\nv^v^vvv^vvv^^^vvv^^",
"output": "YES"
},
{
"input": "19 20\n<><<<><><><<<<<<<<>\n^v^^^^v^^vvvv^^^^vvv",
"output": "NO"
},
{
"input": "19 20\n>>>>>>>><>>><><<<><\n^v^v^^^vvv^^^v^^vvvv",
"output": "YES"
},
{
"input": "20 20\n<<<>>>><>><<>><<>>>>\n^vvv^^^^vv^^^^^v^^vv",
"output": "NO"
},
{
"input": "20 20\n>>><><<><<<<<<<><<><\nvv^vv^vv^^^^^vv^^^^^",
"output": "NO"
},
{
"input": "20 20\n><<><<<<<<<>>><>>><<\n^^^^^^^^vvvv^vv^vvvv",
"output": "YES"
},
{
"input": "20 20\n<>>>>>>>><>>><>><<<>\nvv^^vv^^^^v^vv^v^^^^",
"output": "YES"
},
{
"input": "20 20\n><>><<>><>>>>>>>><<>\n^^v^vv^^^vvv^v^^^vv^",
"output": "NO"
},
{
"input": "20 20\n<<<<><<>><><<<>><<><\nv^^^^vvv^^^vvvv^v^vv",
"output": "NO"
},
{
"input": "20 20\n><<<><<><>>><><<<<<<\nvv^^vvv^^v^^v^vv^vvv",
"output": "NO"
},
{
"input": "20 20\n<<>>><>>>><<<<>>><<>\nv^vv^^^^^vvv^^v^^v^v",
"output": "NO"
},
{
"input": "20 20\n><<><<><<<<<<>><><>>\nv^^^v^vv^^v^^vvvv^vv",
"output": "NO"
},
{
"input": "20 20\n<<<<<<<<><>><><>><<<\n^vvv^^^v^^^vvv^^^^^v",
"output": "NO"
},
{
"input": "20 20\n>>><<<<<>>><><><<><<\n^^^vvv^^^v^^v^^v^vvv",
"output": "YES"
},
{
"input": "20 20\n<><<<><><>><><><<<<>\n^^^vvvv^vv^v^^^^v^vv",
"output": "NO"
},
{
"input": "20 20\n>>>>>>>>>><>>><>><>>\n^vvv^^^vv^^^^^^vvv^v",
"output": "NO"
},
{
"input": "20 20\n<><>><><<<<<>><<>>><\nv^^^v^v^v^vvvv^^^vv^",
"output": "NO"
},
{
"input": "20 20\n><<<><<<><<<><>>>><<\nvvvv^^^^^vv^v^^vv^v^",
"output": "NO"
},
{
"input": "20 20\n<<><<<<<<>>>>><<<>>>\nvvvvvv^v^vvv^^^^^^^^",
"output": "YES"
},
{
"input": "20 20\n><<><<>>>>><><>><>>>\nv^^^^vvv^^^^^v^v^vv^",
"output": "NO"
},
{
"input": "20 20\n<<>>><>><<>>>><<<><<\n^^vvv^^vvvv^vv^^v^v^",
"output": "NO"
},
{
"input": "20 20\n><<>><>>>><<><>><><<\n^v^^^^^^vvvv^v^v^v^^",
"output": "NO"
},
{
"input": "20 20\n<<><<<<><><<>>><>>>>\n^^vvvvv^v^^^^^^^vvv^",
"output": "NO"
},
{
"input": "20 20\n>><<<<<<><>>>><>>><>\n^^^v^v^vv^^vv^vvv^^^",
"output": "NO"
},
{
"input": "20 20\n>>>>>>>>>>>>>>>>>>>>\nvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "2 2\n><\nv^",
"output": "NO"
},
{
"input": "2 2\n<>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\nvvv",
"output": "NO"
},
{
"input": "2 3\n<>\nv^^",
"output": "YES"
},
{
"input": "4 4\n>>><\nvvv^",
"output": "NO"
},
{
"input": "20 20\n<><><><><><><><><><>\nvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "4 4\n<>>>\nv^^^",
"output": "YES"
},
{
"input": "20 20\n<><><><><><><><><><>\nv^v^v^v^v^v^v^v^v^v^",
"output": "YES"
},
{
"input": "2 3\n<>\n^v^",
"output": "NO"
},
{
"input": "4 3\n<><>\n^vv",
"output": "NO"
},
{
"input": "3 3\n<<>\nvv^",
"output": "YES"
},
{
"input": "2 3\n><\nvv^",
"output": "NO"
},
{
"input": "7 6\n>>><>><\n^vv^vv",
"output": "YES"
},
{
"input": "2 2\n<<\nv^",
"output": "NO"
},
{
"input": "3 3\n>><\n^^^",
"output": "NO"
},
{
"input": "3 3\n<><\nv^v",
"output": "NO"
},
{
"input": "20 20\n><><><><><><><><><><\n^v^v^v^v^v^v^v^v^v^v",
"output": "YES"
},
{
"input": "4 4\n<>>>\nvvv^",
"output": "YES"
}
] | 1,527,840,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 7,065,600 | h,v=list(map(int,input().split()))
print('YES') if 1-h%2 and 1-v%2 else print('NO')
| Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
Input Specification:
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
Output Specification:
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
Demo Input:
['3 3\n><>\nv^v\n', '4 6\n<><>\nv^v^v^\n']
Demo Output:
['NO\n', 'YES\n']
Note:
The figure above shows street directions in the second sample test case. | ```python
h,v=list(map(int,input().split()))
print('YES') if 1-h%2 and 1-v%2 else print('NO')
``` | 0 |
|
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*. | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "100 0",
"output": "100"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "160 2",
"output": "800"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "3 1",
"output": "30"
},
{
"input": "4 1",
"output": "20"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "6 1",
"output": "30"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "8 1",
"output": "40"
},
{
"input": "9 1",
"output": "90"
},
{
"input": "10 1",
"output": "10"
},
{
"input": "11 1",
"output": "110"
},
{
"input": "12 1",
"output": "60"
},
{
"input": "16 2",
"output": "400"
},
{
"input": "2 2",
"output": "100"
},
{
"input": "1 2",
"output": "100"
},
{
"input": "5 2",
"output": "100"
},
{
"input": "15 2",
"output": "300"
},
{
"input": "36 2",
"output": "900"
},
{
"input": "1 8",
"output": "100000000"
},
{
"input": "8 8",
"output": "100000000"
},
{
"input": "96 8",
"output": "300000000"
},
{
"input": "175 8",
"output": "700000000"
},
{
"input": "9999995 8",
"output": "199999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "12345678 8",
"output": "617283900000000"
},
{
"input": "78125 8",
"output": "100000000"
},
{
"input": "390625 8",
"output": "100000000"
},
{
"input": "1953125 8",
"output": "500000000"
},
{
"input": "9765625 8",
"output": "2500000000"
},
{
"input": "68359375 8",
"output": "17500000000"
},
{
"input": "268435456 8",
"output": "104857600000000"
},
{
"input": "125829120 8",
"output": "9830400000000"
},
{
"input": "128000 8",
"output": "400000000"
},
{
"input": "300000 8",
"output": "300000000"
},
{
"input": "3711871 8",
"output": "371187100000000"
},
{
"input": "55555 8",
"output": "1111100000000"
},
{
"input": "222222222 8",
"output": "11111111100000000"
},
{
"input": "479001600 8",
"output": "7484400000000"
},
{
"input": "655360001 7",
"output": "6553600010000000"
},
{
"input": "655360001 8",
"output": "65536000100000000"
},
{
"input": "1000000000 1",
"output": "1000000000"
},
{
"input": "1000000000 7",
"output": "1000000000"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "10000000 8",
"output": "100000000"
},
{
"input": "1000000 8",
"output": "100000000"
},
{
"input": "10000009 8",
"output": "1000000900000000"
},
{
"input": "10000005 8",
"output": "200000100000000"
},
{
"input": "10000002 8",
"output": "500000100000000"
},
{
"input": "999999997 8",
"output": "99999999700000000"
},
{
"input": "999999997 7",
"output": "9999999970000000"
},
{
"input": "999999995 8",
"output": "19999999900000000"
},
{
"input": "123 8",
"output": "12300000000"
},
{
"input": "24 2",
"output": "600"
},
{
"input": "16 4",
"output": "10000"
},
{
"input": "123456787 8",
"output": "12345678700000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "101 1",
"output": "1010"
},
{
"input": "50 2",
"output": "100"
},
{
"input": "999999818 1",
"output": "4999999090"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "123 1",
"output": "1230"
},
{
"input": "16 1",
"output": "80"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "15304 6",
"output": "1913000000"
},
{
"input": "3 8",
"output": "300000000"
},
{
"input": "4 2",
"output": "100"
},
{
"input": "100000 7",
"output": "10000000"
},
{
"input": "5 8",
"output": "100000000"
},
{
"input": "16724 6",
"output": "4181000000"
},
{
"input": "999999999 1",
"output": "9999999990"
},
{
"input": "999999990 8",
"output": "9999999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "100000 1",
"output": "100000"
},
{
"input": "8 3",
"output": "1000"
},
{
"input": "16768 6",
"output": "262000000"
},
{
"input": "123456789 1",
"output": "1234567890"
},
{
"input": "2 8",
"output": "100000000"
},
{
"input": "999999937 8",
"output": "99999993700000000"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "2000000 7",
"output": "10000000"
},
{
"input": "1999998 2",
"output": "99999900"
},
{
"input": "125 3",
"output": "1000"
}
] | 1,621,142,531 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 108 | 0 | # A. k-rounding
import math
n, k = map(int,input().split())
print(n*10**k//math.gcd(n,10**k)) | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Output Specification:
Print the *k*-rounding of *n*.
Demo Input:
['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n']
Demo Output:
['30000\n', '10000\n', '38101\n', '12345678900000000\n']
Note:
none | ```python
# A. k-rounding
import math
n, k = map(int,input().split())
print(n*10**k//math.gcd(n,10**k))
``` | 3 |
|
557 | C | Arthur and Table | PROGRAMMING | 1,900 | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | null | null | Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg.
A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table. | Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. | [
"2\n1 5\n3 2\n",
"3\n2 4 4\n1 1 1\n",
"6\n2 2 1 1 3 3\n4 3 5 5 2 1\n"
] | [
"2\n",
"0\n",
"8\n"
] | none | 1,500 | [
{
"input": "2\n1 5\n3 2",
"output": "2"
},
{
"input": "3\n2 4 4\n1 1 1",
"output": "0"
},
{
"input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1",
"output": "8"
},
{
"input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146",
"output": "652"
},
{
"input": "10\n15 16 19 5 14 19 6 17 7 19\n140 183 186 195 67 25 70 56 54 132",
"output": "387"
},
{
"input": "20\n24 15 7 18 6 18 11 22 18 20 28 8 23 17 22 22 23 23 30 23\n24 137 173 189 43 164 2 11 142 153 16 200 53 58 150 199 169 172 38 78",
"output": "1111"
},
{
"input": "30\n20 27 26 17 29 9 25 13 6 21 15 1 14 22 26 2 15 18 20 23 27 9 15 29 11 2 19 23 14 12\n133 199 22 151 9 134 196 119 197 189 117 84 156 6 61 195 98 197 145 75 142 85 187 24 159 3 60 138 156 161",
"output": "2804"
},
{
"input": "5\n1 1 2 2 3\n2 2 2 2 3",
"output": "5"
},
{
"input": "5\n1 1 2 2 3\n2 2 2 2 7",
"output": "8"
},
{
"input": "10\n1 1 3 4 5 6 7 8 9 10\n10 10 4 2 3 4 2 2 2 2",
"output": "21"
},
{
"input": "1\n5\n4",
"output": "0"
},
{
"input": "2\n3 3\n4 5",
"output": "0"
},
{
"input": "2\n4 5\n3 3",
"output": "3"
},
{
"input": "3\n3 3 3\n1 2 3",
"output": "0"
},
{
"input": "3\n1 2 3\n3 3 3",
"output": "6"
}
] | 1,435,956,242 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 327 | 9,830,400 |
n = int(input())
lengths = list(map(int, input().split()))
costs = list(map(int, input().split()))
sum = 0
length_to_sum = {}
length_to_count = {}
cost_to_lengths = {}
for i in range(n):
length, cost = lengths[i], costs[i]
sum += cost
length_to_sum[length] = length_to_sum.setdefault(length, 0) + cost
length_to_count[length] = length_to_count.setdefault(length, 0) + 1
cost_to_lengths.setdefault(cost, []).append(length)
length_set = set(lengths)
for lengths in cost_to_lengths.values():
lengths.sort()
unique_costs = list(reversed(sorted(cost_to_lengths.keys())))
best = -1
for length in length_set:
total = sum - length_to_sum[length]
seek = length_to_count[length] - 1
if seek != 0:
for cost in unique_costs:
for x in cost_to_lengths[cost]:
if x >= length:
break
total -= cost
seek -= 1
if seek == 0:
break
if seek == 0:
break
if best == -1 or total < best:
best = total
print(best)
| Title: Arthur and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg.
A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table.
Output Specification:
Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.
Demo Input:
['2\n1 5\n3 2\n', '3\n2 4 4\n1 1 1\n', '6\n2 2 1 1 3 3\n4 3 5 5 2 1\n']
Demo Output:
['2\n', '0\n', '8\n']
Note:
none | ```python
n = int(input())
lengths = list(map(int, input().split()))
costs = list(map(int, input().split()))
sum = 0
length_to_sum = {}
length_to_count = {}
cost_to_lengths = {}
for i in range(n):
length, cost = lengths[i], costs[i]
sum += cost
length_to_sum[length] = length_to_sum.setdefault(length, 0) + cost
length_to_count[length] = length_to_count.setdefault(length, 0) + 1
cost_to_lengths.setdefault(cost, []).append(length)
length_set = set(lengths)
for lengths in cost_to_lengths.values():
lengths.sort()
unique_costs = list(reversed(sorted(cost_to_lengths.keys())))
best = -1
for length in length_set:
total = sum - length_to_sum[length]
seek = length_to_count[length] - 1
if seek != 0:
for cost in unique_costs:
for x in cost_to_lengths[cost]:
if x >= length:
break
total -= cost
seek -= 1
if seek == 0:
break
if seek == 0:
break
if best == -1 or total < best:
best = total
print(best)
``` | 3 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,699,192,508 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 92 | 0 | xx=input()
xw=xx.replace(" ","")
ppp=xw.replace("{","")
ppx=ppp.replace("}","")
pxx=ppx.replace(",","")
pp=set(pxx)
ww=len(pp)
print(ww) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
xx=input()
xw=xx.replace(" ","")
ppp=xw.replace("{","")
ppx=ppp.replace("}","")
pxx=ppx.replace(",","")
pp=set(pxx)
ww=len(pp)
print(ww)
``` | 3 |
|
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times.
The operation of changing a number's sign is the operation of multiplying this number by -1.
Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5253 -5041 -5000 -4951 -4855 -4384 -4293 -4251 -4001 -3991 -3762 -3544 -3481 -3261 -2983 -2882 -2857 -2713 -2691 -2681 -2653 -2221 -2043 -2011 -1997 -1601 -1471 -1448 -1363 -1217 -1217 -1129 -961 -926 -801 -376 -327 -305 -174 -91",
"output": "102443"
},
{
"input": "12 28\n-6652 -6621 -6471 -5559 -5326 -4551 -4401 -4326 -3294 -1175 -1069 -43",
"output": "49488"
},
{
"input": "78 13\n-9961 -9922 -9817 -9813 -9521 -9368 -9361 -9207 -9153 -9124 -9008 -8981 -8951 -8911 -8551 -8479 -8245 -8216 -7988 -7841 -7748 -7741 -7734 -7101 -6846 -6804 -6651 -6526 -6519 -6463 -6297 -6148 -6090 -5845 -5209 -5201 -5161 -5061 -4537 -4529 -4433 -4370 -4266 -4189 -4125 -3945 -3843 -3777 -3751 -3476 -3461 -3279 -3205 -3001 -2889 -2761 -2661 -2521 -2481 -2305 -2278 -2269 -2225 -1648 -1524 -1476 -1353 -1097 -867 -785 -741 -711 -692 -440 -401 -225 -65 -41",
"output": "-147832"
},
{
"input": "4 1\n218 3441 4901 7601",
"output": "15725"
},
{
"input": "73 26\n-8497 -8363 -7603 -7388 -6830 -6827 -6685 -6389 -6237 -6099 -6013 -5565 -5465 -4965 -4947 -4201 -3851 -3793 -3421 -3410 -3201 -3169 -3156 -2976 -2701 -2623 -2321 -2169 -1469 -1221 -950 -926 -9 47 236 457 773 1321 1485 1545 1671 1736 2014 2137 2174 2301 2625 3181 3536 3851 4041 4685 4981 4987 5145 5163 5209 5249 6011 6337 6790 7254 7361 7407 7969 7982 8083 8251 8407 8735 9660 9855 9957",
"output": "315919"
},
{
"input": "53 5\n-9821 -9429 -9146 -8973 -8807 -8801 -8321 -7361 -7222 -7161 -6913 -5961 -4877 -4756 -4753 -4661 -3375 -3031 -2950 -2661 -2161 -2041 -1111 -1071 -905 -697 -397 323 772 1617 1752 2736 2737 3201 3465 4029 4121 4463 4561 4637 4814 6119 6610 6641 6961 7217 7523 8045 8610 8915 9004 9265 9576",
"output": "92703"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n10000",
"output": "-10000"
},
{
"input": "1 2\n-1",
"output": "-1"
},
{
"input": "2 1\n0 1",
"output": "1"
},
{
"input": "2 2\n-1 0",
"output": "1"
},
{
"input": "5 6\n-3 -2 -1 5 6",
"output": "15"
},
{
"input": "3 3\n-50 -10 30",
"output": "70"
},
{
"input": "4 4\n-100 -90 -80 1",
"output": "269"
},
{
"input": "4 3\n-3 -2 1 2",
"output": "6"
},
{
"input": "6 4\n-6 -3 -2 1 2 3",
"output": "15"
},
{
"input": "5 6\n-10 -9 -8 1 2",
"output": "28"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "2 2\n-1 3",
"output": "2"
},
{
"input": "4 7\n-3 -2 1 6",
"output": "10"
},
{
"input": "4 3\n-7 -6 1 5",
"output": "17"
},
{
"input": "4 4\n-5 -1 1 2",
"output": "9"
}
] | 1,569,686,164 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 44 | 280 | 7,372,800 | #!/usr/bin/env python3
def main():
n, k = map(int, input().split())
inc = list(map(int, input().split()))
b = sum(1 for i in inc if i < 0)
op = abs(k-b) + (1 if b else 0)
if op & 1:
ans = -inc[0]
inc[0] = 0
else:
ans = inc[max(0,b-1)]
inc[max(0,b-1)] = 0
ans += sum(map(lambda x: -x, inc[0:min(b, k)]))
ans += sum(inc[min(b,k):])
print(ans)
if __name__ == "__main__":
main()
| Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times.
The operation of changing a number's sign is the operation of multiplying this number by -1.
Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
Output Specification:
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
Demo Input:
['3 2\n-1 -1 1\n', '3 1\n-1 -1 1\n']
Demo Output:
['3\n', '1\n']
Note:
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | ```python
#!/usr/bin/env python3
def main():
n, k = map(int, input().split())
inc = list(map(int, input().split()))
b = sum(1 for i in inc if i < 0)
op = abs(k-b) + (1 if b else 0)
if op & 1:
ans = -inc[0]
inc[0] = 0
else:
ans = inc[max(0,b-1)]
inc[max(0,b-1)] = 0
ans += sum(map(lambda x: -x, inc[0:min(b, k)]))
ans += sum(inc[min(b,k):])
print(ans)
if __name__ == "__main__":
main()
``` | 0 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,696,442,496 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | #panagram
n=int(input())
s=input()[:n]
alphabet='abcdefghijklmnopqrstuvwxyz'
s=s.lower()
t=1
for i in alphabet:
if i not in s:
t=0
break
if t==1:
print('YES')
else:
print("NO")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
#panagram
n=int(input())
s=input()[:n]
alphabet='abcdefghijklmnopqrstuvwxyz'
s=s.lower()
t=1
for i in alphabet:
if i not in s:
t=0
break
if t==1:
print('YES')
else:
print("NO")
``` | 3 |
|
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,680,529,809 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | r, c = map(int, input().split())
for i in range(1, r+1):
if i % 2 != 0:
print("#"*c)
continue
elif i %2 == 0 and (i % 4) != 0:
print("."*(c-1)+"#")
continue
elif i % 4 == 0:
print("#"+"."*(c-1)) | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none | ```python
r, c = map(int, input().split())
for i in range(1, r+1):
if i % 2 != 0:
print("#"*c)
continue
elif i %2 == 0 and (i % 4) != 0:
print("."*(c-1)+"#")
continue
elif i % 4 == 0:
print("#"+"."*(c-1))
``` | 3 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,688,950,740 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 154 | 0 | n=input()
last=n[0]
d=0
o="NO"
for c in n:
if c==last:
d+=1
else:
d=1
last=c
if d==7:
o="YES"
break
print(o)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
n=input()
last=n[0]
d=0
o="NO"
for c in n:
if c==last:
d+=1
else:
d=1
last=c
if d==7:
o="YES"
break
print(o)
``` | 3.9615 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.