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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8 | C | Looking for Order | PROGRAMMING | 2,000 | [
"bitmasks",
"dp"
] | C. Looking for Order | 4 | 512 | Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period. | The first line of the input file contains the handbag's coordinates *x**s*,<=*y**s*. The second line contains number *n* (1<=≤<=*n*<=≤<=24) — the amount of objects the girl has. The following *n* lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer. | In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to *n*), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them. | [
"0 0\n2\n1 1\n-1 1\n",
"1 1\n3\n4 3\n3 4\n0 0\n"
] | [
"8\n0 1 2 0 \n",
"32\n0 1 2 0 3 0 \n"
] | none | 0 | [
{
"input": "0 0\n2\n1 1\n-1 1",
"output": "8\n0 1 2 0 "
},
{
"input": "1 1\n3\n4 3\n3 4\n0 0",
"output": "32\n0 1 2 0 3 0 "
},
{
"input": "-3 4\n1\n2 2",
"output": "58\n0 1 0 "
},
{
"input": "7 -7\n2\n3 1\n-3 8",
"output": "490\n0 1 2 0 "
},
{
"input": "3 -9\n3\n0 -9\n-10 -3\n-12 -2",
"output": "502\n0 1 0 2 3 0 "
},
{
"input": "4 -1\n4\n14 -3\n-11 10\n-3 -5\n-8 1",
"output": "922\n0 1 0 2 4 0 3 0 "
},
{
"input": "7 -11\n5\n-1 7\n-7 -11\n12 -4\n8 -6\n-18 -8",
"output": "1764\n0 1 3 0 2 5 0 4 0 "
},
{
"input": "11 3\n6\n-17 -17\n-4 -9\n15 19\n7 4\n13 1\n5 -6",
"output": "2584\n0 1 2 0 3 0 4 6 0 5 0 "
},
{
"input": "-6 4\n7\n-10 -11\n-11 -3\n13 27\n12 -22\n19 -17\n21 -21\n-5 4",
"output": "6178\n0 1 4 0 2 0 3 7 0 5 6 0 "
},
{
"input": "27 -5\n8\n-13 -19\n-20 -8\n11 2\n-23 21\n-28 1\n11 -12\n6 29\n22 -15",
"output": "14062\n0 1 2 0 3 7 0 4 5 0 6 8 0 "
},
{
"input": "31 9\n9\n8 -26\n26 4\n3 2\n24 21\n14 34\n-3 26\n35 -25\n5 20\n-1 8",
"output": "9384\n0 1 7 0 2 0 3 9 0 4 5 0 6 8 0 "
},
{
"input": "-44 47\n24\n96 -18\n-50 86\n84 68\n-25 80\n-11 -15\n-62 0\n-42 50\n-57 11\n-5 27\n-44 67\n-77 -3\n-27 -46\n32 63\n86 13\n-21 -51\n-25 -62\n-14 -2\n-21 86\n-92 -94\n-44 -34\n-74 55\n91 -35\n-10 55\n-34 16",
"output": "191534\n0 1 22 0 2 10 0 3 14 0 4 18 0 5 20 0 6 11 0 7 0 8 24 0 9 17 0 12 15 0 13 23 0 16 19 0 21 0 "
},
{
"input": "5 4\n11\n-26 2\n20 35\n-41 39\n31 -15\n-2 -44\n16 -28\n17 -6\n0 7\n-29 -35\n-17 12\n42 29",
"output": "19400\n0 1 3 0 2 11 0 4 6 0 5 9 0 7 0 8 10 0 "
},
{
"input": "-44 22\n12\n-28 24\n41 -19\n-39 -36\n12 -18\n-31 -24\n-7 29\n45 0\n12 -2\n42 31\n28 -37\n-34 -38\n6 24",
"output": "59712\n0 1 5 0 2 10 0 3 11 0 4 8 0 6 12 0 7 9 0 "
},
{
"input": "40 -36\n13\n3 -31\n28 -43\n45 11\n47 -37\n47 -28\n-30 24\n-46 -33\n-31 46\n-2 -38\n-43 -4\n39 11\n45 -1\n50 38",
"output": "52988\n0 1 9 0 2 0 3 13 0 4 5 0 6 8 0 7 10 0 11 12 0 "
},
{
"input": "-54 2\n14\n-21 -2\n-5 34\n48 -55\n-32 -23\n22 -10\n-33 54\n-16 32\n-53 -17\n10 31\n-47 21\n-52 49\n34 42\n-42 -25\n-32 31",
"output": "55146\n0 1 4 0 2 7 0 3 5 0 6 11 0 8 13 0 9 12 0 10 14 0 "
},
{
"input": "-19 -31\n15\n-31 -59\n60 -34\n-22 -59\n5 44\n26 39\n-39 -23\n-60 -7\n1 2\n-5 -19\n-41 -26\n46 -8\n51 -2\n60 4\n-12 44\n14 49",
"output": "60546\n0 1 3 0 2 11 0 4 14 0 5 15 0 6 0 7 10 0 8 9 0 12 13 0 "
},
{
"input": "-34 19\n16\n-44 24\n30 -42\n46 5\n13 -32\n40 53\n35 49\n-30 7\n-60 -50\n37 46\n-18 -57\n37 -44\n-61 58\n13 -55\n28 22\n-50 -3\n5 52",
"output": "81108\n0 1 12 0 2 11 0 3 14 0 4 13 0 5 9 0 6 16 0 7 15 0 8 10 0 "
},
{
"input": "-64 -6\n17\n-3 -18\n66 -58\n55 34\n-4 -40\n-1 -50\n13 -9\n56 55\n3 42\n-54 -52\n51 -56\n21 -27\n62 -17\n54 -5\n-28 -24\n12 68\n43 -22\n8 -6",
"output": "171198\n0 1 14 0 2 10 0 3 7 0 4 5 0 6 17 0 8 15 0 9 0 11 16 0 12 13 0 "
},
{
"input": "7 -35\n18\n24 -3\n25 -42\n-56 0\n63 -30\n18 -63\n-30 -20\n-53 -47\n-11 -17\n-22 -54\n7 -41\n-32 -3\n-29 15\n-30 -25\n68 15\n-18 70\n-28 19\n-12 69\n44 29",
"output": "70504\n0 1 4 0 2 5 0 3 11 0 6 13 0 7 9 0 8 0 10 0 12 16 0 14 18 0 15 17 0 "
},
{
"input": "-8 47\n19\n47 51\n43 -57\n-76 -26\n-23 51\n19 74\n-36 65\n50 4\n48 8\n14 -67\n23 44\n5 59\n7 -45\n-52 -6\n-2 -33\n34 -72\n-51 -47\n-42 4\n-41 55\n22 9",
"output": "112710\n0 1 10 0 2 15 0 3 16 0 4 0 5 11 0 6 18 0 7 8 0 9 12 0 13 17 0 14 19 0 "
},
{
"input": "44 75\n20\n-19 -33\n-25 -42\n-30 -61\n-21 44\n7 4\n-38 -78\n-14 9\n65 40\n-27 25\n65 -1\n-71 -38\n-52 57\n-41 -50\n-52 40\n40 44\n-19 51\n42 -43\n-79 -69\n26 -69\n-56 44",
"output": "288596\n0 1 19 0 2 13 0 3 6 0 4 16 0 5 7 0 8 15 0 9 14 0 10 17 0 11 18 0 12 20 0 "
},
{
"input": "42 -34\n21\n4 62\n43 73\n29 -26\n68 83\n0 52\n-72 34\n-48 44\n64 41\n83 -12\n-25 52\n42 59\n1 38\n12 -79\n-56 -62\n-8 67\n84 -83\n22 -63\n-11 -56\n71 44\n7 55\n-62 65",
"output": "196482\n0 1 15 0 2 4 0 3 0 5 12 0 6 21 0 7 10 0 8 19 0 9 16 0 11 20 0 13 17 0 14 18 0 "
},
{
"input": "-44 42\n22\n-67 -15\n74 -14\n67 76\n-57 58\n-64 78\n29 33\n-27 27\n-20 -52\n-54 -2\n-29 22\n31 -65\n-76 -76\n-29 -51\n-5 -79\n-55 36\n72 36\n-80 -26\n5 60\n-26 69\n78 42\n-47 -84\n8 83",
"output": "181122\n0 1 17 0 2 16 0 3 20 0 4 5 0 6 18 0 7 10 0 8 13 0 9 15 0 11 14 0 12 21 0 19 22 0 "
},
{
"input": "52 92\n23\n-67 -82\n31 82\n-31 -14\n-1 35\n-31 -49\n-75 -14\n78 -51\n-35 -24\n28 -84\n44 -51\n-37 -9\n-38 -91\n41 57\n-19 35\n14 -88\n-60 -60\n-13 -91\n65 -8\n-30 -46\n72 -44\n74 -5\n-79 31\n-3 84",
"output": "492344\n0 1 12 0 2 23 0 3 11 0 4 14 0 5 16 0 6 22 0 7 20 0 8 19 0 9 10 0 13 0 15 17 0 18 21 0 "
},
{
"input": "-21 -47\n24\n-37 1\n-65 8\n-74 74\n58 -7\n81 -31\n-77 90\n-51 10\n-42 -37\n-14 -17\n-26 -71\n62 45\n56 43\n-75 -73\n-33 68\n39 10\n-65 -93\n61 -93\n30 69\n-28 -53\n5 24\n93 38\n-45 -14\n3 -86\n63 -80",
"output": "204138\n0 1 22 0 2 7 0 3 6 0 4 5 0 8 19 0 9 20 0 10 23 0 11 21 0 12 15 0 13 16 0 14 18 0 17 24 0 "
},
{
"input": "31 16\n21\n-9 24\n-59 9\n-25 51\n62 52\n39 15\n83 -24\n45 -81\n42 -62\n57 -56\n-7 -3\n54 47\n-14 -54\n-14 -34\n-19 -60\n-38 58\n68 -63\n-1 -49\n6 75\n-27 22\n-58 -77\n-10 56",
"output": "121890\n0 1 10 0 2 19 0 3 15 0 4 11 0 5 0 6 16 0 7 9 0 8 17 0 12 13 0 14 20 0 18 21 0 "
},
{
"input": "20 -1\n22\n-51 -31\n-41 24\n-19 46\n70 -54\n60 5\n-41 35\n73 -6\n-31 0\n-29 23\n85 9\n-7 -86\n8 65\n-86 66\n-35 14\n11 19\n-66 -34\n-36 61\n84 -10\n-58 -74\n-11 -67\n79 74\n3 -67",
"output": "135950\n0 1 16 0 2 6 0 3 12 0 4 18 0 5 7 0 8 14 0 9 15 0 10 21 0 11 22 0 13 17 0 19 20 0 "
},
{
"input": "-49 4\n23\n-18 -53\n-42 31\n18 -84\n-20 -70\n-12 74\n-72 81\n12 26\n3 9\n-70 -27\n34 -32\n74 -47\n-19 -35\n-46 -8\n-77 90\n7 -42\n81 25\n84 81\n-53 -49\n20 81\n-39 0\n-70 -44\n-63 77\n-67 -73",
"output": "169524\n0 1 4 0 2 22 0 3 15 0 5 19 0 6 14 0 7 8 0 9 21 0 10 11 0 12 13 0 16 17 0 18 23 0 20 0 "
},
{
"input": "-81 35\n24\n58 27\n92 -93\n-82 63\n-55 80\n20 67\n33 93\n-29 46\n-71 -51\n-19 8\n58 -71\n13 60\n0 -48\n-2 -68\n-56 53\n62 52\n64 32\n-12 -63\n-82 -22\n9 -43\n55 12\n77 -21\n26 -25\n-91 -32\n-66 57",
"output": "337256\n0 1 16 0 2 10 0 3 24 0 4 14 0 5 11 0 6 15 0 7 9 0 8 17 0 12 13 0 18 23 0 19 22 0 20 21 0 "
},
{
"input": "45 79\n24\n-66 22\n10 77\n74 88\n59 1\n-51 -86\n-60 91\n1 -51\n-23 85\n3 96\n38 -4\n-55 43\n9 -68\n-4 83\n75 -13\n64 -74\n28 27\n92 -57\n-20 -64\n30 -44\n-95 67\n13 55\n67 -4\n42 77\n61 87",
"output": "277576\n0 1 11 0 2 9 0 3 24 0 4 16 0 5 18 0 6 20 0 7 12 0 8 13 0 10 19 0 14 22 0 15 17 0 21 23 0 "
},
{
"input": "-61 34\n24\n-57 -46\n-37 -24\n-87 -54\n51 -89\n-90 2\n95 -63\n-24 -84\n-85 38\n-52 -62\n96 4\n89 -22\n-16 -3\n-2 -14\n71 -62\n-51 68\n-83 -24\n15 77\n-61 45\n17 -32\n-68 -87\n-93 -28\n-85 24\n-84 -34\n-4 1",
"output": "262400\n0 1 9 0 2 12 0 3 23 0 4 19 0 5 22 0 6 14 0 7 20 0 8 18 0 10 11 0 13 24 0 15 17 0 16 21 0 "
},
{
"input": "70 90\n24\n-64 -96\n-87 -82\n10 -65\n94 22\n95 60\n-13 54\n-83 -92\n95 -50\n-65 -91\n96 -88\n80 -56\n-31 85\n58 86\n-28 22\n-22 45\n-24 -12\n-62 70\n-2 -77\n-31 -72\n61 37\n67 43\n-5 -30\n-84 -59\n-91 51",
"output": "585696\n0 1 7 0 2 23 0 3 18 0 4 8 0 5 0 6 12 0 9 19 0 10 11 0 13 0 14 15 0 16 22 0 17 24 0 20 21 0 "
},
{
"input": "72 -37\n24\n56 -47\n-37 -20\n76 -46\n-14 11\n-63 -46\n52 74\n-60 -23\n27 8\n-78 -26\n15 -23\n74 -90\n39 -64\n86 53\n77 11\n-47 -44\n-1 -14\n90 56\n76 -88\n-27 51\n-67 -8\n-27 4\n83 -91\n54 68\n56 26",
"output": "224008\n0 1 3 0 2 7 0 4 19 0 5 15 0 6 23 0 8 10 0 9 20 0 11 12 0 13 17 0 14 24 0 16 21 0 18 22 0 "
},
{
"input": "9 -5\n10\n-22 23\n22 -26\n10 -32\n18 -34\n7 -27\n2 -38\n-5 -24\n-38 -15\n21 -32\n-17 37",
"output": "13454\n0 1 10 0 2 9 0 3 4 0 5 6 0 7 8 0 "
}
] | 1,654,971,393 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | x0, y0 = map(int, input().split())
n = int(input())
point = []
for _ in range(n):
x, y = map(int, input().split())
point.append([x, y])
end = (1 << n) - 1
dp = [1e10] * (1 << n)
pre = [-1] * (1 << n)
dp[0] = 0
for i in range(1 << n):
f = 0
for j in range(n):
if i & (1 << j):
f += 1
for j in range(n):
if i & (1 << j):
k = i - (1 << j)
if pre[k] == -1 or f % 2 == 1:
d = (point[j][0] - x0) ** 2 + (point[j][1] - y0) ** 2
else:
d = (point[j][0] - point[pre[k]][0]) ** 2 + (point[j][1] - point[pre[k]][1]) ** 2
if f % 2 == 0 or i == end:
d += (point[j][0] - x0) ** 2 + (point[j][1] - y0) ** 2
if dp[i] > dp[k] + d:
pre[i] = j
dp[i] = dp[k] + d
path = ['0']
while end > 0:
path.append(str(pre[end] + 1))
n -= 1
if n % 2 == 0:
path.append(str(0))
end -= 1 << pre[end]
print(dp[end])
print(' '.join(path[::-1])) | Title: Looking for Order
Time Limit: 4 seconds
Memory Limit: 512 megabytes
Problem Description:
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input Specification:
The first line of the input file contains the handbag's coordinates *x**s*,<=*y**s*. The second line contains number *n* (1<=≤<=*n*<=≤<=24) — the amount of objects the girl has. The following *n* lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output Specification:
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to *n*), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Demo Input:
['0 0\n2\n1 1\n-1 1\n', '1 1\n3\n4 3\n3 4\n0 0\n']
Demo Output:
['8\n0 1 2 0 \n', '32\n0 1 2 0 3 0 \n']
Note:
none | ```python
x0, y0 = map(int, input().split())
n = int(input())
point = []
for _ in range(n):
x, y = map(int, input().split())
point.append([x, y])
end = (1 << n) - 1
dp = [1e10] * (1 << n)
pre = [-1] * (1 << n)
dp[0] = 0
for i in range(1 << n):
f = 0
for j in range(n):
if i & (1 << j):
f += 1
for j in range(n):
if i & (1 << j):
k = i - (1 << j)
if pre[k] == -1 or f % 2 == 1:
d = (point[j][0] - x0) ** 2 + (point[j][1] - y0) ** 2
else:
d = (point[j][0] - point[pre[k]][0]) ** 2 + (point[j][1] - point[pre[k]][1]) ** 2
if f % 2 == 0 or i == end:
d += (point[j][0] - x0) ** 2 + (point[j][1] - y0) ** 2
if dp[i] > dp[k] + d:
pre[i] = j
dp[i] = dp[k] + d
path = ['0']
while end > 0:
path.append(str(pre[end] + 1))
n -= 1
if n % 2 == 0:
path.append(str(0))
end -= 1 << pre[end]
print(dp[end])
print(' '.join(path[::-1]))
``` | 0 |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "499999999"
},
{
"input": "1924704072",
"output": "481176017"
},
{
"input": "73740586",
"output": "18435146"
},
{
"input": "1925088820",
"output": "481272204"
},
{
"input": "593070992",
"output": "148267747"
},
{
"input": "1925473570",
"output": "481368392"
},
{
"input": "629490186",
"output": "157372546"
},
{
"input": "1980649112",
"output": "495162277"
},
{
"input": "36661322",
"output": "9165330"
},
{
"input": "1943590793",
"output": "0"
},
{
"input": "71207034",
"output": "17801758"
},
{
"input": "1757577394",
"output": "439394348"
},
{
"input": "168305294",
"output": "42076323"
},
{
"input": "1934896224",
"output": "483724055"
},
{
"input": "297149088",
"output": "74287271"
},
{
"input": "1898001634",
"output": "474500408"
},
{
"input": "176409698",
"output": "44102424"
},
{
"input": "1873025522",
"output": "468256380"
},
{
"input": "5714762",
"output": "1428690"
},
{
"input": "1829551192",
"output": "457387797"
},
{
"input": "16269438",
"output": "4067359"
},
{
"input": "1663283390",
"output": "415820847"
},
{
"input": "42549941",
"output": "0"
},
{
"input": "1967345604",
"output": "491836400"
},
{
"input": "854000",
"output": "213499"
},
{
"input": "1995886626",
"output": "498971656"
},
{
"input": "10330019",
"output": "0"
},
{
"input": "1996193634",
"output": "499048408"
},
{
"input": "9605180",
"output": "2401294"
},
{
"input": "1996459740",
"output": "499114934"
},
{
"input": "32691948",
"output": "8172986"
},
{
"input": "1975903308",
"output": "493975826"
},
{
"input": "1976637136",
"output": "494159283"
},
{
"input": "29803038",
"output": "7450759"
},
{
"input": "1977979692",
"output": "494494922"
},
{
"input": "1978595336",
"output": "494648833"
},
{
"input": "27379344",
"output": "6844835"
},
{
"input": "1979729912",
"output": "494932477"
},
{
"input": "1980253780",
"output": "495063444"
},
{
"input": "1980751584",
"output": "495187895"
},
{
"input": "53224878",
"output": "13306219"
},
{
"input": "5",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "2"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "0"
},
{
"input": "14",
"output": "3"
},
{
"input": "15",
"output": "0"
},
{
"input": "16",
"output": "3"
},
{
"input": "17",
"output": "0"
},
{
"input": "18",
"output": "4"
},
{
"input": "19",
"output": "0"
},
{
"input": "21",
"output": "0"
},
{
"input": "22",
"output": "5"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "26",
"output": "6"
},
{
"input": "27",
"output": "0"
},
{
"input": "28",
"output": "6"
},
{
"input": "29",
"output": "0"
},
{
"input": "30",
"output": "7"
},
{
"input": "111",
"output": "0"
},
{
"input": "55",
"output": "0"
},
{
"input": "105",
"output": "0"
},
{
"input": "199",
"output": "0"
},
{
"input": "151",
"output": "0"
}
] | 1,602,179,034 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;
cin >> n;
int x = n / 2;
cout << (x+1) / 2 - 1;
} | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
Output Specification:
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Demo Input:
['6\n', '20\n']
Demo Output:
['1\n', '4\n']
Note:
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | ```python
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;
cin >> n;
int x = n / 2;
cout << (x+1) / 2 - 1;
}
``` | -1 |
|
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him. | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total. | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output": "52"
},
{
"input": "2 of week",
"output": "52"
},
{
"input": "3 of week",
"output": "52"
},
{
"input": "5 of week",
"output": "53"
},
{
"input": "7 of week",
"output": "52"
},
{
"input": "1 of month",
"output": "12"
},
{
"input": "2 of month",
"output": "12"
},
{
"input": "3 of month",
"output": "12"
},
{
"input": "4 of month",
"output": "12"
},
{
"input": "5 of month",
"output": "12"
},
{
"input": "6 of month",
"output": "12"
},
{
"input": "7 of month",
"output": "12"
},
{
"input": "8 of month",
"output": "12"
},
{
"input": "9 of month",
"output": "12"
},
{
"input": "10 of month",
"output": "12"
},
{
"input": "11 of month",
"output": "12"
},
{
"input": "12 of month",
"output": "12"
},
{
"input": "13 of month",
"output": "12"
},
{
"input": "14 of month",
"output": "12"
},
{
"input": "15 of month",
"output": "12"
},
{
"input": "16 of month",
"output": "12"
},
{
"input": "18 of month",
"output": "12"
},
{
"input": "19 of month",
"output": "12"
},
{
"input": "20 of month",
"output": "12"
},
{
"input": "21 of month",
"output": "12"
},
{
"input": "22 of month",
"output": "12"
},
{
"input": "23 of month",
"output": "12"
},
{
"input": "24 of month",
"output": "12"
},
{
"input": "25 of month",
"output": "12"
},
{
"input": "26 of month",
"output": "12"
},
{
"input": "27 of month",
"output": "12"
},
{
"input": "28 of month",
"output": "12"
},
{
"input": "29 of month",
"output": "12"
}
] | 1,585,563,715 | 535 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 139 | 0 | s = input().split()
if s[-1]=='week':
print(52)
else:
date = int(s[0])
if date<=29:
print(12)
if date==30:
print(11)
if date==31:
print(7)
| Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
Input Specification:
The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Output Specification:
Print one integer — the number of candies Limak will save in the year 2016.
Demo Input:
['4 of week\n', '30 of month\n']
Demo Output:
['52\n', '11\n']
Note:
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total. | ```python
s = input().split()
if s[-1]=='week':
print(52)
else:
date = int(s[0])
if date<=29:
print(12)
if date==30:
print(11)
if date==31:
print(7)
``` | 0 |
|
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,687,282,253 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | STR=str(input())
str0="0000000"
str1="1111111"
if (str0 in STR) or (str1 in STR):
print("YES")
else:
print("NO") | 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
STR=str(input())
str0="0000000"
str1="1111111"
if (str0 in STR) or (str1 in STR):
print("YES")
else:
print("NO")
``` | 3.977 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,420,910,198 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | x=input()
y=input()
i=0
t=''
while i<len(x):
if x[i]==y[i]:s='1'
else:s='0'
t=t+s
i=i+1
print(t)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
x=input()
y=input()
i=0
t=''
while i<len(x):
if x[i]==y[i]:s='1'
else:s='0'
t=t+s
i=i+1
print(t)
``` | 0 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,661,670,335 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n = input()
n = int(n)
a = list(input().split())
a = [int(i) for i in a]
for i in range(1,n):
sum = a[i] - a[i-1]
b = a.copy()
ans = 0
num = 0
for j in range(1,n):
if not(b[j] - b[j-1] == sum):
num+=1
ans = j + 1
b[j] = b[j-1] + sum
if num > 1:
break
if num == 1:
print(ans)
break
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = input()
n = int(n)
a = list(input().split())
a = [int(i) for i in a]
for i in range(1,n):
sum = a[i] - a[i-1]
b = a.copy()
ans = 0
num = 0
for j in range(1,n):
if not(b[j] - b[j-1] == sum):
num+=1
ans = j + 1
b[j] = b[j-1] + sum
if num > 1:
break
if num == 1:
print(ans)
break
``` | 0 |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner. | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct. | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 2147483648\n2 1",
"output": "2"
},
{
"input": "3 2\n1 3 2",
"output": "3 "
},
{
"input": "3 3\n1 2 3",
"output": "3 "
},
{
"input": "5 2\n2 1 3 4 5",
"output": "5 "
},
{
"input": "10 2\n7 10 5 8 9 3 4 6 1 2",
"output": "10 "
},
{
"input": "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98",
"output": "70 "
},
{
"input": "4 10\n2 1 3 4",
"output": "4"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "10 "
},
{
"input": "10 2\n10 9 8 7 6 5 4 3 2 1",
"output": "10 "
},
{
"input": "4 1000000000000\n3 4 1 2",
"output": "4"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "91 "
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "100 "
},
{
"input": "2 1000000000000\n1 2",
"output": "2"
},
{
"input": "5 2\n1 4 3 5 2",
"output": "4 "
},
{
"input": "5 2\n1 3 2 4 5",
"output": "3 "
},
{
"input": "4 1000000000000\n3 1 2 4",
"output": "4"
},
{
"input": "4 2\n1 3 2 4",
"output": "3 "
},
{
"input": "10 3\n8 1 9 2 3 10 4 5 6 7",
"output": "9 "
},
{
"input": "5 2\n2 1 4 3 5",
"output": "4 "
},
{
"input": "3 4294967297\n2 1 3",
"output": "3"
},
{
"input": "4 4294967297\n3 2 1 4",
"output": "4"
},
{
"input": "5 4294967298\n3 2 1 4 5",
"output": "5"
},
{
"input": "10 4\n5 4 7 1 2 9 3 6 8 10",
"output": "9 "
},
{
"input": "11 21474836489\n10 1 2 3 4 5 6 7 8 9 11",
"output": "11"
}
] | 1,572,788,874 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 171 | 921,600 | import math
import os
import random
import re
import sys
playerWins = input().split()
player = int(playerWins[0])
wins = int(playerWins[1])
powerValue = list(map(int, input().rstrip().split()[:player]))
a=0
checker = []
if wins > 1000:
wins = 1000
while len(checker) < wins:
if powerValue[a] > powerValue[a+1]:
checker.append(powerValue[a+1])
powerValue.append(powerValue[a+1])
del powerValue[a+1]
elif powerValue[a] < powerValue[a+1]:
powerValue.append(powerValue[a])
del powerValue[a]
checker.clear()
checker.append(powerValue[a+1])
print(powerValue[a])
| Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
Input Specification:
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
Output Specification:
Output a single integer — power of the winner.
Demo Input:
['2 2\n1 2\n', '4 2\n3 1 2 4\n', '6 2\n6 5 3 1 2 4\n', '2 10000000000\n2 1\n']
Demo Output:
['2 ', '3 ', '6 ', '2\n']
Note:
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | ```python
import math
import os
import random
import re
import sys
playerWins = input().split()
player = int(playerWins[0])
wins = int(playerWins[1])
powerValue = list(map(int, input().rstrip().split()[:player]))
a=0
checker = []
if wins > 1000:
wins = 1000
while len(checker) < wins:
if powerValue[a] > powerValue[a+1]:
checker.append(powerValue[a+1])
powerValue.append(powerValue[a+1])
del powerValue[a+1]
elif powerValue[a] < powerValue[a+1]:
powerValue.append(powerValue[a])
del powerValue[a]
checker.clear()
checker.append(powerValue[a+1])
print(powerValue[a])
``` | 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,588,092,298 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n = int(input())
p = int(input())
q = int(input())
mn = q*(n/(q+p))
ma = p*(n/(q+p))
print(max(mn,ma)) | 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())
p = int(input())
q = int(input())
mn = q*(n/(q+p))
ma = p*(n/(q+p))
print(max(mn,ma))
``` | 0 |
|
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect? | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0. | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "300000"
},
{
"input": "1\n-1 1",
"output": "1"
},
{
"input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463",
"output": "1036452"
},
{
"input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532",
"output": "632240"
},
{
"input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044",
"output": "891593"
},
{
"input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422",
"output": "1109655"
},
{
"input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834",
"output": "847241"
},
{
"input": "3\n-94146 4473\n28707 99079\n-4153 8857",
"output": "112409"
},
{
"input": "3\n-3 3\n-2 2\n-1 1",
"output": "1"
},
{
"input": "2\n100000 3\n-100000 9",
"output": "12"
},
{
"input": "2\n-100000 100000\n100000 99999",
"output": "199999"
}
] | 1,437,095,896 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 |
def MBS(seq):
L = len(seq)
for i in range(L):
for n in range(1, L):
if seq[n][0] == seq[n - 1][0] and seq[n][1] > seq[n - 1][1]:
seq[n - 1], seq[n] = seq[n], seq[n - 1]
N=int(input())
Pos=[]
Neg=[]
for _ in range(N):
X,A=map(int,input().split())
if X<0:
Neg+=[[X,A]]
else:
Pos+=[[X,A]]
Neg.sort()
MBS(Neg)
Pos.sort()
MBS(Pos)
Ans=[0]
I=0
while I<len(Pos)and I<len(Neg):
Ans[0]+=Pos[I][1]
Ans[0]+=Neg[I][1]
I+=1
if I<len(Pos):
Ans+=[Ans[0]+Pos[I][1]]
if I<len(Neg):
Ans+=[Ans[0]+Neg[I][1]]
print(max(Ans))
| Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input Specification:
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output Specification:
Output the maximum number of apples Amr can collect.
Demo Input:
['2\n-1 5\n1 5\n', '3\n-2 2\n1 4\n-1 3\n', '3\n1 9\n3 5\n7 10\n']
Demo Output:
['10', '9', '9']
Note:
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | ```python
def MBS(seq):
L = len(seq)
for i in range(L):
for n in range(1, L):
if seq[n][0] == seq[n - 1][0] and seq[n][1] > seq[n - 1][1]:
seq[n - 1], seq[n] = seq[n], seq[n - 1]
N=int(input())
Pos=[]
Neg=[]
for _ in range(N):
X,A=map(int,input().split())
if X<0:
Neg+=[[X,A]]
else:
Pos+=[[X,A]]
Neg.sort()
MBS(Neg)
Pos.sort()
MBS(Pos)
Ans=[0]
I=0
while I<len(Pos)and I<len(Neg):
Ans[0]+=Pos[I][1]
Ans[0]+=Neg[I][1]
I+=1
if I<len(Pos):
Ans+=[Ans[0]+Pos[I][1]]
if I<len(Neg):
Ans+=[Ans[0]+Neg[I][1]]
print(max(Ans))
``` | 0 |
|
370 | A | Rook, Bishop and King | PROGRAMMING | 1,100 | [
"graphs",
"math",
"shortest paths"
] | null | null | Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:
- A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally.
Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. | The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. | Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. | [
"4 3 1 6\n",
"5 5 5 6\n"
] | [
"2 1 3\n",
"1 0 1\n"
] | none | 500 | [
{
"input": "4 3 1 6",
"output": "2 1 3"
},
{
"input": "5 5 5 6",
"output": "1 0 1"
},
{
"input": "1 1 8 8",
"output": "2 1 7"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 1 1 8",
"output": "1 0 7"
},
{
"input": "8 1 1 1",
"output": "1 0 7"
},
{
"input": "8 1 1 8",
"output": "2 1 7"
},
{
"input": "7 7 6 6",
"output": "2 1 1"
},
{
"input": "8 1 8 8",
"output": "1 0 7"
},
{
"input": "1 8 1 1",
"output": "1 0 7"
},
{
"input": "1 8 8 1",
"output": "2 1 7"
},
{
"input": "1 8 8 8",
"output": "1 0 7"
},
{
"input": "8 8 1 1",
"output": "2 1 7"
},
{
"input": "8 8 1 8",
"output": "1 0 7"
},
{
"input": "8 8 8 1",
"output": "1 0 7"
},
{
"input": "1 3 1 6",
"output": "1 0 3"
},
{
"input": "1 3 1 4",
"output": "1 0 1"
},
{
"input": "1 3 1 5",
"output": "1 2 2"
},
{
"input": "3 3 2 4",
"output": "2 1 1"
},
{
"input": "3 3 1 5",
"output": "2 1 2"
},
{
"input": "1 6 2 1",
"output": "2 2 5"
},
{
"input": "1 5 6 4",
"output": "2 2 5"
},
{
"input": "1 3 3 7",
"output": "2 2 4"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 7 5 4",
"output": "2 0 4"
},
{
"input": "1 5 2 7",
"output": "2 0 2"
},
{
"input": "1 4 6 2",
"output": "2 0 5"
},
{
"input": "1 2 3 5",
"output": "2 0 3"
},
{
"input": "1 8 8 7",
"output": "2 2 7"
},
{
"input": "6 5 6 2",
"output": "1 0 3"
},
{
"input": "6 3 3 5",
"output": "2 0 3"
},
{
"input": "6 1 7 8",
"output": "2 2 7"
},
{
"input": "1 2 3 2",
"output": "1 2 2"
},
{
"input": "3 8 7 2",
"output": "2 2 6"
},
{
"input": "4 2 6 4",
"output": "2 1 2"
},
{
"input": "1 1 1 3",
"output": "1 2 2"
},
{
"input": "6 8 8 6",
"output": "2 1 2"
},
{
"input": "6 7 4 1",
"output": "2 2 6"
},
{
"input": "6 5 1 4",
"output": "2 2 5"
},
{
"input": "3 2 7 6",
"output": "2 1 4"
},
{
"input": "3 8 4 1",
"output": "2 2 7"
},
{
"input": "3 6 1 4",
"output": "2 1 2"
}
] | 1,698,977,233 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 17 | 46 | 0 | def diags(r, c): return (r + c, r - c)
r1, c1, r2, c2 = map(int, input().split())
d1 = diags(r1, c1)
d2 = diags(r2, c2)
print(
1 if r1 == r2 or c1 == c2 else 2,
0 if r1 ^ c1 ^ r2 ^ c2 else 1 if d1[0] == d2[0] or d1[1] == d2[1] else 2,
max(abs(r1 - r2), abs(c1 - c2)),
)
| Title: Rook, Bishop and King
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:
- A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally.
Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.
Input Specification:
The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.
Output Specification:
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
Demo Input:
['4 3 1 6\n', '5 5 5 6\n']
Demo Output:
['2 1 3\n', '1 0 1\n']
Note:
none | ```python
def diags(r, c): return (r + c, r - c)
r1, c1, r2, c2 = map(int, input().split())
d1 = diags(r1, c1)
d2 = diags(r2, c2)
print(
1 if r1 == r2 or c1 == c2 else 2,
0 if r1 ^ c1 ^ r2 ^ c2 else 1 if d1[0] == d2[0] or d1[1] == d2[1] else 2,
max(abs(r1 - r2), abs(c1 - c2)),
)
``` | 0 |
|
894 | D | Ralph And His Tour in Binary Country | PROGRAMMING | 2,200 | [
"brute force",
"data structures",
"trees"
] | null | null | Ralph is in the Binary Country. The Binary Country consists of *n* cities and (*n*<=-<=1) bidirectional roads connecting the cities. The roads are numbered from 1 to (*n*<=-<=1), the *i*-th road connects the city labeled (here ⌊ *x*⌋ denotes the *x* rounded down to the nearest integer) and the city labeled (*i*<=+<=1), and the length of the *i*-th road is *L**i*.
Now Ralph gives you *m* queries. In each query he tells you some city *A**i* and an integer *H**i*. He wants to make some tours starting from this city. He can choose any city in the Binary Country (including *A**i*) as the terminal city for a tour. He gains happiness (*H**i*<=-<=*L*) during a tour, where *L* is the distance between the city *A**i* and the terminal city.
Ralph is interested in tours from *A**i* in which he can gain positive happiness. For each query, compute the sum of happiness gains for all such tours.
Ralph will never take the same tour twice or more (in one query), he will never pass the same city twice or more in one tour. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=105).
(*n*<=-<=1) lines follow, each line contains one integer *L**i* (1<=≤<=*L**i*<=≤<=105), which denotes the length of the *i*-th road.
*m* lines follow, each line contains two integers *A**i* and *H**i* (1<=≤<=*A**i*<=≤<=*n*, 0<=≤<=*H**i*<=≤<=107). | Print *m* lines, on the *i*-th line print one integer — the answer for the *i*-th query. | [
"2 2\n5\n1 8\n2 4\n",
"6 4\n2\n1\n1\n3\n2\n2 4\n1 3\n3 2\n1 7\n"
] | [
"11\n4\n",
"11\n6\n3\n28\n"
] | Here is the explanation for the second sample.
Ralph's first query is to start tours from city 2 and *H*<sub class="lower-index">*i*</sub> equals to 4. Here are the options:
- He can choose city 5 as his terminal city. Since the distance between city 5 and city 2 is 3, he can gain happiness 4 - 3 = 1. - He can choose city 4 as his terminal city and gain happiness 3. - He can choose city 1 as his terminal city and gain happiness 2. - He can choose city 3 as his terminal city and gain happiness 1. - Note that Ralph can choose city 2 as his terminal city and gain happiness 4. - Ralph won't choose city 6 as his terminal city because the distance between city 6 and city 2 is 5, which leads to negative happiness for Ralph.
So the answer for the first query is 1 + 3 + 2 + 1 + 4 = 11. | 2,000 | [
{
"input": "2 2\n5\n1 8\n2 4",
"output": "11\n4"
},
{
"input": "6 4\n2\n1\n1\n3\n2\n2 4\n1 3\n3 2\n1 7",
"output": "11\n6\n3\n28"
},
{
"input": "8 1\n21725\n80273\n97276\n78838\n78474\n1896\n6570\n7 5267977",
"output": "41283845"
},
{
"input": "4 2\n56025\n27554\n51024\n2 4730374\n4 7372300",
"output": "18730868\n29196524"
},
{
"input": "7 3\n73302\n43581\n59091\n35794\n64662\n60029\n6 4980178\n4 2677480\n5 9024109",
"output": "33924130\n17803378\n62346266"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,693,928,157 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 46 | 2,867,200 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
def make_graph(n, m):
s = [0] * (n + 3)
for i in range(0, 2 * m, 2):
s[x[i] + 2] += 1
for i in range(3, n + 3):
s[i] += s[i - 1]
G = [0] * m
for i in range(0, 2 * m, 2):
j = x[i] + 1
G[s[j]] = x[i ^ 1]
s[j] += 1
return G, s
n, m = map(int, input().split())
l = [0] * 2 + [int(input()) for _ in range(n - 1)]
x = []
ans = [0] * m
for i in range(m):
a, h = map(int, input().split())
x.append(a)
x.append(f(h, i))
h -= l[a]
while a ^ 1 and h > 0:
ans[i] += h
if a ^ 1 <= n and h > l[a ^ 1]:
x.append(a ^ 1)
x.append(f(h - l[a ^ 1], i))
a >>= 1
h -= l[a]
z = pow(2, n.bit_length())
G, s0 = make_graph(z, len(x) // 2)
inf = pow(10, 9) + 1
l += [inf] * (z - n - 1)
u = [0 if not i & 1 else inf for i in range(z)]
for i in range(z >> 1, z):
for v in range(s0[i], s0[i + 1]):
h, j = divmod(G[v], m)
ans[j] += h
n, s, d = z >> 2, 0, 2
while n:
for i in range(n, n << 1):
p, q = l[2 * i], l[2 * i + 1]
j, k = s, s + d
x = [0] * (2 * (d - 1))
for v in range(2 * (d - 1)):
if u[j] + p < u[k] + q:
x[v] = u[j] + p
j += 1
else:
x[v] = u[k] + q
k += 1
y = [0] * (s0[i + 1] - s0[i])
for v in range(s0[i], s0[i + 1]):
y[v - s0[i]] = G[v]
c, p = 0, 0
for j in sorted(y):
h, k = divmod(j, m)
while c < 2 * (d - 1) and x[c] <= h:
p += x[c]
c += 1
ans[k] += h * (c + 1) - p
for v in range(2 * (d - 1)):
u[s + v + 1] = x[v]
s += 2 * d
n, s, d = n >> 1, 0, 2 * d
sys.stdout.write("\n".join(map(str, ans))) | Title: Ralph And His Tour in Binary Country
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ralph is in the Binary Country. The Binary Country consists of *n* cities and (*n*<=-<=1) bidirectional roads connecting the cities. The roads are numbered from 1 to (*n*<=-<=1), the *i*-th road connects the city labeled (here ⌊ *x*⌋ denotes the *x* rounded down to the nearest integer) and the city labeled (*i*<=+<=1), and the length of the *i*-th road is *L**i*.
Now Ralph gives you *m* queries. In each query he tells you some city *A**i* and an integer *H**i*. He wants to make some tours starting from this city. He can choose any city in the Binary Country (including *A**i*) as the terminal city for a tour. He gains happiness (*H**i*<=-<=*L*) during a tour, where *L* is the distance between the city *A**i* and the terminal city.
Ralph is interested in tours from *A**i* in which he can gain positive happiness. For each query, compute the sum of happiness gains for all such tours.
Ralph will never take the same tour twice or more (in one query), he will never pass the same city twice or more in one tour.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=105).
(*n*<=-<=1) lines follow, each line contains one integer *L**i* (1<=≤<=*L**i*<=≤<=105), which denotes the length of the *i*-th road.
*m* lines follow, each line contains two integers *A**i* and *H**i* (1<=≤<=*A**i*<=≤<=*n*, 0<=≤<=*H**i*<=≤<=107).
Output Specification:
Print *m* lines, on the *i*-th line print one integer — the answer for the *i*-th query.
Demo Input:
['2 2\n5\n1 8\n2 4\n', '6 4\n2\n1\n1\n3\n2\n2 4\n1 3\n3 2\n1 7\n']
Demo Output:
['11\n4\n', '11\n6\n3\n28\n']
Note:
Here is the explanation for the second sample.
Ralph's first query is to start tours from city 2 and *H*<sub class="lower-index">*i*</sub> equals to 4. Here are the options:
- He can choose city 5 as his terminal city. Since the distance between city 5 and city 2 is 3, he can gain happiness 4 - 3 = 1. - He can choose city 4 as his terminal city and gain happiness 3. - He can choose city 1 as his terminal city and gain happiness 2. - He can choose city 3 as his terminal city and gain happiness 1. - Note that Ralph can choose city 2 as his terminal city and gain happiness 4. - Ralph won't choose city 6 as his terminal city because the distance between city 6 and city 2 is 5, which leads to negative happiness for Ralph.
So the answer for the first query is 1 + 3 + 2 + 1 + 4 = 11. | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
def make_graph(n, m):
s = [0] * (n + 3)
for i in range(0, 2 * m, 2):
s[x[i] + 2] += 1
for i in range(3, n + 3):
s[i] += s[i - 1]
G = [0] * m
for i in range(0, 2 * m, 2):
j = x[i] + 1
G[s[j]] = x[i ^ 1]
s[j] += 1
return G, s
n, m = map(int, input().split())
l = [0] * 2 + [int(input()) for _ in range(n - 1)]
x = []
ans = [0] * m
for i in range(m):
a, h = map(int, input().split())
x.append(a)
x.append(f(h, i))
h -= l[a]
while a ^ 1 and h > 0:
ans[i] += h
if a ^ 1 <= n and h > l[a ^ 1]:
x.append(a ^ 1)
x.append(f(h - l[a ^ 1], i))
a >>= 1
h -= l[a]
z = pow(2, n.bit_length())
G, s0 = make_graph(z, len(x) // 2)
inf = pow(10, 9) + 1
l += [inf] * (z - n - 1)
u = [0 if not i & 1 else inf for i in range(z)]
for i in range(z >> 1, z):
for v in range(s0[i], s0[i + 1]):
h, j = divmod(G[v], m)
ans[j] += h
n, s, d = z >> 2, 0, 2
while n:
for i in range(n, n << 1):
p, q = l[2 * i], l[2 * i + 1]
j, k = s, s + d
x = [0] * (2 * (d - 1))
for v in range(2 * (d - 1)):
if u[j] + p < u[k] + q:
x[v] = u[j] + p
j += 1
else:
x[v] = u[k] + q
k += 1
y = [0] * (s0[i + 1] - s0[i])
for v in range(s0[i], s0[i + 1]):
y[v - s0[i]] = G[v]
c, p = 0, 0
for j in sorted(y):
h, k = divmod(j, m)
while c < 2 * (d - 1) and x[c] <= h:
p += x[c]
c += 1
ans[k] += h * (c + 1) - p
for v in range(2 * (d - 1)):
u[s + v + 1] = x[v]
s += 2 * d
n, s, d = n >> 1, 0, 2 * d
sys.stdout.write("\n".join(map(str, ans)))
``` | -1 |
|
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,694,875,313 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | rows = [input() for _ in range(5)]
for j in range(5):
ix = rows[j].find('1')
if (ix != - 1):
ix = ix - (ix // 2)
print(abs(2-j)+abs(ix-2))
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
rows = [input() for _ in range(5)]
for j in range(5):
ix = rows[j].find('1')
if (ix != - 1):
ix = ix - (ix // 2)
print(abs(2-j)+abs(ix-2))
``` | 3 |
|
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a. | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw"
},
{
"input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "12\nmmmmmmmmmmmm",
"output": "mmmmmmmmmmmm"
},
{
"input": "18\nyaywptqwuyiqypwoyw",
"output": "ywptqwuqypwow"
},
{
"input": "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "13\nmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmm"
},
{
"input": "10\nmmmmmmmmmm",
"output": "mmmmmmmmmm"
},
{
"input": "11\nmmmmmmmmmmm",
"output": "mmmmmmmmmmm"
},
{
"input": "15\nmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmm"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "14\nmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmm"
},
{
"input": "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "2\naa",
"output": "a"
},
{
"input": "18\niuiuqpyyaoaetiwliu",
"output": "iqpytiwli"
},
{
"input": "5\nxxxxx",
"output": "xxxxx"
},
{
"input": "6\nxxxahg",
"output": "xxxahg"
},
{
"input": "3\nzcv",
"output": "zcv"
},
{
"input": "4\naepo",
"output": "apo"
},
{
"input": "5\nqqqqq",
"output": "qqqqq"
},
{
"input": "6\naaaaaa",
"output": "a"
},
{
"input": "4\naeta",
"output": "ata"
},
{
"input": "20\nttyttlwaoieulyiluuri",
"output": "ttyttlwalyluri"
},
{
"input": "1\nb",
"output": "b"
},
{
"input": "3\nanc",
"output": "anc"
},
{
"input": "1\ne",
"output": "e"
},
{
"input": "3\naie",
"output": "a"
},
{
"input": "3\nvio",
"output": "vi"
},
{
"input": "2\nea",
"output": "e"
},
{
"input": "3\nuas",
"output": "us"
},
{
"input": "2\nba",
"output": "ba"
},
{
"input": "2\naq",
"output": "aq"
},
{
"input": "2\nya",
"output": "y"
},
{
"input": "2\nou",
"output": "o"
},
{
"input": "2\nbb",
"output": "bb"
},
{
"input": "7\nayylmao",
"output": "alma"
},
{
"input": "2\nab",
"output": "ab"
},
{
"input": "19\nyuouiyaoiiweqrryqqp",
"output": "yweqrryqqp"
},
{
"input": "25\niqypwqpriiioetiuqqqttouei",
"output": "iqypwqpritiqqqtto"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz"
},
{
"input": "17\naccccccccccccccca",
"output": "accccccccccccccca"
},
{
"input": "5\nababa",
"output": "ababa"
},
{
"input": "10\naaaaaaaaaa",
"output": "a"
},
{
"input": "22\naaaaabbbbboyoyoyoyoyac",
"output": "abbbbboc"
},
{
"input": "7\nmahmoud",
"output": "mahmod"
}
] | 1,526,834,702 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n=int(input())
m=input()
indice =0
vo = ['a', 'e', 'i', 'o', 'u', 'y']
while indice <(len(m)-1):
if m[indice] in vo and m[indice+1]in vo:
m.pop(indice)
else:
indice += 1
print(m) | Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output Specification:
Output the word *s* after the correction.
Demo Input:
['5\nweird\n', '4\nword\n', '5\naaeaa\n']
Demo Output:
['werd\n', 'word\n', 'a\n']
Note:
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a. | ```python
n=int(input())
m=input()
indice =0
vo = ['a', 'e', 'i', 'o', 'u', 'y']
while indice <(len(m)-1):
if m[indice] in vo and m[indice+1]in vo:
m.pop(indice)
else:
indice += 1
print(m)
``` | -1 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,598,482,626 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 280 | 1,228,800 | from fractions import Fraction
def main():
a = max(map(int, input().split())) -1
print(Fraction(a, 6) if Fraction(a, 6) > 0 else '1/1')
main() | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
from fractions import Fraction
def main():
a = max(map(int, input().split())) -1
print(Fraction(a, 6) if Fraction(a, 6) > 0 else '1/1')
main()
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,573,048,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | s1 = input()
s2 = 'hello'
hello = 'NO'
for i in range(len(s1)):
if s1[i] == s2[0]:
if len(s2) > 1:
s2 = s2[1:]
else:
hello = 'YES'
break
elif i > 0 and s1[i] != s1[i-1]:
break
print(hello) | 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
s1 = input()
s2 = 'hello'
hello = 'NO'
for i in range(len(s1)):
if s1[i] == s2[0]:
if len(s2) > 1:
s2 = s2[1:]
else:
hello = 'YES'
break
elif i > 0 and s1[i] != s1[i-1]:
break
print(hello)
``` | 0 |
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
"output": "2\n99 100 "
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 "
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421",
"output": "8\n117 151 183 227 954 222 909 421 "
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2",
"output": "4\n62 726 903 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2",
"output": "6\n5 33 375 37 3 2 "
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6",
"output": "6\n4 3 2 5 1 6 "
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2\n233 1 "
},
{
"input": "47\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1\n1 "
},
{
"input": "2\n964 964",
"output": "1\n964 "
},
{
"input": "2\n1000 1000",
"output": "1\n1000 "
},
{
"input": "1\n1000",
"output": "1\n1000 "
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993",
"output": "10\n996 1000 999 992 997 991 995 998 994 993 "
},
{
"input": "6\n994 993 1000 998 991 994",
"output": "5\n993 1000 998 991 994 "
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999",
"output": "10\n993 996 995 991 994 997 998 992 1000 999 "
},
{
"input": "3\n6 6 3",
"output": "2\n6 3 "
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997",
"output": "9\n1000 995 994 993 999 996 998 991 997 "
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996",
"output": "10\n998 995 999 992 1000 993 994 997 991 996 "
},
{
"input": "2\n1000 999",
"output": "2\n1000 999 "
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000",
"output": "10\n996 999 993 994 997 995 991 992 998 1000 "
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992",
"output": "8\n993 997 998 994 1000 991 995 992 "
},
{
"input": "6\n1000 1 1000 2 1000 1",
"output": "3\n2 1000 1 "
},
{
"input": "6\n1000 1 1000 2 1 1000",
"output": "3\n2 1 1000 "
},
{
"input": "7\n1 1000 1 999 1000 1 2",
"output": "4\n999 1000 1 2 "
}
] | 1,661,552,804 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 409,600 | from cmath import *
from math import *
from decimal import *
from collections import *
from re import X
import sys
def _input(): return map(int, input().split())
def _list(): return list(map(int, input().split()))
def _int(): return int(input())
#ord -> chuyen asciiz thanh int
def solves():
n= _int()
lst=set(_list())
print(*lst)
t=1
#t =int(input())
for _ in range(0,t):
solves()
| Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
Output Specification:
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
Demo Input:
['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n']
Demo Output:
['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n']
Note:
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | ```python
from cmath import *
from math import *
from decimal import *
from collections import *
from re import X
import sys
def _input(): return map(int, input().split())
def _list(): return list(map(int, input().split()))
def _int(): return int(input())
#ord -> chuyen asciiz thanh int
def solves():
n= _int()
lst=set(_list())
print(*lst)
t=1
#t =int(input())
for _ in range(0,t):
solves()
``` | 0 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,654,776,247 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,318,400 | n=int(input())
lstn=[int(x) for x in input().split()]
m=int(input())
lstm=[int(x) for x in input().split()]
vasya,petya=0,0
for i in lstm:
vasya+=lstn.index(i)+1
petya+=n-lstn.index(i)
print(vasya,petya)
| Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
n=int(input())
lstn=[int(x) for x in input().split()]
m=int(input())
lstm=[int(x) for x in input().split()]
vasya,petya=0,0
for i in lstm:
vasya+=lstn.index(i)+1
petya+=n-lstn.index(i)
print(vasya,petya)
``` | 0 |
|
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -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": "2\n-1 5",
"output": "6"
},
{
"input": "3\n-2 0 1",
"output": "3"
},
{
"input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3",
"output": "94"
},
{
"input": "4\n1 -1 1 -1",
"output": "4"
},
{
"input": "4\n100 -100 100 -100",
"output": "400"
},
{
"input": "3\n-2 -5 10",
"output": "17"
},
{
"input": "5\n1 -2 3 -4 5",
"output": "15"
},
{
"input": "3\n-100 100 -100",
"output": "300"
},
{
"input": "6\n1 -1 1 -1 1 -1",
"output": "6"
},
{
"input": "6\n2 -2 2 -2 2 -2",
"output": "12"
},
{
"input": "9\n12 93 -2 0 0 0 3 -3 -9",
"output": "122"
},
{
"input": "6\n-1 2 4 -5 -3 55",
"output": "70"
},
{
"input": "6\n-12 8 68 -53 1 -15",
"output": "157"
},
{
"input": "2\n-2 1",
"output": "3"
},
{
"input": "3\n100 -100 100",
"output": "300"
},
{
"input": "5\n100 100 -1 -100 2",
"output": "303"
},
{
"input": "6\n-5 -4 -3 -2 -1 0",
"output": "15"
},
{
"input": "6\n4 4 4 -3 -3 2",
"output": "20"
},
{
"input": "2\n-1 2",
"output": "3"
},
{
"input": "1\n100",
"output": "100"
},
{
"input": "5\n-1 -2 3 1 2",
"output": "9"
},
{
"input": "5\n100 -100 100 -100 100",
"output": "500"
},
{
"input": "5\n1 -1 1 -1 1",
"output": "5"
},
{
"input": "4\n0 0 0 -1",
"output": "1"
},
{
"input": "5\n100 -100 -1 2 100",
"output": "303"
},
{
"input": "2\n75 0",
"output": "75"
},
{
"input": "4\n55 56 -59 -58",
"output": "228"
},
{
"input": "2\n9 71",
"output": "80"
},
{
"input": "2\n9 70",
"output": "79"
},
{
"input": "2\n9 69",
"output": "78"
},
{
"input": "2\n100 -100",
"output": "200"
},
{
"input": "4\n-9 4 -9 5",
"output": "27"
},
{
"input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36",
"output": "2348"
},
{
"input": "7\n-1 2 2 2 -1 2 -1",
"output": "11"
},
{
"input": "6\n-12 8 17 -69 7 -88",
"output": "201"
},
{
"input": "3\n1 -2 5",
"output": "8"
},
{
"input": "6\n-2 3 -4 5 6 -1",
"output": "21"
},
{
"input": "2\n-5 1",
"output": "6"
},
{
"input": "4\n2 2 -2 4",
"output": "10"
},
{
"input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72",
"output": "3991"
},
{
"input": "5\n5 5 -10 -1 1",
"output": "22"
},
{
"input": "3\n-1 2 3",
"output": "6"
},
{
"input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1",
"output": "3787"
},
{
"input": "5\n-1 -2 1 2 3",
"output": "9"
},
{
"input": "4\n2 2 -2 -2",
"output": "8"
},
{
"input": "6\n100 -100 100 -100 100 -100",
"output": "600"
},
{
"input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41",
"output": "4362"
},
{
"input": "2\n-1 1",
"output": "2"
},
{
"input": "3\n1 -2 100",
"output": "103"
},
{
"input": "5\n1 -2 3 1 2",
"output": "9"
},
{
"input": "10\n100 -10 -100 10 10 10 10 10 10 10",
"output": "280"
},
{
"input": "4\n2 0 -2 4",
"output": "8"
},
{
"input": "4\n3 -3 1 -1",
"output": "8"
},
{
"input": "3\n1 -1 1",
"output": "3"
},
{
"input": "4\n2 5 -2 4",
"output": "13"
},
{
"input": "2\n-2 2",
"output": "4"
},
{
"input": "3\n1 -2 1",
"output": "4"
},
{
"input": "5\n-1 -2 1 1 -1",
"output": "6"
},
{
"input": "4\n-2 0 2 4",
"output": "8"
},
{
"input": "8\n-42 7 87 -16 -5 65 -88 1",
"output": "311"
},
{
"input": "3\n1 -3 4",
"output": "8"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "3\n-1 2 -1",
"output": "4"
},
{
"input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95",
"output": "761"
},
{
"input": "4\n-1 1 -1 1",
"output": "4"
},
{
"input": "5\n-1 2 1 1 1",
"output": "6"
},
{
"input": "3\n1 1 1",
"output": "3"
}
] | 1,642,390,256 | 2,147,483,647 | PyPy 3 | OK | TESTS | 72 | 155 | 3,481,600 | import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n=int(input())
l=sorted([int(i) for i in input().split()])
if(l[0]>=0):
print(sum(l))
else:
s1,s2=0,0
for i in range(n):
if(l[i]<0):
s1+=l[i]
else:
s2+=l[i]
print(s2-s1) | Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Output Specification:
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
Demo Input:
['3\n1 -2 0\n', '6\n16 23 16 15 42 8\n']
Demo Output:
['3\n', '120\n']
Note:
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | ```python
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n=int(input())
l=sorted([int(i) for i in input().split()])
if(l[0]>=0):
print(sum(l))
else:
s1,s2=0,0
for i in range(n):
if(l[i]<0):
s1+=l[i]
else:
s2+=l[i]
print(s2-s1)
``` | 3 |
|
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color. | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n#.#.\n#.#.",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n#.#.\n.#.#",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n#.#.\n#.#.",
"output": "NO"
},
{
"input": ".#.#\n.#.#\n.#.#\n.#.#",
"output": "NO"
},
{
"input": "#..#\n.##.\n####\n####",
"output": "YES"
},
{
"input": "#.#.\n.###\n#.#.\n.###",
"output": "YES"
},
{
"input": "#..#\n.##.\n.##.\n#..#",
"output": "YES"
},
{
"input": ".##.\n.#..\n##.#\n#..#",
"output": "YES"
},
{
"input": ".##.\n##..\n#..#\n..##",
"output": "YES"
},
{
"input": "##..\n##..\n..##\n..##",
"output": "YES"
},
{
"input": ".#..\n###.\n.#.#\n..#.",
"output": "YES"
},
{
"input": "###.\n###.\n...#\n...#",
"output": "YES"
},
{
"input": "#.##\n##.#\n#.##\n##.#",
"output": "YES"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.##",
"output": "YES"
},
{
"input": "##..\n..##\n##..\n...#",
"output": "YES"
},
{
"input": ".#..\n..##\n##..\n..##",
"output": "YES"
},
{
"input": "##..\n...#\n##..\n...#",
"output": "YES"
},
{
"input": ".#..\n..#.\n.#..\n..#.",
"output": "YES"
},
{
"input": "....\n....\n....\n.#.#",
"output": "YES"
},
{
"input": "....\n....\n....\n...#",
"output": "YES"
}
] | 1,589,972,216 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 140 | 0 | def iq_test():
maze = []
for i in range(4):
maze.append(input())
for i in range(len(maze) - 1):
for j in range(len(maze[i]) - 1):
dic = {'#': 0, '.': 0}
dic[maze[i][j]] += 1
dic[maze[i + 1][j]] += 1
dic[maze[i + 1][j + 1]] += 1
dic[maze[i][j + 1]] += 1
if dic['#'] >= 3:
return 'YES'
elif dic['.'] >= 3:
return 'YES'
return 'NO'
print(iq_test()) | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color.
Input Specification:
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Output Specification:
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Demo Input:
['####\n.#..\n####\n....\n', '####\n....\n####\n....\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | ```python
def iq_test():
maze = []
for i in range(4):
maze.append(input())
for i in range(len(maze) - 1):
for j in range(len(maze[i]) - 1):
dic = {'#': 0, '.': 0}
dic[maze[i][j]] += 1
dic[maze[i + 1][j]] += 1
dic[maze[i + 1][j + 1]] += 1
dic[maze[i][j + 1]] += 1
if dic['#'] >= 3:
return 'YES'
elif dic['.'] >= 3:
return 'YES'
return 'NO'
print(iq_test())
``` | 3 |
|
429 | A | Xor-tree | PROGRAMMING | 1,300 | [
"dfs and similar",
"trees"
] | null | null | Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on.
The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*.
The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). | In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. | [
"10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n"
] | [
"2\n4\n7\n"
] | none | 500 | [
{
"input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1",
"output": "2\n4\n7"
},
{
"input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0",
"output": "7\n1\n4\n7\n8\n9\n11\n13"
},
{
"input": "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13 2\n14 12\n15 14\n16 8\n17 9\n18 13\n19 2\n20 17\n1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0\n1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1",
"output": "8\n11\n15\n17\n20\n10\n18\n19\n7"
},
{
"input": "30\n2 1\n3 2\n4 3\n5 3\n6 5\n7 3\n8 3\n9 2\n10 3\n11 2\n12 11\n13 6\n14 4\n15 5\n16 11\n17 9\n18 14\n19 6\n20 2\n21 19\n22 9\n23 19\n24 20\n25 14\n26 22\n27 1\n28 6\n29 13\n30 27\n1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0\n0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0",
"output": "15\n1\n2\n4\n5\n6\n13\n29\n19\n21\n23\n28\n7\n22\n26\n30"
},
{
"input": "15\n2 1\n3 1\n4 1\n5 1\n6 3\n7 1\n8 1\n9 1\n10 5\n11 9\n12 3\n13 5\n14 5\n15 4\n1 1 0 0 0 0 1 1 1 0 1 1 1 0 0\n1 0 1 1 0 1 1 1 1 1 1 1 1 1 0",
"output": "6\n2\n3\n6\n4\n10\n14"
},
{
"input": "20\n2 1\n3 1\n4 2\n5 2\n6 3\n7 1\n8 6\n9 2\n10 3\n11 6\n12 2\n13 3\n14 2\n15 1\n16 8\n17 15\n18 2\n19 14\n20 14\n0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1\n0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0",
"output": "10\n2\n4\n19\n18\n8\n16\n11\n10\n13\n7"
},
{
"input": "23\n2 1\n3 2\n4 1\n5 1\n6 5\n7 3\n8 2\n9 8\n10 5\n11 6\n12 9\n13 3\n14 11\n15 5\n16 2\n17 3\n18 10\n19 16\n20 14\n21 19\n22 17\n23 7\n0 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1",
"output": "8\n2\n23\n13\n17\n9\n4\n11\n20"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "10\n1 10\n1 9\n10 2\n10 3\n3 7\n3 8\n9 4\n9 5\n5 6\n1 0 1 1 0 1 0 1 0 1\n0 0 0 0 0 0 0 0 0 0",
"output": "6\n1\n10\n2\n7\n5\n6"
}
] | 1,648,229,830 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 12 | 951 | 66,764,800 | n = int(input())
edges = [set() for _ in range(n)]
for _ in range(n - 1):
u, v = [int(i) - 1 for i in input().split()]
edges[u].add(v)
edges[v].add(u)
inits = [int(i) for i in input().split()]
goals = [int(i) for i in input().split()]
require_change = set()
for index, init, goal in zip(range(n), inits, goals):
if init != goal:
require_change.add(index)
results = []
discovered = set()
def discover(index: int, state: bool = True, first_state: bool = True) -> None:
if index in discovered:
return
discovered.add(index)
if any((state and index in require_change, not state and index not in require_change)):
results.append(index)
next_state = not state
else:
next_state = state
for edge in edges[index]:
discover(edge, first_state, next_state)
discover(0)
print(len(results))
print("\n".join(str(r + 1) for r in results))
| Title: Xor-tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on.
The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*.
The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
Output Specification:
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
Demo Input:
['10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n']
Demo Output:
['2\n4\n7\n']
Note:
none | ```python
n = int(input())
edges = [set() for _ in range(n)]
for _ in range(n - 1):
u, v = [int(i) - 1 for i in input().split()]
edges[u].add(v)
edges[v].add(u)
inits = [int(i) for i in input().split()]
goals = [int(i) for i in input().split()]
require_change = set()
for index, init, goal in zip(range(n), inits, goals):
if init != goal:
require_change.add(index)
results = []
discovered = set()
def discover(index: int, state: bool = True, first_state: bool = True) -> None:
if index in discovered:
return
discovered.add(index)
if any((state and index in require_change, not state and index not in require_change)):
results.append(index)
next_state = not state
else:
next_state = state
for edge in edges[index]:
discover(edge, first_state, next_state)
discover(0)
print(len(results))
print("\n".join(str(r + 1) for r in results))
``` | -1 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,567,751,717 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 248 | 0 | n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
if(a[i]%2==0):
o.append(i)
else:
e.append(i)
print(e[0]+1) if(len(e)==1) else print(o[0]+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
if(a[i]%2==0):
o.append(i)
else:
e.append(i)
print(e[0]+1) if(len(e)==1) else print(o[0]+1)
``` | 3.938 |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number. | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell. | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs. | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSDDSDSDS\nSSDDDDDDDS"
},
{
"input": "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....\nS..S...S.S\n...WWW..S.\n..S..S.S.S\nSS.......S",
"output": "No"
},
{
"input": "1 50\nW...S..............W.....S..S...............S...W.",
"output": "Yes\nWDDDSDDDDDDDDDDDDDDWDDDDDSDDSDDDDDDDDDDDDDDDSDDDWD"
},
{
"input": "2 4\n...S\n...W",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nSW",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nWS",
"output": "No"
},
{
"input": "2 4\n...W\n...S",
"output": "No"
},
{
"input": "50 1\nS\n.\n.\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\n.\nS\n.\nW\n.\nS\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\nW\n.\n.\n.\nW\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "Yes\nS\nD\nD\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nD\nS\nD\nW\nD\nS\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nW\nD\nD\nD\nW\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD"
},
{
"input": "4 4\nW..S\nW..S\nW..S\nW..S",
"output": "Yes\nWDDS\nWDDS\nWDDS\nWDDS"
},
{
"input": "4 4\nSSSS\n....\n....\nWWWW",
"output": "Yes\nSSSS\nDDDD\nDDDD\nWWWW"
},
{
"input": "4 4\nWWWW\n....\n....\nSSSS",
"output": "Yes\nWWWW\nDDDD\nDDDD\nSSSS"
},
{
"input": "4 4\nS..W\nS..W\nS..W\nS..W",
"output": "Yes\nSDDW\nSDDW\nSDDW\nSDDW"
},
{
"input": "1 1\n.",
"output": "Yes\nD"
},
{
"input": "1 1\nW",
"output": "Yes\nW"
},
{
"input": "1 1\nS",
"output": "Yes\nS"
},
{
"input": "4 2\n..\n..\n.W\n.S",
"output": "No"
},
{
"input": "4 2\n..\n..\n.S\n.W",
"output": "No"
},
{
"input": "4 2\n..\n..\nW.\nS.",
"output": "No"
},
{
"input": "4 2\n..\n..\nS.\nW.",
"output": "No"
},
{
"input": "2 4\n....\n..SW",
"output": "No"
},
{
"input": "2 4\n....\n..WS",
"output": "No"
},
{
"input": "1 2\nS.",
"output": "Yes\nSD"
}
] | 1,529,071,755 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 1,638,400 | def bfs(arr):
visited = [[False]*len(arr[0]) for i in range(len(arr))]
q = []
q.append((0, 0))
visited[0][0] = True
neighbors = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while len(q) != 0:
nextLevel = []
for i, j in q:
for dx, dy in neighbors:
x = dx + i
y = dy + j
if 0 <= x < len(arr) and 0 <= y < len(arr[0]) and not visited[x][y]:
visited[x][y] = True
nextLevel.append((x, y))
if 0 <= x < len(arr) and 0 <= y < len(arr[0]) and arr[i][j] == 'S' and arr[x][y] == 'W':
return 'No'
q = nextLevel
return 'Yes'
r, c = map(int, input().split())
# r = 2
# c = 10
# arr = ['DDDWDDDDDS',
# 'DSDSDDDSDD']
arr = []
for i in range(r):
arr.append(input().replace('.' ,'D'))
answer = bfs(arr)
print(answer)
if answer == 'Yes':
for i in range(r):
print(arr[i])
| Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number.
Input Specification:
First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.
Output Specification:
If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.
Demo Input:
['6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n', '1 2\nSW\n', '5 5\n.S...\n...S.\nS....\n...S.\n.S...\n']
Demo Output:
['Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n', 'No\n', 'Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n']
Note:
In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | ```python
def bfs(arr):
visited = [[False]*len(arr[0]) for i in range(len(arr))]
q = []
q.append((0, 0))
visited[0][0] = True
neighbors = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while len(q) != 0:
nextLevel = []
for i, j in q:
for dx, dy in neighbors:
x = dx + i
y = dy + j
if 0 <= x < len(arr) and 0 <= y < len(arr[0]) and not visited[x][y]:
visited[x][y] = True
nextLevel.append((x, y))
if 0 <= x < len(arr) and 0 <= y < len(arr[0]) and arr[i][j] == 'S' and arr[x][y] == 'W':
return 'No'
q = nextLevel
return 'Yes'
r, c = map(int, input().split())
# r = 2
# c = 10
# arr = ['DDDWDDDDDS',
# 'DSDSDDDSDD']
arr = []
for i in range(r):
arr.append(input().replace('.' ,'D'))
answer = bfs(arr)
print(answer)
if answer == 'Yes':
for i in range(r):
print(arr[i])
``` | 0 |
|
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation. | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{
"input": "10 6 3",
"output": "<< 3 4 5 (6) 7 8 9 >> "
},
{
"input": "8 5 4",
"output": "1 2 3 4 (5) 6 7 8 "
},
{
"input": "100 10 20",
"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 >> "
},
{
"input": "100 25 11",
"output": "<< 14 15 16 17 18 19 20 21 22 23 24 (25) 26 27 28 29 30 31 32 33 34 35 36 >> "
},
{
"input": "5 2 1",
"output": "1 (2) 3 >> "
},
{
"input": "5 3 1",
"output": "<< 2 (3) 4 >> "
},
{
"input": "79 35 12",
"output": "<< 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 >> "
},
{
"input": "100 99 5",
"output": "<< 94 95 96 97 98 (99) 100 "
},
{
"input": "100 99 15",
"output": "<< 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 (99) 100 "
},
{
"input": "100 100 17",
"output": "<< 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 (100) "
},
{
"input": "100 35 28",
"output": "<< 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 >> "
},
{
"input": "100 46 38",
"output": "<< 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 >> "
},
{
"input": "100 46 48",
"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 >> "
},
{
"input": "100 10 100",
"output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3 1 1",
"output": "(1) 2 >> "
},
{
"input": "3 2 1",
"output": "1 (2) 3 "
},
{
"input": "17 5 3",
"output": "<< 2 3 4 (5) 6 7 8 >> "
},
{
"input": "3 1 3",
"output": "(1) 2 3 "
},
{
"input": "7 5 1",
"output": "<< 4 (5) 6 >> "
},
{
"input": "5 5 5",
"output": "1 2 3 4 (5) "
},
{
"input": "5 3 5",
"output": "1 2 (3) 4 5 "
}
] | 1,585,235,351 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 155 | 0 | x=input()
xx=x.split( )
n=int(xx[0])
p=int(xx[1])
k=int(xx[2])
if p-k<=1:
kk=p-1
while kk!=0:
print(p-kk,end=' ')
kk-=1
else:
kk=k
print('<<',end=' ')
while kk!=0:
print(p-kk,end=' ')
kk-=1
print('(',end='')
print(p,end='')
print(')',end=' ')
if p+k>=n:
kk=n-p
for i in range(1,kk+1):
print(p+i,end=' ')
else:
kk=k
for i in range(1,kk+1):
print(p+i,end=' ')
print('>>')
| Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input Specification:
The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*)
Output Specification:
Print the proper navigation. Follow the format of the output from the test samples.
Demo Input:
['17 5 2\n', '6 5 2\n', '6 1 2\n', '6 2 2\n', '9 6 3\n', '10 6 3\n', '8 5 4\n']
Demo Output:
['<< 3 4 (5) 6 7 >> ', '<< 3 4 (5) 6 ', '(1) 2 3 >> ', '1 (2) 3 4 >>', '<< 3 4 5 (6) 7 8 9', '<< 3 4 5 (6) 7 8 9 >>', '1 2 3 4 (5) 6 7 8 ']
Note:
none | ```python
x=input()
xx=x.split( )
n=int(xx[0])
p=int(xx[1])
k=int(xx[2])
if p-k<=1:
kk=p-1
while kk!=0:
print(p-kk,end=' ')
kk-=1
else:
kk=k
print('<<',end=' ')
while kk!=0:
print(p-kk,end=' ')
kk-=1
print('(',end='')
print(p,end='')
print(')',end=' ')
if p+k>=n:
kk=n-p
for i in range(1,kk+1):
print(p+i,end=' ')
else:
kk=k
for i in range(1,kk+1):
print(p+i,end=' ')
print('>>')
``` | 3 |
|
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,567,625,026 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 155 | 0 | #encoding: utf-8
n = int(input())
digits_number = 0
power_10 = 1
while power_10 <= n:
digits_number += n - (power_10 - 1)
power_10 *= 10
print(digits_number) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
#encoding: utf-8
n = int(input())
digits_number = 0
power_10 = 1
while power_10 <= n:
digits_number += n - (power_10 - 1)
power_10 *= 10
print(digits_number)
``` | 3 |
|
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,635,104,816 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 4,300,800 | # -*- coding: utf-8 -*-
"""
Created on Sun Oct 24 15:39:01 2021
@author: Nikiq
"""
s = input()
s = s[::-1]
#[::-1] reverses a string, s.reverse() reverses a list
#print(s)
n = input()
if s == n:
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
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 24 15:39:01 2021
@author: Nikiq
"""
s = input()
s = s[::-1]
#[::-1] reverses a string, s.reverse() reverses a list
#print(s)
n = input()
if s == n:
print("YES")
else:
print("NO")
``` | 3.968989 |
0 | none | none | none | 0 | [
"none"
] | null | null | Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* with substrings equal to *t**i*". For example, if *s*<==<=123123, then query "2<=→<=00" transforms *s* to 10031003, and query "3<=→<=" ("replace 3 by an empty string") transforms it to *s*<==<=1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to *s* by 1000000007 (109<=+<=7). When you represent *s* as a decimal number, please ignore the leading zeroes; also if *s* is an empty string, then it's assumed that the number equals to zero.
Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him! | The first line contains string *s* (1<=≤<=|*s*|<=≤<=105), consisting of digits — the string before processing all the requests.
The second line contains a single integer *n* (0<=≤<=*n*<=≤<=105) — the number of queries.
The next *n* lines contain the descriptions of the queries. The *i*-th query is described by string "*d**i*->*t**i*", where *d**i* is exactly one digit (from 0 to 9), *t**i* is a string consisting of digits (*t**i* can be an empty string). The sum of lengths of *t**i* for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed. | Print a single integer — remainder of division of the resulting number by 1000000007 (109<=+<=7). | [
"123123\n1\n2->00\n",
"123123\n1\n3->\n",
"222\n2\n2->0\n0->7\n",
"1000000008\n0\n"
] | [
"10031003\n",
"1212\n",
"777\n",
"1\n"
] | Note that the leading zeroes are not removed from string *s* after the replacement (you can see it in the third sample). | 0 | [
{
"input": "123123\n1\n2->00",
"output": "10031003"
},
{
"input": "123123\n1\n3->",
"output": "1212"
},
{
"input": "222\n2\n2->0\n0->7",
"output": "777"
},
{
"input": "1000000008\n0",
"output": "1"
},
{
"input": "100\n5\n1->301\n0->013\n1->013\n0->103\n0->103",
"output": "624761980"
},
{
"input": "21222\n10\n1->\n2->1\n1->1\n1->1\n1->1\n1->22\n2->2\n2->1\n1->21\n1->",
"output": "22222222"
},
{
"input": "21122\n10\n1->\n2->12\n1->\n2->21\n2->\n1->21\n1->\n2->12\n2->\n1->21",
"output": "212121"
},
{
"input": "7048431802\n3\n0->9285051\n0->785476659\n6->3187205",
"output": "106409986"
},
{
"input": "1\n10\n1->111\n1->111\n1->111\n1->111\n1->111\n1->111\n1->111\n1->111\n1->111\n1->111",
"output": "97443114"
},
{
"input": "80125168586785605523636285409060490408816122518314\n0",
"output": "410301862"
},
{
"input": "4432535330257407726572090980499847187198996038948464049414107600178053433384837707125968777715401617\n10\n1->\n3->\n5->\n2->\n9->\n0->\n4->\n6->\n7->\n8->",
"output": "0"
},
{
"input": "332434109630379\n20\n7->1\n0->2\n3->6\n1->8\n6->8\n4->0\n9->8\n2->4\n4->8\n0->1\n1->7\n7->3\n3->4\n4->6\n6->3\n8->4\n3->8\n4->2\n2->8\n8->1",
"output": "110333334"
},
{
"input": "88296041076454194379\n20\n5->62\n8->48\n4->\n1->60\n9->00\n6->16\n0->03\n6->\n3->\n1->\n7->02\n2->35\n8->86\n5->\n3->34\n4->\n8->\n0->\n3->46\n6->84",
"output": "425093096"
},
{
"input": "19693141406182378241404307417907800263629336520110\n49\n2->\n0->\n3->\n9->\n6->\n5->\n1->\n4->\n8->\n7->0649713852\n0->\n4->\n5->\n3->\n1->\n8->\n7->\n9->\n6->\n2->2563194780\n0->\n8->\n1->\n3->\n5->\n4->\n7->\n2->\n6->\n9->8360512479\n0->\n3->\n6->\n4->\n2->\n9->\n7->\n1->\n8->\n5->8036451792\n7->\n6->\n5->\n1->\n2->\n0->\n8->\n9->\n4->",
"output": "3333"
}
] | 1,410,110,831 | 7,031 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 1,000 | 204,800 | a = input()
if a == "":
num = 0
else:
num = str(int(a))
n = int(input())
for x in range(n):
old, new = input().split('->')
while True:
onum = num
num = onum.replace(old, new)
if(onum == num):
break
print((int(num) + 1000000007) % 1000000007)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* with substrings equal to *t**i*". For example, if *s*<==<=123123, then query "2<=→<=00" transforms *s* to 10031003, and query "3<=→<=" ("replace 3 by an empty string") transforms it to *s*<==<=1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to *s* by 1000000007 (109<=+<=7). When you represent *s* as a decimal number, please ignore the leading zeroes; also if *s* is an empty string, then it's assumed that the number equals to zero.
Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him!
Input Specification:
The first line contains string *s* (1<=≤<=|*s*|<=≤<=105), consisting of digits — the string before processing all the requests.
The second line contains a single integer *n* (0<=≤<=*n*<=≤<=105) — the number of queries.
The next *n* lines contain the descriptions of the queries. The *i*-th query is described by string "*d**i*->*t**i*", where *d**i* is exactly one digit (from 0 to 9), *t**i* is a string consisting of digits (*t**i* can be an empty string). The sum of lengths of *t**i* for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed.
Output Specification:
Print a single integer — remainder of division of the resulting number by 1000000007 (109<=+<=7).
Demo Input:
['123123\n1\n2->00\n', '123123\n1\n3->\n', '222\n2\n2->0\n0->7\n', '1000000008\n0\n']
Demo Output:
['10031003\n', '1212\n', '777\n', '1\n']
Note:
Note that the leading zeroes are not removed from string *s* after the replacement (you can see it in the third sample). | ```python
a = input()
if a == "":
num = 0
else:
num = str(int(a))
n = int(input())
for x in range(n):
old, new = input().split('->')
while True:
onum = num
num = onum.replace(old, new)
if(onum == num):
break
print((int(num) + 1000000007) % 1000000007)
``` | 0 |
|
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order. | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 1,599,526,919 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 140 | 0 | x=int(input())
first=[]
second=[]
for i in range(x):
y=int(input())
if y>0:
first.append(y)
else:
second.append(y)
sumf=sum(first)
sums=sum(second)
if abs(sumf)>abs(sums):
print("first")
elif abs(sums)>abs(sumf):
print("second")
else:
if y>0:
print("first")
else:
print("second")
| Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input Specification:
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
Output Specification:
If the first wrestler wins, print string "first", otherwise print "second"
Demo Input:
['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n']
Demo Output:
['second\n', 'first\n', 'second\n']
Note:
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | ```python
x=int(input())
first=[]
second=[]
for i in range(x):
y=int(input())
if y>0:
first.append(y)
else:
second.append(y)
sumf=sum(first)
sums=sum(second)
if abs(sumf)>abs(sums):
print("first")
elif abs(sums)>abs(sumf):
print("second")
else:
if y>0:
print("first")
else:
print("second")
``` | 0 |
|
463 | C | Gargari and Bishops | PROGRAMMING | 1,900 | [
"greedy",
"hashing",
"implementation"
] | null | null | Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard. | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right.
If there are several optimal solutions, you can print any of them. | [
"4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n"
] | [
"12\n2 2 3 2\n"
] | none | 1,500 | [
{
"input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1",
"output": "12\n2 2 3 2"
},
{
"input": "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 79 51\n93 66 53 39 89 30 16 27 63 93",
"output": "2242\n6 6 7 6"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0",
"output": "0\n1 1 1 2"
},
{
"input": "15\n2 6 9 4 8 9 10 10 3 8 8 4 4 8 7\n10 9 2 6 8 10 5 2 8 4 9 6 9 10 10\n3 1 5 1 6 5 1 6 4 4 3 3 9 8 10\n5 7 10 6 4 9 6 8 1 5 4 9 10 4 8\n9 6 10 5 8 6 9 9 3 4 4 7 6 2 4\n8 6 10 7 3 3 8 10 3 8 4 8 8 3 1\n7 3 6 8 8 5 5 8 3 7 2 6 3 9 7\n6 8 4 7 7 7 10 4 6 4 3 10 1 10 2\n1 6 7 8 3 4 2 8 1 7 4 4 4 9 5\n3 4 4 6 1 10 2 2 5 8 7 7 7 7 6\n10 9 3 6 8 6 1 9 5 4 7 10 7 1 8\n3 3 4 9 8 6 10 2 9 5 9 5 3 7 3\n1 8 1 3 4 8 10 4 8 4 7 5 4 6 7\n3 10 9 6 8 8 1 8 9 9 4 9 5 6 5\n7 6 3 9 9 8 6 10 3 6 4 2 10 9 7",
"output": "361\n7 9 9 8"
},
{
"input": "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5",
"output": "159\n4 4 5 4"
},
{
"input": "13\n9 9 3 3 5 6 8 2 6 1 10 3 8\n10 4 9 2 10 3 5 10 10 7 10 7 3\n5 8 4 1 10 2 1 2 4 7 9 1 10\n6 3 10 10 10 1 3 10 4 4 2 10 4\n1 7 5 7 9 9 7 4 1 8 5 4 1\n10 10 9 2 2 6 4 1 5 5 1 9 4\n4 2 5 5 7 8 1 2 6 1 2 4 6\n5 1 10 8 1 1 9 1 2 10 6 7 2\n2 1 2 10 4 7 4 1 4 10 10 4 3\n7 7 5 1 2 1 1 4 8 2 4 8 2\n8 8 8 4 1 1 7 3 1 10 1 4 2\n4 5 1 10 8 8 8 4 10 9 4 10 4\n3 1 10 10 5 7 9 4 2 10 4 8 4",
"output": "280\n6 6 7 6"
},
{
"input": "9\n3 9 6 1 7 6 2 8 4\n5 4 1 1 7 2 7 4 10\n7 9 9 4 6 2 7 2 8\n5 7 7 4 9 5 9 1 3\n7 3 10 2 9 4 2 1 2\n5 8 7 4 6 6 2 2 3\n4 8 4 3 4 2 1 8 10\n5 8 2 8 4 4 7 5 4\n2 8 7 4 3 6 10 8 1",
"output": "181\n5 4 6 4"
}
] | 1,589,892,271 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 1,028 | 31,334,400 | import sys
input=sys.stdin.buffer.readline
def d3(i,j,a):
n=len(a)
i1,j1=i-1,j-1
a[i][j]=0
while j1>=0 and i1>=0:
a[i1][j1]=0
i1-=1
j1-=1
i1,j1=i+1,j+1
while i1<n and j1<n:
a[i1][j1]=0
i1+=1
j1+=1
def d4(i,j,a):
n=len(a)
i1,j1=i-1,j+1
while i1>=0 and j1<n:
a[i1][j1]=0
i1-=1
j1+=1
i1,j1=i+1,j-1
while i1<n and j1>=0:
a[i1][j1]=0
i1+=1
j1-=1
t=1
for __ in range(t):
a=[]
n=int(input())
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
dr={}
di={}
for i in range(n):
for j in range(n):
dr[i+j]=dr.get(i+j,0)+a[i][j]
di[i+n-j+1]=di.get(i+n-j+1,0)+a[i][j]
ind_i,ind_j=-1,-1
maxi=0
for i in range(n):
for j in range(n):
if maxi<(dr[i+j]+di[i+n-j+1]-a[i][j]):
maxi=(dr[i+j]+di[i+n-j+1]-a[i][j])
ind_i=i
ind_j=j
d3(ind_i,ind_j,a)
d4(ind_i,ind_j,a)
dr={}
di={}
for i in range(n):
for j in range(n):
dr[i+j]=dr.get(i+j,0)+a[i][j]
di[i+n-j+1]=di.get(i+n-j+1,0)+a[i][j]
ind_i1,ind_j1=-1,-1
maxi1=0
for i in range(n):
for j in range(n):
if maxi1<(dr[i+j]+di[i+n-j+1]-a[i][j]):
maxi1=(dr[i+j]+di[i+n-j+1]-a[i][j])
ind_i1=i
ind_j1=j
print(maxi+maxi1)
print(ind_i+1,ind_j+1,ind_i1+1,ind_j1+1) | Title: Gargari and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard.
Output Specification:
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right.
If there are several optimal solutions, you can print any of them.
Demo Input:
['4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n']
Demo Output:
['12\n2 2 3 2\n']
Note:
none | ```python
import sys
input=sys.stdin.buffer.readline
def d3(i,j,a):
n=len(a)
i1,j1=i-1,j-1
a[i][j]=0
while j1>=0 and i1>=0:
a[i1][j1]=0
i1-=1
j1-=1
i1,j1=i+1,j+1
while i1<n and j1<n:
a[i1][j1]=0
i1+=1
j1+=1
def d4(i,j,a):
n=len(a)
i1,j1=i-1,j+1
while i1>=0 and j1<n:
a[i1][j1]=0
i1-=1
j1+=1
i1,j1=i+1,j-1
while i1<n and j1>=0:
a[i1][j1]=0
i1+=1
j1-=1
t=1
for __ in range(t):
a=[]
n=int(input())
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
dr={}
di={}
for i in range(n):
for j in range(n):
dr[i+j]=dr.get(i+j,0)+a[i][j]
di[i+n-j+1]=di.get(i+n-j+1,0)+a[i][j]
ind_i,ind_j=-1,-1
maxi=0
for i in range(n):
for j in range(n):
if maxi<(dr[i+j]+di[i+n-j+1]-a[i][j]):
maxi=(dr[i+j]+di[i+n-j+1]-a[i][j])
ind_i=i
ind_j=j
d3(ind_i,ind_j,a)
d4(ind_i,ind_j,a)
dr={}
di={}
for i in range(n):
for j in range(n):
dr[i+j]=dr.get(i+j,0)+a[i][j]
di[i+n-j+1]=di.get(i+n-j+1,0)+a[i][j]
ind_i1,ind_j1=-1,-1
maxi1=0
for i in range(n):
for j in range(n):
if maxi1<(dr[i+j]+di[i+n-j+1]-a[i][j]):
maxi1=(dr[i+j]+di[i+n-j+1]-a[i][j])
ind_i1=i
ind_j1=j
print(maxi+maxi1)
print(ind_i+1,ind_j+1,ind_i1+1,ind_j1+1)
``` | 0 |
|
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that:
- there wouldn't be a pair of any side-adjacent cards with zeroes in a row; - there wouldn't be a group of three consecutive cards containing numbers one.
Today Vanya brought *n* cards with zeroes and *m* cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "74 99",
"output": "11011011011011011011011011011011011011011011011011011011011011011011011010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"input": "19 30",
"output": "1101101101101101101101101101101010101010101010101"
},
{
"input": "33 77",
"output": "-1"
},
{
"input": "3830 6966",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "1000000 1000000",
"output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..."
},
{
"input": "1027 2030",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "4610 4609",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "3342 3339",
"output": "-1"
},
{
"input": "7757 7755",
"output": "-1"
},
{
"input": "10 8",
"output": "-1"
},
{
"input": "4247 8495",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "7101 14204",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "9801 19605",
"output": "-1"
},
{
"input": "4025 6858",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "7129 13245",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "8826 12432",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "6322 9256",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "8097 14682",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "6196 6197",
"output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..."
},
{
"input": "1709 2902",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "455 512",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..."
},
{
"input": "1781 1272",
"output": "-1"
},
{
"input": "3383 5670",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "954 1788",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "9481 15554",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "9079 100096",
"output": "-1"
},
{
"input": "481533 676709",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "423472 564888",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "227774 373297",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "42346 51898",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "739107 1000000",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "455043 798612",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "801460 801459",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "303498 503791",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "518822 597833",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "32342 64687",
"output": "-1"
},
{
"input": "873192 873189",
"output": "-1"
},
{
"input": "384870 450227",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "201106 208474",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "775338 980888",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "263338 393171",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "241043 330384",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "307203 614408",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "379310 417986",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "661101 785111",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "284634 319008",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "500000 1000000",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "499999 1000000",
"output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..."
},
{
"input": "3 1",
"output": "-1"
},
{
"input": "14124 242112",
"output": "-1"
},
{
"input": "2 1",
"output": "010"
},
{
"input": "2 3",
"output": "10101"
},
{
"input": "1 4",
"output": "11011"
},
{
"input": "2 6",
"output": "11011011"
},
{
"input": "2 5",
"output": "1101101"
},
{
"input": "2 4",
"output": "110101"
},
{
"input": "2 3",
"output": "10101"
},
{
"input": "2 2",
"output": "1010"
},
{
"input": "2 1",
"output": "010"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1 3",
"output": "1101"
},
{
"input": "3 2",
"output": "01010"
},
{
"input": "5 4",
"output": "010101010"
},
{
"input": "4 3",
"output": "0101010"
},
{
"input": "11 10",
"output": "010101010101010101010"
},
{
"input": "8 7",
"output": "010101010101010"
},
{
"input": "4 2",
"output": "-1"
},
{
"input": "6 5",
"output": "01010101010"
},
{
"input": "3 7",
"output": "1101101101"
},
{
"input": "5 1",
"output": "-1"
},
{
"input": "10 1",
"output": "-1"
},
{
"input": "4 9",
"output": "1101101101101"
},
{
"input": "6 4",
"output": "-1"
},
{
"input": "12 10",
"output": "-1"
},
{
"input": "4 100",
"output": "-1"
}
] | 1,590,317,521 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 248 | 6,963,200 | import math
test = 1
for tes in range(test):
n,m=list(map(int, input().split()))
if m>=2*n:
m = m-2*n
if(m>2):
print(-1)
continue
print('110'*n + '1'*m)
else:
print('110'*(m-n)+'10'*(2*n-m))
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that:
- there wouldn't be a pair of any side-adjacent cards with zeroes in a row; - there wouldn't be a group of three consecutive cards containing numbers one.
Today Vanya brought *n* cards with zeroes and *m* cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
Input Specification:
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1.
Output Specification:
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
Demo Input:
['1 2\n', '4 8\n', '4 10\n', '1 5\n']
Demo Output:
['101\n', '110110110101\n', '11011011011011\n', '-1\n']
Note:
none | ```python
import math
test = 1
for tes in range(test):
n,m=list(map(int, input().split()))
if m>=2*n:
m = m-2*n
if(m>2):
print(-1)
continue
print('110'*n + '1'*m)
else:
print('110'*(m-n)+'10'*(2*n-m))
``` | 0 |
|
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,698,967,597 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
z = list(map(int,input().split()))
ans = 0
res = 0
for i in z :
if i == -1 :
if not res :
ans +=1
else :
res -=1
else :
res +=1
print(ans) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
n = int(input())
z = list(map(int,input().split()))
ans = 0
res = 0
for i in z :
if i == -1 :
if not res :
ans +=1
else :
res -=1
else :
res +=1
print(ans)
``` | 0 |
|
670 | C | Cinema | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Moscow is hosting a major international conference, which is attended by *n* scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all *n* scientists decided to go to the cinema. There are *m* movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of scientists.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the index of a language, which the *i*-th scientist knows.
The third line contains a positive integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of movies in the cinema.
The fourth line contains *m* positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=109), where *b**j* is the index of the audio language of the *j*-th movie.
The fifth line contains *m* positive integers *c*1,<=*c*2,<=...,<=*c**m* (1<=≤<=*c**j*<=≤<=109), where *c**j* is the index of subtitles language of the *j*-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is *b**j*<=≠<=*c**j*. | Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them. | [
"3\n2 3 2\n2\n3 2\n2 3\n",
"6\n6 3 1 1 3 7\n5\n1 2 3 4 5\n2 3 4 5 1\n"
] | [
"2\n",
"1\n"
] | In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | 1,000 | [
{
"input": "3\n2 3 2\n2\n3 2\n2 3",
"output": "2"
},
{
"input": "6\n6 3 1 1 3 7\n5\n1 2 3 4 5\n2 3 4 5 1",
"output": "1"
},
{
"input": "1\n10\n1\n10\n3",
"output": "1"
},
{
"input": "2\n1 6\n1\n6\n1",
"output": "1"
},
{
"input": "1\n5\n2\n2 2\n5 5",
"output": "1"
},
{
"input": "2\n4 4\n2\n4 7\n7 5",
"output": "1"
},
{
"input": "10\n3 1 8 8 1 1 5 1 3 5\n2\n1 4\n3 1",
"output": "1"
},
{
"input": "10\n7 6 1 2 7 3 9 7 7 9\n10\n2 9 6 5 9 3 10 3 1 6\n4 6 7 9 7 4 1 9 2 5",
"output": "5"
},
{
"input": "20\n2 2 1 6 6 5 10 2 5 5 4 8 6 8 8 10 2 1 5 6\n20\n1 9 1 1 5 1 9 10 1 10 9 9 8 7 5 1 1 10 2 7\n3 5 9 10 10 8 2 9 6 7 8 8 6 5 3 4 6 3 7 4",
"output": "5"
},
{
"input": "2\n10 8\n10\n8 3 10 8 8 8 3 8 8 8\n10 10 8 3 10 3 8 3 10 10",
"output": "1"
},
{
"input": "5\n9 9 2 4 2\n5\n4 1 1 1 2\n2 4 4 9 7",
"output": "5"
},
{
"input": "1\n320994883\n1\n332200603\n942930950",
"output": "1"
},
{
"input": "3\n1000000000 1 1000000000\n2\n1000000000 1\n1 1000000000",
"output": "1"
},
{
"input": "5\n1 2 3 3 4\n2\n1 2\n3 4",
"output": "1"
},
{
"input": "3\n1 3 2\n2\n1 3\n2 4",
"output": "1"
},
{
"input": "5\n2 2 3 3 4\n3\n5 2 2\n6 3 4",
"output": "2"
},
{
"input": "2\n1 2\n2\n3 3\n4 1",
"output": "2"
},
{
"input": "12\n3 2 1 1 4 4 5 1 6 6 7 7\n4\n3 2 4 7\n2 1 5 6",
"output": "4"
},
{
"input": "14\n1 1 2 2 2 3 3 3 4 5 5 5 6 6\n3\n1 3 5\n2 6 4",
"output": "2"
}
] | 1,611,722,150 | 2,147,483,647 | PyPy 3 | OK | TESTS | 138 | 1,372 | 49,561,600 | from collections import defaultdict
n = int(input())
lang = list(map(int, input().split()))
m = int(input())
B = list(map(int,input().split()))
C = list(map(int, input().split()))
ind = [i for i in range(m)]
movies = [list(x) for x in zip(B,C,ind)]
lcount = defaultdict(int)
for i in lang:
lcount[i] += 1
movies.sort(key=lambda x:(lcount[x[0]], lcount[x[1]]), reverse=True)
print(movies[0][2]+1) | Title: Cinema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Moscow is hosting a major international conference, which is attended by *n* scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all *n* scientists decided to go to the cinema. There are *m* movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of scientists.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the index of a language, which the *i*-th scientist knows.
The third line contains a positive integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of movies in the cinema.
The fourth line contains *m* positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=109), where *b**j* is the index of the audio language of the *j*-th movie.
The fifth line contains *m* positive integers *c*1,<=*c*2,<=...,<=*c**m* (1<=≤<=*c**j*<=≤<=109), where *c**j* is the index of subtitles language of the *j*-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is *b**j*<=≠<=*c**j*.
Output Specification:
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Demo Input:
['3\n2 3 2\n2\n3 2\n2 3\n', '6\n6 3 1 1 3 7\n5\n1 2 3 4 5\n2 3 4 5 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | ```python
from collections import defaultdict
n = int(input())
lang = list(map(int, input().split()))
m = int(input())
B = list(map(int,input().split()))
C = list(map(int, input().split()))
ind = [i for i in range(m)]
movies = [list(x) for x in zip(B,C,ind)]
lcount = defaultdict(int)
for i in lang:
lcount[i] += 1
movies.sort(key=lambda x:(lcount[x[0]], lcount[x[1]]), reverse=True)
print(movies[0][2]+1)
``` | 3 |
|
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14",
"output": "151"
},
{
"input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54",
"output": "-1"
},
{
"input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260",
"output": "2157"
},
{
"input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354",
"output": "-1"
},
{
"input": "4 2\n1 2 3 4",
"output": "-1"
},
{
"input": "3 4\n3 5 5",
"output": "-1"
},
{
"input": "3 2\n88888884 88888886 88888888",
"output": "3"
},
{
"input": "2 1\n1000000000 1000000000",
"output": "0"
},
{
"input": "4 2\n1000000000 100000000 100000000 100000000",
"output": "450000000"
},
{
"input": "2 2\n1000000000 1000000000",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "-1"
},
{
"input": "3 4\n3 5 3",
"output": "-1"
},
{
"input": "3 2\n1 2 2",
"output": "-1"
},
{
"input": "4 2\n2 3 3 2",
"output": "-1"
},
{
"input": "3 2\n1 2 4",
"output": "-1"
},
{
"input": "3 2\n3 4 4",
"output": "-1"
},
{
"input": "3 3\n4 7 10",
"output": "3"
},
{
"input": "4 3\n2 2 5 1",
"output": "-1"
},
{
"input": "3 3\n1 3 5",
"output": "-1"
},
{
"input": "2 5\n5 9",
"output": "-1"
},
{
"input": "2 3\n5 7",
"output": "-1"
},
{
"input": "3 137\n1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 5\n1 2 5",
"output": "-1"
},
{
"input": "3 3\n1000000000 1000000000 999999997",
"output": "2"
},
{
"input": "2 4\n5 6",
"output": "-1"
},
{
"input": "4 1\n1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "2 3\n5 8",
"output": "1"
},
{
"input": "2 6\n8 16",
"output": "-1"
},
{
"input": "5 3\n15 14 9 12 18",
"output": "-1"
},
{
"input": "3 3\n1 2 3",
"output": "-1"
},
{
"input": "3 3\n3 4 5",
"output": "-1"
},
{
"input": "2 5\n8 17",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "0"
},
{
"input": "3 3\n5 3 4",
"output": "-1"
},
{
"input": "3 6\n10 14 12",
"output": "-1"
},
{
"input": "2 2\n3 5",
"output": "1"
},
{
"input": "3 5\n1 3 4",
"output": "-1"
},
{
"input": "4 3\n1 6 6 6",
"output": "-1"
},
{
"input": "2 3\n1 8",
"output": "-1"
},
{
"input": "3 5\n6 11 17",
"output": "-1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "2 4\n6 8",
"output": "-1"
},
{
"input": "2 1\n2 3",
"output": "1"
},
{
"input": "4 4\n1 5 8 14",
"output": "-1"
},
{
"input": "3 3\n1 5 3",
"output": "-1"
},
{
"input": "4 3\n1 2 2 5",
"output": "-1"
},
{
"input": "3 2\n1 4 6",
"output": "-1"
},
{
"input": "2 3\n6 9",
"output": "1"
},
{
"input": "3 3\n2 3 4",
"output": "-1"
},
{
"input": "3 2\n9 10 10",
"output": "-1"
},
{
"input": "2 2\n9 12",
"output": "-1"
},
{
"input": "2 2\n100000003 100000005",
"output": "1"
},
{
"input": "2 3\n2 4",
"output": "-1"
},
{
"input": "3 2\n2 3 5",
"output": "-1"
},
{
"input": "3 3\n1 3 4",
"output": "-1"
},
{
"input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "4499999991"
},
{
"input": "3 5\n2 4 5",
"output": "-1"
},
{
"input": "2 3\n7 10",
"output": "1"
},
{
"input": "3 10\n10 13 17",
"output": "-1"
},
{
"input": "2 3\n1 6",
"output": "-1"
},
{
"input": "1 7\n1000000000",
"output": "0"
},
{
"input": "2 4\n3 7",
"output": "1"
},
{
"input": "2 3\n2 5",
"output": "1"
},
{
"input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 3\n7 8 8",
"output": "-1"
},
{
"input": "4 10\n1 11 100 11",
"output": "-1"
}
] | 1,494,146,294 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 9,216,000 | n,k=map(int,input().split())
a=list(map(int,input().split()))
q=True
mi=a[0]
for i in a:
if i%k!=0:
q=False
break
elif i<mi:
mi=i
ans=0
if q:
for i in a:
ans+=(i-mi)//k
else: ans=-1
print(ans)
| Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Output Specification:
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
Demo Input:
['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n']
Demo Output:
['3', '-1', '2999999997']
Note:
Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
q=True
mi=a[0]
for i in a:
if i%k!=0:
q=False
break
elif i<mi:
mi=i
ans=0
if q:
for i in a:
ans+=(i-mi)//k
else: ans=-1
print(ans)
``` | 0 |
|
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces. | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"input": "3 1 2\n6 5 5",
"output": "1"
},
{
"input": "3 2 1\n10 10 8",
"output": "2"
},
{
"input": "8 3 5\n42 55 61 72 83 10 22 33",
"output": "6"
},
{
"input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995",
"output": "999999990"
},
{
"input": "4 1 3\n10 8 7 3",
"output": "2"
},
{
"input": "4 2 2\n402 10 10 402",
"output": "392"
},
{
"input": "4 1 3\n10 402 402 10",
"output": "0"
},
{
"input": "4 3 1\n100 100 200 200",
"output": "0"
},
{
"input": "150 10 140\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
}
] | 1,616,323,949 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | a, b, c=map(int, input().split())
d=sorted(list(map(int, input().split())))
print(d)
e=d[b]
f=d[b+1]
print(f-e)
| Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
Input Specification:
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output Specification:
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
Demo Input:
['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | ```python
a, b, c=map(int, input().split())
d=sorted(list(map(int, input().split())))
print(d)
e=d[b]
f=d[b+1]
print(f-e)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number *i* (1<=≤<=*i*<=≤<=*n*), someone can use the first portal to move from it to room number (*i*<=+<=1), also someone can use the second portal to move from it to room number *p**i*, where 1<=≤<=*p**i*<=≤<=*i*.
In order not to get lost, Vasya decided to act as follows.
- Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. - Let's assume that Vasya is in room *i* and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room *p**i*), otherwise Vasya uses the first portal.
Help Vasya determine the number of times he needs to use portals to get to room (*n*<=+<=1) in the end. | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of rooms. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*i*). Each *p**i* denotes the number of the room, that someone can reach, if he will use the second portal in the *i*-th room. | Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"2\n1 2\n",
"4\n1 1 2 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"20\n",
"62\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "20"
},
{
"input": "5\n1 1 1 1 1",
"output": "62"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "154"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "3\n1 1 3",
"output": "8"
},
{
"input": "10\n1 1 3 2 2 1 3 4 7 5",
"output": "858"
},
{
"input": "20\n1 2 2 2 2 1 4 7 8 6 5 3 5 3 8 11 5 10 16 10",
"output": "433410"
},
{
"input": "32\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",
"output": "589934534"
},
{
"input": "10\n1 1 3 2 2 1 3 4 7 5",
"output": "858"
},
{
"input": "30\n1 1 2 2 5 6 4 3 4 7 3 5 12 12 2 15 3 8 3 10 12 3 14 1 10 4 22 11 22 27",
"output": "132632316"
},
{
"input": "70\n1 1 2 3 4 3 5 2 2 4 8 6 13 6 13 3 5 4 5 10 11 9 11 8 12 24 21 6 9 29 25 31 17 27 3 17 35 5 21 11 27 14 33 7 33 44 22 33 21 11 38 46 53 46 3 22 5 27 55 22 41 25 56 61 27 28 11 66 68 13",
"output": "707517223"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "2046"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2097150"
},
{
"input": "102\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "810970229"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "20"
},
{
"input": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "40"
},
{
"input": "107\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107",
"output": "214"
},
{
"input": "129\n1 1 3 3 1 4 7 4 3 5 8 11 3 9 15 4 11 17 1 6 18 9 11 13 17 22 8 18 26 13 16 20 3 16 35 26 23 28 27 30 39 29 43 8 14 6 17 32 26 31 2 18 3 47 52 21 57 1 35 35 53 47 16 26 30 65 48 2 32 11 10 5 4 1 4 53 71 21 53 8 58 49 17 6 19 80 1 49 43 60 12 60 35 25 86 45 47 97 52 74 10 91 93 31 69 41 80 90 67 4 94 92 82 36 27 18 65 8 45 90 42 115 34 61 16 97 20 43 104",
"output": "931883285"
},
{
"input": "100\n1 1 3 1 5 1 1 1 8 9 7 3 11 11 15 14 4 10 11 12 1 10 13 11 7 23 8 12 18 23 27 17 14 29 1 33 5 24 26 29 25 14 40 8 43 29 43 40 34 18 21 31 3 8 20 14 28 29 3 54 14 3 59 1 45 9 13 11 50 48 26 57 17 33 9 52 21 46 24 20 16 58 69 77 52 36 80 2 31 3 44 36 64 90 84 8 21 25 65 67",
"output": "264413610"
},
{
"input": "31\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 29",
"output": "758096363"
},
{
"input": "104\n1 1 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",
"output": "740446116"
}
] | 1,581,810,156 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 1,228,800 | n = int(input())
portals = [int(x)-1 for x in input().split()]
crosses = [0]*n
i = 0
moves = 0
while i != n:
moves += 1
crosses[i] += 1
if crosses[i] % 2 == 0:
i += 1
else:
i = portals[i]
print(moves)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number *i* (1<=≤<=*i*<=≤<=*n*), someone can use the first portal to move from it to room number (*i*<=+<=1), also someone can use the second portal to move from it to room number *p**i*, where 1<=≤<=*p**i*<=≤<=*i*.
In order not to get lost, Vasya decided to act as follows.
- Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. - Let's assume that Vasya is in room *i* and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room *p**i*), otherwise Vasya uses the first portal.
Help Vasya determine the number of times he needs to use portals to get to room (*n*<=+<=1) in the end.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of rooms. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*i*). Each *p**i* denotes the number of the room, that someone can reach, if he will use the second portal in the *i*-th room.
Output Specification:
Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n1 2\n', '4\n1 1 2 3\n', '5\n1 1 1 1 1\n']
Demo Output:
['4\n', '20\n', '62\n']
Note:
none | ```python
n = int(input())
portals = [int(x)-1 for x in input().split()]
crosses = [0]*n
i = 0
moves = 0
while i != n:
moves += 1
crosses[i] += 1
if crosses[i] % 2 == 0:
i += 1
else:
i = portals[i]
print(moves)
``` | 0 |
|
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8",
"output": "429.309294877"
},
{
"input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10",
"output": "13629.282573522"
},
{
"input": "2 1\n-20 -10\n-10 -6",
"output": "0.215406592"
},
{
"input": "2 13\n13 -10\n-3 -2",
"output": "4.651021393"
},
{
"input": "2 21\n13 8\n14 10",
"output": "0.939148551"
},
{
"input": "2 75\n-3 12\n1 12",
"output": "6.000000000"
},
{
"input": "2 466\n10 16\n-6 -3",
"output": "231.503997374"
},
{
"input": "2 999\n6 16\n-17 -14",
"output": "755.286284531"
},
{
"input": "2 1000\n-17 -14\n-14 -8",
"output": "134.164078650"
},
{
"input": "3 384\n-4 -19\n-17 -2\n3 4",
"output": "324.722285390"
},
{
"input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5",
"output": "668.956254495"
},
{
"input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15",
"output": "789.212495576"
},
{
"input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18",
"output": "3415.618464093"
},
{
"input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5",
"output": "2113.552527680"
},
{
"input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6",
"output": "2999.497312668"
},
{
"input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4",
"output": "2797.756635934"
},
{
"input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5",
"output": "12766.080247922"
},
{
"input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3",
"output": "36.467924851"
},
{
"input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4",
"output": "9495.010556306"
},
{
"input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14",
"output": "6087.366930474"
},
{
"input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11",
"output": "8929.162822862"
},
{
"input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13",
"output": "16314.207721932"
},
{
"input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11",
"output": "22153.369189802"
}
] | 1,673,078,020 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | import math
n,k = map(int,input().split())
a,b = map(int,input().split())
sum = 0
for i in range(n-1):
c,d = map(int,input().split())
if b == d or a == c:
i = abs(a-c)+abs(b-d)
else:
t = (a-c)**2 + (b-d)**2
i = math.sqrt(t)
sum += (i * k)
a,b = c,d
print(round(sum/50, 6))
# Sat Jan 07 2023 10:53:39 GMT+0300 (Moscow Standard Time)
| Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Output Specification:
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
Demo Input:
['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n']
Demo Output:
['0.200000000', '6.032163204', '3.000000000']
Note:
none | ```python
import math
n,k = map(int,input().split())
a,b = map(int,input().split())
sum = 0
for i in range(n-1):
c,d = map(int,input().split())
if b == d or a == c:
i = abs(a-c)+abs(b-d)
else:
t = (a-c)**2 + (b-d)**2
i = math.sqrt(t)
sum += (i * k)
a,b = c,d
print(round(sum/50, 6))
# Sat Jan 07 2023 10:53:39 GMT+0300 (Moscow Standard Time)
``` | 3 |
|
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game. | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
{
"input": "8 8 1 1 1",
"output": "Second"
},
{
"input": "15 14 32 65 28",
"output": "First"
},
{
"input": "894 197 325 232 902",
"output": "First"
},
{
"input": "1 2 8 8 5",
"output": "Friendship"
},
{
"input": "37 261 207 1 1000",
"output": "Friendship"
},
{
"input": "29 344 406 900 1",
"output": "Friendship"
},
{
"input": "1 2 8 9 8",
"output": "First"
},
{
"input": "2 9 8 8 9",
"output": "Friendship"
},
{
"input": "213 480 811 134 745",
"output": "First"
},
{
"input": "2 313 856 964 421",
"output": "Friendship"
},
{
"input": "1 10 2 6 10",
"output": "Friendship"
},
{
"input": "2 7 6 2 3",
"output": "Friendship"
},
{
"input": "637 324 69 612 998",
"output": "Second"
},
{
"input": "13 849 819 723 918",
"output": "Friendship"
},
{
"input": "9 5 7 8 7",
"output": "First"
},
{
"input": "6 5 7 10 4",
"output": "Friendship"
},
{
"input": "61 464 623 89 548",
"output": "First"
},
{
"input": "641 31 29 161 802",
"output": "Friendship"
},
{
"input": "3 3 1 6 9",
"output": "Friendship"
},
{
"input": "2 3 9 8 2",
"output": "Friendship"
},
{
"input": "485 117 368 567 609",
"output": "First"
},
{
"input": "4 202 512 995 375",
"output": "Friendship"
},
{
"input": "424 41 41 909 909",
"output": "Friendship"
},
{
"input": "884 913 263 641 265",
"output": "Second"
},
{
"input": "12 462 8 311 327",
"output": "Second"
},
{
"input": "436 306 266 493 580",
"output": "Second"
},
{
"input": "69 1 2 1 2",
"output": "First"
}
] | 1,626,628,095 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 6,758,400 | s,v1,v2,t1,t2=list(map(int,input().split()))
c1=(s*v1)+(2*t1)
c2=(s*v2)+(2*t2)
if(c1<c2):
print("First")
elif c1==c2:
print("Friendship")
else:
print("Second")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input Specification:
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output Specification:
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Demo Input:
['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n']
Demo Output:
['First\n', 'Second\n', 'Friendship\n']
Note:
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | ```python
s,v1,v2,t1,t2=list(map(int,input().split()))
c1=(s*v1)+(2*t1)
c2=(s*v2)+(2*t2)
if(c1<c2):
print("First")
elif c1==c2:
print("Friendship")
else:
print("Second")
``` | 3 |
|
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,618,568,015 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 7,065,600 | n=int(input())
l=[int(x) for x in input().split()]
for i in range(0,n):
l1=[]
for j in range(0,n):
if j!=i:
l1.append(abs(l[j]-l[i]))
print(min(l1),max(l1),sep=' ')
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
n=int(input())
l=[int(x) for x in input().split()]
for i in range(0,n):
l1=[]
for j in range(0,n):
if j!=i:
l1.append(abs(l[j]-l[i]))
print(min(l1),max(l1),sep=' ')
``` | 0 |
|
916 | B | Jamie and Binary Sequence (changed after round) | PROGRAMMING | 2,000 | [
"bitmasks",
"greedy",
"math"
] | null | null | Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length *k* (*a*1,<=*a*2,<=...,<=*a**k*) with . Give a value to each sequence. Among all sequence(s) that have the minimum *y* value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes. | The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence. | Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018]. | [
"23 5\n",
"13 2\n",
"1 2\n"
] | [
"Yes\n3 3 2 1 0 \n",
"No\n",
"Yes\n-1 -1 \n"
] | Sample 1:
2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum *y* value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a8539b2d27aefc8d2fab6dfd8296d11c36dcaa40.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Powers of 2:
If *x* > 0, then 2<sup class="upper-index">*x*</sup> = 2·2·2·...·2 (*x* times).
If *x* = 0, then 2<sup class="upper-index">*x*</sup> = 1.
If *x* < 0, then <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/766628f1c7814795eac1a0afaa1ff062c40ef29e.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Lexicographical order:
Given two different sequences of the same length, (*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ... , *a*<sub class="lower-index">*k*</sub>) and (*b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ... , *b*<sub class="lower-index">*k*</sub>), the first one is smaller than the second one for the lexicographical order, if and only if *a*<sub class="lower-index">*i*</sub> < *b*<sub class="lower-index">*i*</sub>, for the first *i* where *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> differ. | 1,000 | [
{
"input": "23 5",
"output": "Yes\n3 3 2 1 0 "
},
{
"input": "13 2",
"output": "No"
},
{
"input": "1 2",
"output": "Yes\n-1 -1 "
},
{
"input": "1 1",
"output": "Yes\n0 "
},
{
"input": "1000000000000000000 100000",
"output": "Yes\n44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44..."
},
{
"input": "7 2",
"output": "No"
},
{
"input": "7 3",
"output": "Yes\n2 1 0 "
},
{
"input": "7 4",
"output": "Yes\n1 1 1 0 "
},
{
"input": "521325125150442808 10",
"output": "No"
},
{
"input": "498518679725149504 1000",
"output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49..."
},
{
"input": "464823731286228582 100000",
"output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..."
},
{
"input": "1 4",
"output": "Yes\n-2 -2 -2 -2 "
},
{
"input": "9 4",
"output": "Yes\n2 2 -1 -1 "
},
{
"input": "3 4",
"output": "Yes\n0 0 -1 -1 "
},
{
"input": "144 4",
"output": "Yes\n6 6 3 3 "
},
{
"input": "59 4",
"output": "No"
},
{
"input": "78 4",
"output": "Yes\n6 3 2 1 "
},
{
"input": "192 4",
"output": "Yes\n6 6 5 5 "
},
{
"input": "107 4",
"output": "No"
},
{
"input": "552 5",
"output": "Yes\n8 8 5 2 2 "
},
{
"input": "680 5",
"output": "Yes\n8 8 7 5 3 "
},
{
"input": "808 5",
"output": "Yes\n8 8 8 5 3 "
},
{
"input": "1528 5",
"output": "No"
},
{
"input": "1656 5",
"output": "No"
},
{
"input": "26972 8",
"output": "Yes\n14 13 11 8 6 4 3 2 "
},
{
"input": "23100 8",
"output": "Yes\n14 12 11 9 5 4 3 2 "
},
{
"input": "19228 8",
"output": "Yes\n13 13 11 9 8 4 3 2 "
},
{
"input": "22652 8",
"output": "Yes\n14 12 11 6 5 4 3 2 "
},
{
"input": "26076 8",
"output": "No"
},
{
"input": "329438 10",
"output": "Yes\n18 16 10 9 7 6 4 3 2 1 "
},
{
"input": "12862 10",
"output": "Yes\n12 12 12 9 5 4 3 2 0 0 "
},
{
"input": "96286 10",
"output": "Yes\n15 15 14 13 12 11 4 3 2 1 "
},
{
"input": "12414 10",
"output": "Yes\n12 12 12 6 5 4 3 2 0 0 "
},
{
"input": "95838 10",
"output": "No"
},
{
"input": "1728568411 16",
"output": "No"
},
{
"input": "611684539 16",
"output": "Yes\n28 28 26 22 21 20 18 16 15 12 7 5 4 3 1 0 "
},
{
"input": "84735259 16",
"output": "Yes\n25 25 24 19 18 15 14 13 12 10 8 4 3 1 -1 -1 "
},
{
"input": "6967851387 16",
"output": "No"
},
{
"input": "2145934811 16",
"output": "No"
},
{
"input": "6795804571172 20",
"output": "Yes\n41 41 41 37 35 34 33 30 26 24 23 18 14 13 12 10 9 5 1 1 "
},
{
"input": "1038982654596 20",
"output": "Yes\n38 38 38 37 36 32 31 30 29 27 21 20 16 13 11 9 7 1 0 0 "
},
{
"input": "11277865770724 20",
"output": "No"
},
{
"input": "5525338821444 20",
"output": "No"
},
{
"input": "15764221937572 20",
"output": "No"
},
{
"input": "922239521698513045 30",
"output": "Yes\n58 58 58 55 54 51 50 46 45 44 41 40 39 38 37 36 34 32 30 29 28 23 21 19 17 15 7 4 2 0 "
},
{
"input": "923065764876596469 30",
"output": "No"
},
{
"input": "923892008054679893 30",
"output": "No"
},
{
"input": "924718251232763317 30",
"output": "Yes\n58 58 58 55 54 52 50 48 46 41 38 36 35 32 31 29 25 19 18 15 12 11 10 8 7 5 4 2 -1 -1 "
},
{
"input": "925544490115879445 30",
"output": "Yes\n59 58 55 54 52 51 45 44 40 39 38 35 34 33 32 30 28 27 26 24 21 19 18 16 14 12 9 4 2 0 "
},
{
"input": "926370733293962869 30",
"output": "Yes\n57 57 57 57 57 57 55 54 52 51 49 48 45 40 38 34 33 28 27 22 19 18 17 10 9 6 5 4 2 0 "
},
{
"input": "927196976472046293 30",
"output": "No"
},
{
"input": "928023215355162421 30",
"output": "Yes\n58 58 58 55 54 53 48 37 36 33 31 27 26 25 23 19 18 17 16 14 13 11 10 9 8 5 4 2 -1 -1 "
},
{
"input": "928849458533245845 30",
"output": "No"
},
{
"input": "855969764271400156 30",
"output": "No"
},
{
"input": "856796007449483580 30",
"output": "No"
},
{
"input": "857622246332599708 30",
"output": "Yes\n58 58 57 56 55 54 53 50 49 47 46 45 41 39 38 37 33 32 31 29 21 15 11 10 8 7 4 3 1 1 "
},
{
"input": "858448489510683132 30",
"output": "No"
},
{
"input": "859274728393799260 30",
"output": "Yes\n59 57 56 55 54 53 51 50 47 46 40 39 38 36 28 26 25 22 21 16 15 14 13 12 10 9 6 4 3 2 "
},
{
"input": "860100975866849980 30",
"output": "No"
},
{
"input": "860927214749966108 30",
"output": "No"
},
{
"input": "861753457928049532 30",
"output": "Yes\n58 58 57 56 55 54 53 52 50 48 47 44 37 36 34 30 26 25 24 23 22 18 12 9 8 6 5 4 3 2 "
},
{
"input": "862579701106132957 30",
"output": "No"
},
{
"input": "863405944284216381 30",
"output": "No"
},
{
"input": "374585535361966567 30",
"output": "No"
},
{
"input": "4 1",
"output": "Yes\n2 "
},
{
"input": "4 9",
"output": "Yes\n-1 -1 -1 -1 -1 -1 -1 -2 -2 "
},
{
"input": "4 3",
"output": "Yes\n1 0 0 "
},
{
"input": "4 144",
"output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -21 "
},
{
"input": "4 59",
"output": "Yes\n-3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -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 -30 "
},
{
"input": "4 78",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 "
},
{
"input": "4 192",
"output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -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 -..."
},
{
"input": "4 107",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -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 -47 "
},
{
"input": "5 552",
"output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..."
},
{
"input": "5 680",
"output": "Yes\n-7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7..."
},
{
"input": "5 808",
"output": "Yes\n-7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7..."
},
{
"input": "5 1528",
"output": "Yes\n-8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8..."
},
{
"input": "5 1656",
"output": "Yes\n-8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8..."
},
{
"input": "8 26972",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 23100",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 19228",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 22652",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 26076",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 19354",
"output": "Yes\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9..."
},
{
"input": "23 35482",
"output": "Yes\n-10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -1..."
},
{
"input": "23 18906",
"output": "Yes\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9..."
},
{
"input": "23 2330",
"output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..."
},
{
"input": "23 85754",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 1882",
"output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..."
},
{
"input": "23 85306",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 68730",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 84859",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 45148",
"output": "Yes\n-10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -1..."
},
{
"input": "281474976710656 5",
"output": "Yes\n46 46 46 45 45 "
},
{
"input": "288230376151973890 5",
"output": "Yes\n57 57 18 0 0 "
},
{
"input": "36029346774812736 5",
"output": "Yes\n55 39 15 11 6 "
},
{
"input": "901283150305558530 5",
"output": "No"
},
{
"input": "288318372649779720 50",
"output": "Yes\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 46 44 35 30 27 17 14 9 2 1 0 -1 -2 -3 -4 -5 -6 -6 "
},
{
"input": "513703875844698663 50",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 53 48 43 41 39 38 37 36 34 27 26 25 24 22 21 20 18 17 15 14 13 12 9 5 2 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -9 "
},
{
"input": "287632104387196918 50",
"output": "Yes\n57 56 55 54 53 52 51 50 48 47 46 44 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 13 12 10 9 8 7 6 5 4 2 1 "
},
{
"input": "864690028406636543 58",
"output": "Yes\n58 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 39 38 37 36 35 34 33 32 31 30 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 "
},
{
"input": "576460752303423487 60",
"output": "Yes\n57 57 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 "
},
{
"input": "141012366262272 1",
"output": "No"
},
{
"input": "1100585377792 4",
"output": "Yes\n39 39 30 13 "
},
{
"input": "18598239186190594 9",
"output": "Yes\n54 49 44 41 40 21 18 8 1 "
},
{
"input": "18647719372456016 19",
"output": "Yes\n51 51 51 51 51 51 51 51 49 46 31 24 20 16 6 3 2 1 1 "
},
{
"input": "9297478914673158 29",
"output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 48 43 33 18 11 9 2 0 -1 -2 -3 -4 -4 "
},
{
"input": "668507368948226 39",
"output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 32 22 16 15 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -13 "
},
{
"input": "1143595340402690 49",
"output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 36 35 27 25 19 12 0 -1 -2 -3 -4 -5 -6 -7 -8 -8 "
},
{
"input": "35527987183872 59",
"output": "Yes\n40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 38 36 24 19 18 17 14 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 "
},
{
"input": "324634416758413825 9",
"output": "No"
},
{
"input": "577030480059438572 19",
"output": "Yes\n59 49 42 41 37 35 33 28 26 23 18 12 10 8 7 6 5 3 2 "
},
{
"input": "185505960265024385 29",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 52 49 48 43 42 39 37 36 29 24 22 20 15 9 8 7 -1 -2 -2 "
},
{
"input": "57421517433081233 39",
"output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 51 50 39 36 31 30 28 27 26 24 20 11 10 8 7 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -10 "
},
{
"input": "90131572647657641 49",
"output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 45 44 42 41 37 36 28 25 23 21 20 18 17 7 5 3 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -12 "
},
{
"input": "732268459757413905 59",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 53 51 48 47 43 41 38 35 31 30 28 20 13 10 9 4 -1 -2 -2 "
},
{
"input": "226111453445787190 9",
"output": "No"
},
{
"input": "478818723873062027 19",
"output": "No"
},
{
"input": "337790572680259391 29",
"output": "Yes\n58 55 53 52 44 41 39 37 36 35 34 30 29 28 26 24 20 18 16 13 10 9 8 5 4 3 2 1 0 "
},
{
"input": "168057637182978458 39",
"output": "Yes\n54 54 54 54 54 54 54 54 54 52 50 48 43 42 41 40 39 34 33 32 31 30 28 26 25 20 18 16 13 12 11 8 7 4 3 0 -1 -2 -2 "
},
{
"input": "401486559567818547 49",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 52 49 46 44 43 42 40 39 38 37 34 33 28 26 24 21 17 13 11 10 9 8 5 4 1 -1 -1 "
},
{
"input": "828935109688089201 59",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 47 46 45 44 43 36 34 33 32 29 25 23 22 19 18 17 15 14 12 11 9 6 5 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 "
},
{
"input": "954687629161163764 9",
"output": "No"
},
{
"input": "287025268967992526 19",
"output": "No"
},
{
"input": "844118423640988373 29",
"output": "No"
},
{
"input": "128233154575908599 39",
"output": "Yes\n56 55 54 50 49 48 47 44 41 40 38 36 35 34 33 32 31 30 29 27 25 23 22 21 19 18 15 13 12 11 10 9 7 6 5 4 2 1 0 "
},
{
"input": "792058388714085231 49",
"output": "Yes\n56 56 56 56 56 56 56 56 56 56 55 54 53 52 51 50 48 47 46 45 44 42 39 38 37 35 30 29 28 26 23 21 19 17 16 15 14 12 11 9 8 6 5 3 2 1 -1 -2 -2 "
},
{
"input": "827183623566145225 59",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 54 53 52 51 49 47 45 44 43 42 41 40 36 35 34 33 32 30 29 28 27 26 25 23 21 19 18 17 13 12 10 9 7 6 3 -1 -1 "
},
{
"input": "846113779983498737 9",
"output": "No"
},
{
"input": "780248358343081983 19",
"output": "No"
},
{
"input": "576460580458522095 29",
"output": "No"
},
{
"input": "540145805193625598 39",
"output": "No"
},
{
"input": "576388182371377103 49",
"output": "Yes\n58 57 56 55 54 53 52 51 50 49 48 47 45 44 43 42 40 39 38 37 36 35 34 33 32 30 29 28 27 26 25 23 22 21 20 19 17 15 12 11 10 9 8 7 6 3 2 1 0 "
},
{
"input": "567448991726268409 59",
"output": "Yes\n56 56 56 56 56 56 56 55 54 52 51 50 49 48 47 46 45 44 43 41 40 39 38 36 35 32 31 30 29 28 27 25 24 23 22 21 20 19 18 17 16 14 13 11 10 9 8 7 6 5 4 3 -1 -2 -3 -4 -5 -6 -6 "
},
{
"input": "576460752303423487 9",
"output": "No"
},
{
"input": "576460752303423487 19",
"output": "No"
},
{
"input": "864691128455135231 29",
"output": "No"
},
{
"input": "864691128455135231 39",
"output": "No"
},
{
"input": "576460752303423487 49",
"output": "No"
},
{
"input": "864691128455135231 59",
"output": "Yes\n59 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 "
},
{
"input": "628839188486443015 2412",
"output": "Yes\n48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48..."
},
{
"input": "558445254282313727 89558",
"output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..."
},
{
"input": "576460752303423487 100000",
"output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..."
},
{
"input": "1 100000",
"output": "Yes\n-16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -1..."
},
{
"input": "99997 100000",
"output": "Yes\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..."
},
{
"input": "99998 100000",
"output": "Yes\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..."
},
{
"input": "99999 100000",
"output": "Yes\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..."
},
{
"input": "100000 100000",
"output": "Yes\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..."
},
{
"input": "100001 100000",
"output": "Yes\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "100002 100000",
"output": "Yes\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "100003 100000",
"output": "Yes\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "12 202",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4..."
},
{
"input": "1 4",
"output": "Yes\n-2 -2 -2 -2 "
},
{
"input": "2 64",
"output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 "
},
{
"input": "2 8",
"output": "Yes\n-2 -2 -2 -2 -2 -2 -2 -2 "
},
{
"input": "1 5",
"output": "Yes\n-2 -2 -2 -3 -3 "
},
{
"input": "1 7",
"output": "Yes\n-2 -2 -2 -3 -4 -5 -5 "
},
{
"input": "19 5",
"output": "Yes\n3 3 1 -1 -1 "
},
{
"input": "1 30",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 "
}
] | 1,517,456,793 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 5,632,000 | import math
n, k = map(int, input().split())
binn=[]
t = n
sb = 0
val=[0]*128
ind = 0
small = 0
one = True
while t > 0:
binn.append(t%2)
if t%2 == 1:
sb += 1
if one:
small = ind
one = False
t = math.trunc(t/2)
ind = ind + 1
#print("small = ", small)
ind = ind - 1
if k < sb:
print("No")
exit(0)
rem = k - sb
#print("k = ", k, " set bits = ", sb)
ans = []
for i in range(0, ind+1):
ans.append([i, binn[i]])
index = len(ans) - 1
c=1
while rem!=0:
shift = 0
if ans[index][1] <= rem:
shift = ans[index][1]
else:
upto = small-rem
break
if index - 1 < 0:
ans[0][1] -= shift
ans.insert(0, [index - c, 2*shift])
else:
ans[index-1][1] += 2*shift
ans[index][1] -= shift
rem -= shift
index -= 1
if index < 0:
index = 0
c+=1
print("Yes")
res = ""
aa = 0
count=0
for i in range(len(ans)-1, -1, -1):
if ans[i][1] > 0:
res = res + (str(ans[i][0])+" ")*ans[i][1]
#if ans[i][0]>0 or ans[i][0] < -43000:
# print(ans[i][0], " x ", ans[i][1])
for i in range(small-1, upto-1, -1):
res = res + (str(i))+" "
#aa += pow(2, (ans[i][0]))*ans[i][1]
#count+=ans[i][1]
res = res + str(upto)
print(res) | Title: Jamie and Binary Sequence (changed after round)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length *k* (*a*1,<=*a*2,<=...,<=*a**k*) with . Give a value to each sequence. Among all sequence(s) that have the minimum *y* value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes.
Input Specification:
The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence.
Output Specification:
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018].
Demo Input:
['23 5\n', '13 2\n', '1 2\n']
Demo Output:
['Yes\n3 3 2 1 0 \n', 'No\n', 'Yes\n-1 -1 \n']
Note:
Sample 1:
2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum *y* value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a8539b2d27aefc8d2fab6dfd8296d11c36dcaa40.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Powers of 2:
If *x* > 0, then 2<sup class="upper-index">*x*</sup> = 2·2·2·...·2 (*x* times).
If *x* = 0, then 2<sup class="upper-index">*x*</sup> = 1.
If *x* < 0, then <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/766628f1c7814795eac1a0afaa1ff062c40ef29e.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Lexicographical order:
Given two different sequences of the same length, (*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ... , *a*<sub class="lower-index">*k*</sub>) and (*b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ... , *b*<sub class="lower-index">*k*</sub>), the first one is smaller than the second one for the lexicographical order, if and only if *a*<sub class="lower-index">*i*</sub> < *b*<sub class="lower-index">*i*</sub>, for the first *i* where *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> differ. | ```python
import math
n, k = map(int, input().split())
binn=[]
t = n
sb = 0
val=[0]*128
ind = 0
small = 0
one = True
while t > 0:
binn.append(t%2)
if t%2 == 1:
sb += 1
if one:
small = ind
one = False
t = math.trunc(t/2)
ind = ind + 1
#print("small = ", small)
ind = ind - 1
if k < sb:
print("No")
exit(0)
rem = k - sb
#print("k = ", k, " set bits = ", sb)
ans = []
for i in range(0, ind+1):
ans.append([i, binn[i]])
index = len(ans) - 1
c=1
while rem!=0:
shift = 0
if ans[index][1] <= rem:
shift = ans[index][1]
else:
upto = small-rem
break
if index - 1 < 0:
ans[0][1] -= shift
ans.insert(0, [index - c, 2*shift])
else:
ans[index-1][1] += 2*shift
ans[index][1] -= shift
rem -= shift
index -= 1
if index < 0:
index = 0
c+=1
print("Yes")
res = ""
aa = 0
count=0
for i in range(len(ans)-1, -1, -1):
if ans[i][1] > 0:
res = res + (str(ans[i][0])+" ")*ans[i][1]
#if ans[i][0]>0 or ans[i][0] < -43000:
# print(ans[i][0], " x ", ans[i][1])
for i in range(small-1, upto-1, -1):
res = res + (str(i))+" "
#aa += pow(2, (ans[i][0]))*ans[i][1]
#count+=ans[i][1]
res = res + str(upto)
print(res)
``` | -1 |
|
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,665,686,476 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 6,041,600 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
f = False
for i in range(n-1):
c = i+1+a[i]
if c == t:
f = True
break
if f:
print("YES")
else:
print("NO") | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | ```python
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
f = False
for i in range(n-1):
c = i+1+a[i]
if c == t:
f = True
break
if f:
print("YES")
else:
print("NO")
``` | 0 |
|
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,660,045,282 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n , m =map(int,input().split())
a =[]
color = 0
for i in range(n):
a.append(list(map(str, input().split()))[:m])
for b in range(n):
for C in range(m):
if a[n][m]=="w" or a[n][m]=="G" or [n][m]=="B":
color= color
else:
color = color+1
print(color)
if color>= 1:
print("#Color")
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none | ```python
n , m =map(int,input().split())
a =[]
color = 0
for i in range(n):
a.append(list(map(str, input().split()))[:m])
for b in range(n):
for C in range(m):
if a[n][m]=="w" or a[n][m]=="G" or [n][m]=="B":
color= color
else:
color = color+1
print(color)
if color>= 1:
print("#Color")
else:
print("#Black&White")
``` | -1 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,695,229,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | k, n, w = [int(i) for i in "1 2 1".split()]
price = 0
for i in range(w):
price += (i+1)*k
if n > price:
print(0)
else:
print(price-n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k, n, w = [int(i) for i in "1 2 1".split()]
price = 0
for i in range(w):
price += (i+1)*k
if n > price:
print(0)
else:
print(price-n)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,664,593,404 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sat Oct 1 10:20:34 2022
@author: thinkpad
"""
line = input()
word = 'hello'
c = 0
for i in range(len(line)):
if c<5 and line[i] == word[c]:
c+=1
if c==5:
break
if c == 5:
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 1 10:20:34 2022
@author: thinkpad
"""
line = input()
word = 'hello'
c = 0
for i in range(len(line)):
if c<5 and line[i] == word[c]:
c+=1
if c==5:
break
if c == 5:
print('YES')
else:
print('NO')
``` | 3.977 |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"input": "1000\n999",
"output": "1"
},
{
"input": "1000\n1",
"output": "250000"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n999",
"output": "249001"
},
{
"input": "2\n998",
"output": "248502"
},
{
"input": "999\n2",
"output": "249001"
},
{
"input": "998\n2",
"output": "248502"
},
{
"input": "2\n1000",
"output": "249500"
},
{
"input": "1000\n2",
"output": "249500"
},
{
"input": "1\n999",
"output": "249500"
},
{
"input": "999\n1",
"output": "249500"
},
{
"input": "188\n762",
"output": "82656"
},
{
"input": "596\n777",
"output": "8281"
},
{
"input": "773\n70",
"output": "123904"
},
{
"input": "825\n729",
"output": "2352"
},
{
"input": "944\n348",
"output": "89102"
},
{
"input": "352\n445",
"output": "2209"
},
{
"input": "529\n656",
"output": "4096"
},
{
"input": "19\n315",
"output": "22052"
},
{
"input": "138\n370",
"output": "13572"
},
{
"input": "546\n593",
"output": "576"
},
{
"input": "285\n242",
"output": "484"
},
{
"input": "773\n901",
"output": "4160"
},
{
"input": "892\n520",
"output": "34782"
},
{
"input": "864\n179",
"output": "117649"
},
{
"input": "479\n470",
"output": "25"
},
{
"input": "967\n487",
"output": "57840"
},
{
"input": "648\n106",
"output": "73712"
},
{
"input": "58\n765",
"output": "125316"
},
{
"input": "235\n56",
"output": "8100"
},
{
"input": "285\n153",
"output": "4422"
},
{
"input": "943\n13",
"output": "216690"
},
{
"input": "675\n541",
"output": "4556"
},
{
"input": "4\n912",
"output": "206570"
}
] | 1,672,277,144 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | import math as m
a=int(input())
b=int(input())
if b<a:
a,b=b,a
d=a+m.ceil(abs(a-b)/2)
x=d-a
y=b-d
stress=0
for i in range(1,x+1):
stress+=i
for i in range(1,y+1):
stress+=i
print(stress) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
Input Specification:
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*.
Output Specification:
Print the minimum possible total tiredness if the friends meet in the same point.
Demo Input:
['3\n4\n', '101\n99\n', '5\n10\n']
Demo Output:
['1\n', '2\n', '9\n']
Note:
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | ```python
import math as m
a=int(input())
b=int(input())
if b<a:
a,b=b,a
d=a+m.ceil(abs(a-b)/2)
x=d-a
y=b-d
stress=0
for i in range(1,x+1):
stress+=i
for i in range(1,y+1):
stress+=i
print(stress)
``` | 3 |
|
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy. | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n1000",
"output": "1"
},
{
"input": "5 1\n100 100 100 100 100\n100",
"output": "1"
},
{
"input": "2 1\n2 1\n1",
"output": "1"
},
{
"input": "2 3\n3 1\n2 4 2",
"output": "1"
},
{
"input": "1 5\n4\n1 4 3 3 2",
"output": "0"
},
{
"input": "5 3\n4 2 3 1 1\n2 1 3",
"output": "3"
},
{
"input": "3 5\n5 2 5\n1 4 1 4 2",
"output": "0"
},
{
"input": "7 3\n9 7 10 2 1 1 1\n8 9 6",
"output": "3"
},
{
"input": "5 3\n2 5 3 3 2\n2 5 3",
"output": "3"
}
] | 1,592,909,059 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 218 | 22,220,800 | def solution(l1,l2,l3):
n,m=l1[0],l2[1]
costs=l2
bills=l3
i=0
ans=0
while i<len(costs):
bill=bills[0]
if bill>=costs[i]:
ans+=1
bills.remove(bill)
i+=1
return ans
def answer():
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
l3 = [int(x) for x in input().split()]
print(solution(l1,l2,l3))
answer() | Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy.
Input Specification:
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Output Specification:
Print a single integer — the number of games Maxim will buy.
Demo Input:
['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n']
Demo Output:
['3\n', '0\n', '4\n']
Note:
The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | ```python
def solution(l1,l2,l3):
n,m=l1[0],l2[1]
costs=l2
bills=l3
i=0
ans=0
while i<len(costs):
bill=bills[0]
if bill>=costs[i]:
ans+=1
bills.remove(bill)
i+=1
return ans
def answer():
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
l3 = [int(x) for x in input().split()]
print(solution(l1,l2,l3))
answer()
``` | -1 |
|
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve? | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems. | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62",
"output": "100"
},
{
"input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98",
"output": "98"
},
{
"input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2",
"output": "39"
},
{
"input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16",
"output": "99"
},
{
"input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1",
"output": "1"
},
{
"input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "3 2\n1 4 1",
"output": "2"
},
{
"input": "1 2\n100",
"output": "0"
},
{
"input": "7 4\n4 2 3 4 4 2 3",
"output": "7"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "1 2\n15",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "5 3\n3 4 3 2 1",
"output": "4"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "1 5\n1",
"output": "1"
},
{
"input": "6 6\n7 1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n6 5 5 5 5",
"output": "4"
},
{
"input": "1 4\n2",
"output": "1"
},
{
"input": "9 4\n1 2 1 2 4 2 1 2 1",
"output": "9"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n5",
"output": "1"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4",
"output": "71"
},
{
"input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90",
"output": "63"
},
{
"input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8",
"output": "61"
},
{
"input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22",
"output": "72"
},
{
"input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2",
"output": "52"
},
{
"input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90",
"output": "60"
},
{
"input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10",
"output": "56"
},
{
"input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90",
"output": "61"
},
{
"input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24",
"output": "99"
},
{
"input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50",
"output": "99"
},
{
"input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48",
"output": "99"
},
{
"input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57",
"output": "99"
},
{
"input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93",
"output": "99"
},
{
"input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33",
"output": "3"
},
{
"input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51",
"output": "3"
},
{
"input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49",
"output": "6"
},
{
"input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8",
"output": "66"
},
{
"input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95",
"output": "0"
},
{
"input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66",
"output": "0"
},
{
"input": "2 8\n8 8",
"output": "2"
},
{
"input": "1 6\n3",
"output": "1"
},
{
"input": "1 5\n5",
"output": "1"
}
] | 1,676,967,323 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 77 | 0 | from collections import deque
n, k = map(int, input().split())
lst = deque(map(int, input().split()))
while len(lst) > 0 and lst[0] <= k:
lst.popleft()
while len(lst) > 0 and lst[-1] <= k:
lst.pop()
print(n - len(lst)) | Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
Input Specification:
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Output Specification:
Print one integer — the maximum number of problems Mishka can solve.
Demo Input:
['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n']
Demo Output:
['5\n', '0\n', '5\n']
Note:
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems. | ```python
from collections import deque
n, k = map(int, input().split())
lst = deque(map(int, input().split()))
while len(lst) > 0 and lst[0] <= k:
lst.popleft()
while len(lst) > 0 and lst[-1] <= k:
lst.pop()
print(n - len(lst))
``` | 3 |
|
491 | B | New York Hotel | PROGRAMMING | 2,100 | [
"greedy",
"math"
] | null | null | Think of New York as a rectangular grid consisting of *N* vertical avenues numerated from 1 to *N* and *M* horizontal streets numerated 1 to *M*. *C* friends are staying at *C* hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of *H* restaurants also located at some street-avenue crossings. They also want that the maximum distance covered by one of them while traveling to the restaurant to be minimum possible. Help friends choose optimal restaurant for a celebration.
Suppose that the distance between neighboring crossings are all the same equal to one kilometer. | The first line contains two integers *N* и *M* — size of the city (1<=≤<=*N*,<=*M*<=≤<=109). In the next line there is a single integer *C* (1<=≤<=*C*<=≤<=105) — the number of hotels friends stayed at. Following *C* lines contain descriptions of hotels, each consisting of two coordinates *x* and *y* (1<=≤<=*x*<=≤<=*N*, 1<=≤<=*y*<=≤<=*M*). The next line contains an integer *H* — the number of restaurants (1<=≤<=*H*<=≤<=105). Following *H* lines contain descriptions of restaurants in the same format.
Several restaurants and hotels may be located near the same crossing. | In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them. | [
"10 10\n2\n1 1\n3 3\n2\n1 10\n4 4\n"
] | [
"6\n2\n"
] | none | 1,000 | [
{
"input": "10 10\n2\n1 1\n3 3\n2\n1 10\n4 4",
"output": "6\n2"
},
{
"input": "100 100\n10\n53 20\n97 6\n12 74\n48 92\n97 13\n47 96\n75 32\n69 21\n95 75\n1 54\n10\n36 97\n41 1\n1 87\n39 23\n27 44\n73 97\n1 1\n6 26\n48 3\n5 69",
"output": "108\n4"
},
{
"input": "100 100\n10\n86 72\n25 73\n29 84\n34 33\n29 20\n84 83\n41 80\n22 22\n16 89\n77 49\n1\n4 23",
"output": "140\n1"
},
{
"input": "100 100\n1\n66 77\n10\n70 11\n76 69\n79 39\n90 3\n38 87\n61 81\n98 66\n63 68\n62 93\n53 36",
"output": "9\n6"
},
{
"input": "1000000000 1000000000\n1\n1 1\n1\n1000000000 1000000000",
"output": "1999999998\n1"
},
{
"input": "123456789 987654321\n1\n312 987654321\n1\n123456789 213",
"output": "1111110585\n1"
},
{
"input": "453456789 987654321\n1\n443943901 1\n1\n1354 213389832",
"output": "657332378\n1"
},
{
"input": "923456789 987654321\n1\n443943901 132319791\n1\n1354 560",
"output": "576261778\n1"
},
{
"input": "100 100\n1\n1 100\n1\n1 100",
"output": "0\n1"
},
{
"input": "1 1\n1\n1 1\n1\n1 1",
"output": "0\n1"
},
{
"input": "1000000000 1000000000\n2\n1 1\n3 3\n2\n1 10\n4 4",
"output": "6\n2"
}
] | 1,419,910,593 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | #!/usr/bin/env python3
n, m = map(int, input().split())
minx = miny = n + m
maxx = maxy = - minx
dist = n + m + 1
c = int(input())
for _ in range(c):
x, y = map(int, input().split())
minx = min(minx, x - y)
miny = min(miny, x + y)
maxx = max(maxx, x - y)
maxy = max(maxy, x + y)
h = int(input())
for i in range(h):
a, b = map(int, input().split())
x = a - b
y = a + b
maxxy = max(
max(abs(minx - x), abs(maxx - x)),
max(abs(miny - y), abs(maxy - y))
)
if maxxy < dist:
dist = maxxy
res = i
print(dist)
print(res)
| Title: New York Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Think of New York as a rectangular grid consisting of *N* vertical avenues numerated from 1 to *N* and *M* horizontal streets numerated 1 to *M*. *C* friends are staying at *C* hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of *H* restaurants also located at some street-avenue crossings. They also want that the maximum distance covered by one of them while traveling to the restaurant to be minimum possible. Help friends choose optimal restaurant for a celebration.
Suppose that the distance between neighboring crossings are all the same equal to one kilometer.
Input Specification:
The first line contains two integers *N* и *M* — size of the city (1<=≤<=*N*,<=*M*<=≤<=109). In the next line there is a single integer *C* (1<=≤<=*C*<=≤<=105) — the number of hotels friends stayed at. Following *C* lines contain descriptions of hotels, each consisting of two coordinates *x* and *y* (1<=≤<=*x*<=≤<=*N*, 1<=≤<=*y*<=≤<=*M*). The next line contains an integer *H* — the number of restaurants (1<=≤<=*H*<=≤<=105). Following *H* lines contain descriptions of restaurants in the same format.
Several restaurants and hotels may be located near the same crossing.
Output Specification:
In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them.
Demo Input:
['10 10\n2\n1 1\n3 3\n2\n1 10\n4 4\n']
Demo Output:
['6\n2\n']
Note:
none | ```python
#!/usr/bin/env python3
n, m = map(int, input().split())
minx = miny = n + m
maxx = maxy = - minx
dist = n + m + 1
c = int(input())
for _ in range(c):
x, y = map(int, input().split())
minx = min(minx, x - y)
miny = min(miny, x + y)
maxx = max(maxx, x - y)
maxy = max(maxy, x + y)
h = int(input())
for i in range(h):
a, b = map(int, input().split())
x = a - b
y = a + b
maxxy = max(
max(abs(minx - x), abs(maxx - x)),
max(abs(miny - y), abs(maxy - y))
)
if maxxy < dist:
dist = maxxy
res = i
print(dist)
print(res)
``` | 0 |
|
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,558,541,880 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 93 | 0 | s=[int(n) for n in input().split()]
if abs(s[0]-s[1])<=1:
print('YES')
else:
print('NO') | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
s=[int(n) for n in input().split()]
if abs(s[0]-s[1])<=1:
print('YES')
else:
print('NO')
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system.
Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 0 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"input": "1000000000",
"output": "1\n999999932"
},
{
"input": "999999979",
"output": "2\n999999899\n999999908"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "1\n5"
},
{
"input": "11",
"output": "1\n10"
},
{
"input": "39",
"output": "1\n33"
},
{
"input": "66",
"output": "1\n60"
},
{
"input": "75",
"output": "0"
},
{
"input": "100",
"output": "1\n86"
},
{
"input": "101",
"output": "2\n91\n100"
},
{
"input": "2014",
"output": "2\n1988\n2006"
},
{
"input": "999999994",
"output": "0"
}
] | 1,508,154,795 | 2,895 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 46 | 0 | import math
def sumn(n):
k = str(n)
ans = 0
for elem in k:
ans += int(elem)
return ans
n = int(input())
a = int(math.log10(n)) + 1
res = []
for i in range(n - a * 10, n):
if i + sumn(i) == n:
res.append(i)
print(len(res))
if res:
print(*res) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system.
Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order.
Demo Input:
['21\n', '20\n']
Demo Output:
['1\n15\n', '0\n']
Note:
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | ```python
import math
def sumn(n):
k = str(n)
ans = 0
for elem in k:
ans += int(elem)
return ans
n = int(input())
a = int(math.log10(n)) + 1
res = []
for i in range(n - a * 10, n):
if i + sumn(i) == n:
res.append(i)
print(len(res))
if res:
print(*res)
``` | -1 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,586,890,320 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | x=str(input())
y=str(input())
c=0
l=len(x)
ll=len(y)
if(l==ll):
for i in range(l):
if(x[i]==y[i]):
print("0",end="")
else:
print("1",end="")
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
x=str(input())
y=str(input())
c=0
l=len(x)
ll=len(y)
if(l==ll):
for i in range(l):
if(x[i]==y[i]):
print("0",end="")
else:
print("1",end="")
``` | 3.969 |
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,609,147,657 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | a,b=map(int,input().split())
c=0
while(a and b):
if a>b:
a=max(a-2,0)
b+=1
else:
a+=1
b=max(b-2,0)
c+=1
print(c) | 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())
c=0
while(a and b):
if a>b:
a=max(a-2,0)
b+=1
else:
a+=1
b=max(b-2,0)
c+=1
print(c)
``` | 0 |
|
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,666,917,221 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 92 | 0 | lst=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
n,m=map(int,input().split())
ind=lst.index(n)
if ind==len(lst)-1:
print('NO')
else:
if m==lst[ind+1]:
print('YES')
else:
print('NO') | 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
lst=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
n,m=map(int,input().split())
ind=lst.index(n)
if ind==len(lst)-1:
print('NO')
else:
if m==lst[ind+1]:
print('YES')
else:
print('NO')
``` | 3.977 |
620 | E | New Year Tree | PROGRAMMING | 2,100 | [
"bitmasks",
"data structures",
"trees"
] | null | null | The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.
The New Year tree is an undirected tree with *n* vertices and root in the vertex 1.
You should process the queries of the two types:
1. Change the colours of all vertices in the subtree of the vertex *v* to the colour *c*. 1. Find the number of different colours in the subtree of the vertex *v*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=4·105) — the number of vertices in the tree and the number of the queries.
The second line contains *n* integers *c**i* (1<=≤<=*c**i*<=≤<=60) — the colour of the *i*-th vertex.
Each of the next *n*<=-<=1 lines contains two integers *x**j*,<=*y**j* (1<=≤<=*x**j*,<=*y**j*<=≤<=*n*) — the vertices of the *j*-th edge. It is guaranteed that you are given correct undirected tree.
The last *m* lines contains the description of the queries. Each description starts with the integer *t**k* (1<=≤<=*t**k*<=≤<=2) — the type of the *k*-th query. For the queries of the first type then follows two integers *v**k*,<=*c**k* (1<=≤<=*v**k*<=≤<=*n*,<=1<=≤<=*c**k*<=≤<=60) — the number of the vertex whose subtree will be recoloured with the colour *c**k*. For the queries of the second type then follows integer *v**k* (1<=≤<=*v**k*<=≤<=*n*) — the number of the vertex for which subtree you should find the number of different colours. | For each query of the second type print the integer *a* — the number of different colours in the subtree of the vertex given in the query.
Each of the numbers should be printed on a separate line in order of query appearing in the input. | [
"7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3\n",
"23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n"
] | [
"2\n3\n4\n5\n1\n2\n",
"6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3\n"
] | none | 0 | [
{
"input": "7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3",
"output": "2\n3\n4\n5\n1\n2"
},
{
"input": "23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4",
"output": "6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3"
},
{
"input": "1 1\n14\n2 1",
"output": "1"
},
{
"input": "1 1\n36\n2 1",
"output": "1"
},
{
"input": "1 1\n3\n2 1",
"output": "1"
},
{
"input": "1 1\n43\n2 1",
"output": "1"
},
{
"input": "1 1\n41\n2 1",
"output": "1"
},
{
"input": "10 10\n59 59 59 59 59 59 59 59 59 59\n6 8\n6 10\n2 6\n2 5\n7 2\n10 1\n4 2\n7 3\n9 1\n1 8 59\n2 8\n1 3 59\n1 4 59\n1 8 59\n1 2 59\n1 5 59\n1 10 59\n2 2\n2 5",
"output": "1\n1\n1"
},
{
"input": "10 10\n8 8 14 32 14 8 32 8 14 32\n4 5\n4 1\n4 8\n4 9\n7 4\n2 5\n3 5\n4 6\n10 4\n2 2\n1 9 8\n1 1 40\n1 7 32\n1 4 8\n2 8\n1 1 8\n2 2\n2 8\n2 4",
"output": "1\n1\n1\n1\n1"
},
{
"input": "10 10\n39 50 50 7 39 7 46 7 39 7\n10 7\n7 3\n3 5\n3 4\n6 4\n1 4\n1 8\n8 2\n2 9\n2 8\n1 6 50\n2 4\n2 6\n1 7 39\n1 3 39\n2 9\n1 1 15\n2 7\n1 10 7",
"output": "3\n4\n1\n1\n1"
},
{
"input": "10 10\n23 25 23 42 23 53 49 40 28 44\n1 7\n1 2\n2 4\n4 10\n8 10\n6 8\n3 8\n5 3\n9 5\n2 10\n1 6 52\n1 8 43\n2 3\n1 4 39\n1 8 44\n1 9 39\n2 1\n2 4\n1 6 36",
"output": "5\n1\n5\n2"
},
{
"input": "10 10\n16 25 25 27 39 29 29 58 50 30\n8 2\n2 10\n4 2\n2 1\n6 2\n2 3\n9 2\n5 2\n2 7\n2 4\n1 3 31\n2 5\n1 7 27\n1 4 56\n1 4 52\n1 5 25\n1 6 32\n1 6 22\n1 7 42",
"output": "1\n1"
},
{
"input": "10 10\n60 46 56 7 4 27 43 28 4 9\n1 5\n5 8\n10 8\n10 6\n7 6\n2 10\n4 2\n9 4\n9 3\n2 3\n1 9 57\n2 2\n1 6 50\n1 5 34\n1 8 45\n1 9 39\n2 2\n1 10 1\n2 4",
"output": "1\n3\n2\n1"
},
{
"input": "10 10\n15 39 52 24 36 30 46 21 40 24\n5 9\n5 3\n5 10\n1 3\n9 4\n9 8\n9 7\n7 2\n3 6\n1 4 47\n1 7 25\n1 10 42\n2 10\n1 2 18\n1 1 60\n1 7 56\n2 7\n2 9\n2 10",
"output": "1\n1\n2\n1"
},
{
"input": "10 10\n39 28 21 20 11 11 40 30 42 14\n7 1\n10 1\n6 1\n1 9\n5 1\n8 1\n1 3\n1 4\n2 10\n1 7 55\n2 3\n1 8 18\n1 10 48\n2 7\n1 6 26\n2 2\n1 1 4\n2 9\n1 5 31",
"output": "1\n1\n1\n1"
}
] | 1,647,794,260 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | # # def should_i_stay_or_should_i_go(d,i,H,E,N):
# # temp1=H
# # temp2=E
# # x=()
# # if d[i]=='om':
# # temp2 = temp2 - 2
# # if temp1>=N-1 and temp2>N-1:
# # x.add(temp1)
# # x.add(temp2)
# # return x
# # if d[i]=='Milk':
# # temp1=temp1-3
# # if temp1>=N-1 and temp2>N-1:
# # x.add(temp1)
# # x.add(temp2)
# # return x
# # if d[i]=='Cake':
# # temp1=temp1-1
# # temp2 = temp2 - 1
# # if temp1>=N-1 and temp2>N-1:
# # x.add(temp1)
# # x.add(temp2)
# # return x
# #for i in l:
# # while(N!=0 and (E>0 or H>0)):
# # print(i)
# # temp1 = H
# # temp2 = E
# # if i == 'om':
# # temp2 = temp2 - 2
# # if temp1 >= N - 1 and temp2 > N - 1:
# # E=E-2
# # P += d[i]
# # if i == 'Milk':
# # temp1 = temp1 - 3
# # if temp1 >= N - 1 and temp2 > N - 1:
# # H=H-3
# # P += d[i]
# # if i == 'Cake':
# # temp1 = temp1 - 1
# # temp2 = temp2 - 1
# # if temp1 >= N - 1 and temp2 > N - 1:
# # E=E-1
# # H=H-1
# # P += d[i]
# # N=N-1
#
#
for _ in range(int(input())):
P=0
N, E, H, A, B,C=list(map(int,input().split()))
if N>=1 and N<=100:
d={}
d['om']=A
d['Milk'] = B
d['Cake'] = C
temp=list(d.values())
if E<N and H<N:
print('-1')
continue
d2={}
temp.sort()
for i in temp :
for j in d.keys():
if d[j]==i:
d2[j]=i
l=list(d2.keys())
M=N
try:
i=0
Choclate = H
Eggs = E
while(N>0):
x=l[i]
Choclate = H
Eggs = E
if x == 'om':
if Eggs>=2:
E=E-2
P += d[x]
N = N - 1
else:
i=i+1
if x == 'Milk':
if Choclate >=3:
H=H-3
P += d[x]
N = N - 1
else:
i=i+1
if x == 'Cake':
if Choclate >=1 and Eggs >=1:
E=E-1
H=H-1
P += d[x]
N = N - 1
else:
i=i+1
print(P)
except:
P=0
print(M*C)
| Title: New Year Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.
The New Year tree is an undirected tree with *n* vertices and root in the vertex 1.
You should process the queries of the two types:
1. Change the colours of all vertices in the subtree of the vertex *v* to the colour *c*. 1. Find the number of different colours in the subtree of the vertex *v*.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=4·105) — the number of vertices in the tree and the number of the queries.
The second line contains *n* integers *c**i* (1<=≤<=*c**i*<=≤<=60) — the colour of the *i*-th vertex.
Each of the next *n*<=-<=1 lines contains two integers *x**j*,<=*y**j* (1<=≤<=*x**j*,<=*y**j*<=≤<=*n*) — the vertices of the *j*-th edge. It is guaranteed that you are given correct undirected tree.
The last *m* lines contains the description of the queries. Each description starts with the integer *t**k* (1<=≤<=*t**k*<=≤<=2) — the type of the *k*-th query. For the queries of the first type then follows two integers *v**k*,<=*c**k* (1<=≤<=*v**k*<=≤<=*n*,<=1<=≤<=*c**k*<=≤<=60) — the number of the vertex whose subtree will be recoloured with the colour *c**k*. For the queries of the second type then follows integer *v**k* (1<=≤<=*v**k*<=≤<=*n*) — the number of the vertex for which subtree you should find the number of different colours.
Output Specification:
For each query of the second type print the integer *a* — the number of different colours in the subtree of the vertex given in the query.
Each of the numbers should be printed on a separate line in order of query appearing in the input.
Demo Input:
['7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3\n', '23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n']
Demo Output:
['2\n3\n4\n5\n1\n2\n', '6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3\n']
Note:
none | ```python
# # def should_i_stay_or_should_i_go(d,i,H,E,N):
# # temp1=H
# # temp2=E
# # x=()
# # if d[i]=='om':
# # temp2 = temp2 - 2
# # if temp1>=N-1 and temp2>N-1:
# # x.add(temp1)
# # x.add(temp2)
# # return x
# # if d[i]=='Milk':
# # temp1=temp1-3
# # if temp1>=N-1 and temp2>N-1:
# # x.add(temp1)
# # x.add(temp2)
# # return x
# # if d[i]=='Cake':
# # temp1=temp1-1
# # temp2 = temp2 - 1
# # if temp1>=N-1 and temp2>N-1:
# # x.add(temp1)
# # x.add(temp2)
# # return x
# #for i in l:
# # while(N!=0 and (E>0 or H>0)):
# # print(i)
# # temp1 = H
# # temp2 = E
# # if i == 'om':
# # temp2 = temp2 - 2
# # if temp1 >= N - 1 and temp2 > N - 1:
# # E=E-2
# # P += d[i]
# # if i == 'Milk':
# # temp1 = temp1 - 3
# # if temp1 >= N - 1 and temp2 > N - 1:
# # H=H-3
# # P += d[i]
# # if i == 'Cake':
# # temp1 = temp1 - 1
# # temp2 = temp2 - 1
# # if temp1 >= N - 1 and temp2 > N - 1:
# # E=E-1
# # H=H-1
# # P += d[i]
# # N=N-1
#
#
for _ in range(int(input())):
P=0
N, E, H, A, B,C=list(map(int,input().split()))
if N>=1 and N<=100:
d={}
d['om']=A
d['Milk'] = B
d['Cake'] = C
temp=list(d.values())
if E<N and H<N:
print('-1')
continue
d2={}
temp.sort()
for i in temp :
for j in d.keys():
if d[j]==i:
d2[j]=i
l=list(d2.keys())
M=N
try:
i=0
Choclate = H
Eggs = E
while(N>0):
x=l[i]
Choclate = H
Eggs = E
if x == 'om':
if Eggs>=2:
E=E-2
P += d[x]
N = N - 1
else:
i=i+1
if x == 'Milk':
if Choclate >=3:
H=H-3
P += d[x]
N = N - 1
else:
i=i+1
if x == 'Cake':
if Choclate >=1 and Eggs >=1:
E=E-1
H=H-1
P += d[x]
N = N - 1
else:
i=i+1
print(P)
except:
P=0
print(M*C)
``` | -1 |
|
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,511,013,227 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
forces = []
for i in range(n):
forces.append(list(map(int, input().split())))
for i in range(n):
if sum(forces[i][0] == 0) and sum(forces[i][1] == 0) and sum(forces[i][1] == 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())
forces = []
for i in range(n):
forces.append(list(map(int, input().split())))
for i in range(n):
if sum(forces[i][0] == 0) and sum(forces[i][1] == 0) and sum(forces[i][1] == 0):
print('YES')
else :
print('NO')
``` | -1 |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "60000",
"output": "0\n30000 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59991",
"output": "0\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59989",
"output": "1\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "6",
"output": "1\n3 1 4 5 "
},
{
"input": "7",
"output": "0\n3\n1 6 7 "
},
{
"input": "8",
"output": "0\n4 1 4 5 8 "
},
{
"input": "9",
"output": "1\n5\n1 2 3 8 9 "
},
{
"input": "10",
"output": "1\n5 1 4 5 8 9 "
},
{
"input": "11",
"output": "0\n5\n1 2 9 10 11 "
},
{
"input": "12",
"output": "0\n6 1 4 5 8 9 12 "
},
{
"input": "13",
"output": "1\n7\n1 2 3 4 11 12 13 "
},
{
"input": "14",
"output": "1\n7 1 4 5 8 9 12 13 "
},
{
"input": "15",
"output": "0\n7\n1 2 3 12 13 14 15 "
},
{
"input": "16",
"output": "0\n8 1 4 5 8 9 12 13 16 "
},
{
"input": "17",
"output": "1\n9\n1 2 3 4 5 14 15 16 17 "
},
{
"input": "18",
"output": "1\n9 1 4 5 8 9 12 13 16 17 "
},
{
"input": "19",
"output": "0\n9\n1 2 3 4 15 16 17 18 19 "
},
{
"input": "20",
"output": "0\n10 1 4 5 8 9 12 13 16 17 20 "
},
{
"input": "21",
"output": "1\n11\n1 2 3 4 5 6 17 18 19 20 21 "
},
{
"input": "22",
"output": "1\n11 1 4 5 8 9 12 13 16 17 20 21 "
},
{
"input": "23",
"output": "0\n11\n1 2 3 4 5 18 19 20 21 22 23 "
},
{
"input": "24",
"output": "0\n12 1 4 5 8 9 12 13 16 17 20 21 24 "
},
{
"input": "59999",
"output": "0\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59997",
"output": "1\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59996",
"output": "0\n29998 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59995",
"output": "0\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59994",
"output": "1\n29997 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59993",
"output": "1\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59992",
"output": "0\n29996 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59990",
"output": "1\n29995 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "100",
"output": "0\n50 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 "
},
{
"input": "1000",
"output": "0\n500 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..."
},
{
"input": "10001",
"output": "1\n5001\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "103",
"output": "0\n51\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 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": "1002",
"output": "1\n501 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..."
},
{
"input": "31724",
"output": "0\n15862 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "2032",
"output": "0\n1016 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "42620",
"output": "0\n21310 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "18076",
"output": "0\n9038 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "53520",
"output": "0\n26760 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "37193",
"output": "1\n18597\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "12645",
"output": "1\n6323\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "53237",
"output": "1\n26619\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "28693",
"output": "1\n14347\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "4145",
"output": "1\n2073\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "36042",
"output": "1\n18021 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "16646",
"output": "1\n8323 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "57238",
"output": "1\n28619 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "27542",
"output": "1\n13771 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "8146",
"output": "1\n4073 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "46659",
"output": "0\n23329\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "27259",
"output": "0\n13629\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "2715",
"output": "0\n1357\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "38159",
"output": "0\n19079\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "18759",
"output": "0\n9379\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
}
] | 1,679,607,189 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 223,744,000 | import itertools
n = int(input())
nums = list(range(1, n + 1))
total_sum = (n * (n + 1)) // 2
min_diff = total_sum
min_group1 = []
dp = [[0 for _ in range(total_sum + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, total_sum + 1):
if j < i:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = max(dp[i-1][j], dp[i-1][j-i] + i)
for i in range(total_sum // 2, -1, -1):
if dp[n][i] <= i:
min_diff = total_sum - 2 * i
group1_sum = i
break
for i in range(n, 0, -1):
if group1_sum >= i and dp[i][group1_sum] == dp[i-1][group1_sum-i] + i:
min_group1.append(i)
group1_sum -= i
min_group1.reverse()
if min_diff == total_sum:
min_group1 = nums
print(min_diff)
print(len(min_group1), *min_group1)
| Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Output Specification:
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Demo Input:
['4\n', '2\n']
Demo Output:
['0\n2 1 4 \n', '1\n1 1 \n']
Note:
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | ```python
import itertools
n = int(input())
nums = list(range(1, n + 1))
total_sum = (n * (n + 1)) // 2
min_diff = total_sum
min_group1 = []
dp = [[0 for _ in range(total_sum + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, total_sum + 1):
if j < i:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = max(dp[i-1][j], dp[i-1][j-i] + i)
for i in range(total_sum // 2, -1, -1):
if dp[n][i] <= i:
min_diff = total_sum - 2 * i
group1_sum = i
break
for i in range(n, 0, -1):
if group1_sum >= i and dp[i][group1_sum] == dp[i-1][group1_sum-i] + i:
min_group1.append(i)
group1_sum -= i
min_group1.reverse()
if min_diff == total_sum:
min_group1 = nums
print(min_diff)
print(len(min_group1), *min_group1)
``` | 0 |
|
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n0 1 1",
"output": "YES"
},
{
"input": "3\n0 1 0",
"output": "NO"
},
{
"input": "2\n0 1",
"output": "YES"
},
{
"input": "2\n1 0",
"output": "YES"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "10\n1 0 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5\n1 1 1 1 0",
"output": "YES"
},
{
"input": "4\n1 0 1 0",
"output": "NO"
},
{
"input": "4\n1 1 0 0",
"output": "NO"
},
{
"input": "10\n0 0 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "94\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "64\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "34\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "10\n1 1 0 1 1 1 0 1 1 1",
"output": "NO"
}
] | 1,536,213,141 | 141 | Python 3 | WRONG_ANSWER | TESTS | 12 | 109 | 0 | n = int(input())
a = list(map(int, input().split()))
print('YES' if a.count(0) == 1 else 'NO')
| Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
Output Specification:
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
Demo Input:
['3\n1 0 1\n', '3\n1 0 0\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
print('YES' if a.count(0) == 1 else 'NO')
``` | 0 |
|
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number *n* and array *a*.
But Valera could have made a mistake, because he hasn't yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of *n* doesn't exist, print -1. | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, you are allowed to print any of them. | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input": "7",
"output": "7 6 5 4 3 2 1 "
},
{
"input": "8",
"output": "8 7 6 5 4 3 2 1 "
},
{
"input": "9",
"output": "9 8 7 6 5 4 3 2 1 "
},
{
"input": "50",
"output": "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 "
},
{
"input": "22",
"output": "22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "34",
"output": "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 "
},
{
"input": "50",
"output": "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 "
},
{
"input": "12",
"output": "12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "26",
"output": "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 "
},
{
"input": "38",
"output": "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 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "18",
"output": "18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "30",
"output": "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 "
},
{
"input": "46",
"output": "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 "
},
{
"input": "32",
"output": "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,628,775,430 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,963,200 | n = int(input())
a = [0 for i in range(n)]
a[0] = 1
for j in range(1, n):
a[j] = 100-j
def printArray(a):
for k in range(0,len(a)):
if k == len(a)-1:
print(a[k])
else:
print(a[k], end = " ")
if n == 1:
print("-1")
else:
printArray(a) | Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number *n* and array *a*.
But Valera could have made a mistake, because he hasn't yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of *n* doesn't exist, print -1.
Input Specification:
You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array.
Output Specification:
Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, you are allowed to print any of them.
Demo Input:
['1\n']
Demo Output:
['-1\n']
Note:
none | ```python
n = int(input())
a = [0 for i in range(n)]
a[0] = 1
for j in range(1, n):
a[j] = 100-j
def printArray(a):
for k in range(0,len(a)):
if k == len(a)-1:
print(a[k])
else:
print(a[k], end = " ")
if n == 1:
print("-1")
else:
printArray(a)
``` | 0 |
|
514 | C | Watto and Mechanism | PROGRAMMING | 2,000 | [
"binary search",
"data structures",
"hashing",
"string suffix structures",
"strings"
] | null | null | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism should be able to process queries of the following type: "Given string *s*, determine if the memory of the mechanism contains string *t* that consists of the same number of characters as *s* and differs from *s* in exactly one position".
Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of *n* initial lines and *m* queries. He decided to entrust this job to you. | The first line contains two non-negative numbers *n* and *m* (0<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of the initial strings and the number of queries, respectively.
Next follow *n* non-empty strings that are uploaded to the memory of the mechanism.
Next follow *m* non-empty strings that are the queries to the mechanism.
The total length of lines in the input doesn't exceed 6·105. Each line consists only of letters 'a', 'b', 'c'. | For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes). | [
"2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n"
] | [
"YES\nNO\nNO\n"
] | none | 2,000 | [
{
"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac",
"output": "YES\nNO\nNO"
},
{
"input": "1 5\nacbacbacb\ncbacbacb\nacbacbac\naacbacbacb\nacbacbacbb\nacbaabacb",
"output": "NO\nNO\nNO\nNO\nYES"
},
{
"input": "5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb",
"output": "YES\nYES\nNO\nYES"
},
{
"input": "9 9\ncaccbcacabccba\naacbcbcaabacbcbcba\nbabccaaacccacbb\ncaaabcaacbababbabbb\nabbaccacabacaaaa\nbccbccababcaacb\ncaacbcaacbababbabbb\nbcacababbbcaaca\nccbbcbababbccaab\nbbcbccababcaacb\naacccbabbacbabacaca\nbbcbcccbabcaacb\nacbacacbcacc\ncaaabcaaabacabbabbb\nabbbabaaaba\naacccbcaabacbcbcba\nabbaccacabbcaaaa\naaccbbcabbacbcbcba",
"output": "YES\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO"
},
{
"input": "1 1\nbbbbbbbaaaabbbbbaabbbba\naaabbbabbbbbbbaabbabbbb",
"output": "NO"
}
] | 1,668,615,063 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | from collections import deque
class Trie:
def __init__(self):
self.root = {}
def insert(self, word):
t = self.root
for i in word:
if i not in t:
t[i] = {}
t = t[i]
t["-"] = True
def query(self,word):
queue = deque()
queue.append([self.root,0])
ind =0
while queue:
node,cnt = queue.popleft()
if cnt>1:
continue
while ind<len(word):
if word[ind] not in node:
if 'a' in node: queue.append([node['a'],cnt+1])
if 'b' in node: queue.append([node['b'],cnt+1])
if 'c' in node: queue.append([node['c'],cnt+1])
ind+=1
break
else:
node = node[word[ind]]
ind+=1
else:
if cnt==1:
return True
return False
n, m = map(int, input().split())
trie = Trie()
for _ in range(n):
trie.insert(input())
for _ in range(m):
inp = input()
if trie.query(inp):
print("YES")
else:
print("NO") | Title: Watto and Mechanism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism should be able to process queries of the following type: "Given string *s*, determine if the memory of the mechanism contains string *t* that consists of the same number of characters as *s* and differs from *s* in exactly one position".
Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of *n* initial lines and *m* queries. He decided to entrust this job to you.
Input Specification:
The first line contains two non-negative numbers *n* and *m* (0<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of the initial strings and the number of queries, respectively.
Next follow *n* non-empty strings that are uploaded to the memory of the mechanism.
Next follow *m* non-empty strings that are the queries to the mechanism.
The total length of lines in the input doesn't exceed 6·105. Each line consists only of letters 'a', 'b', 'c'.
Output Specification:
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
Demo Input:
['2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
none | ```python
from collections import deque
class Trie:
def __init__(self):
self.root = {}
def insert(self, word):
t = self.root
for i in word:
if i not in t:
t[i] = {}
t = t[i]
t["-"] = True
def query(self,word):
queue = deque()
queue.append([self.root,0])
ind =0
while queue:
node,cnt = queue.popleft()
if cnt>1:
continue
while ind<len(word):
if word[ind] not in node:
if 'a' in node: queue.append([node['a'],cnt+1])
if 'b' in node: queue.append([node['b'],cnt+1])
if 'c' in node: queue.append([node['c'],cnt+1])
ind+=1
break
else:
node = node[word[ind]]
ind+=1
else:
if cnt==1:
return True
return False
n, m = map(int, input().split())
trie = Trie()
for _ in range(n):
trie.insert(input())
for _ in range(m):
inp = input()
if trie.query(inp):
print("YES")
else:
print("NO")
``` | 0 |
|
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,695,308,358 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | for i in range(5):
p=input()
if '1' in p:
x=abs(i-2)
s=p.split()
for j in range(5):
if s[j]=='1':
y=abs(j-2)
print(x+y)
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
for i in range(5):
p=input()
if '1' in p:
x=abs(i-2)
s=p.split()
for j in range(5):
if s[j]=='1':
y=abs(j-2)
print(x+y)
``` | 3 |
|
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51",
"output": "6"
},
{
"input": "2 400 23 57",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10000 10000 3 2",
"output": "16670000"
},
{
"input": "1 2 1 2",
"output": "1"
},
{
"input": "1 1 2 2",
"output": "1"
},
{
"input": "1 1 10 10",
"output": "1"
},
{
"input": "5324 5439 32 13",
"output": "69622"
},
{
"input": "9000 1 2432 1",
"output": "9000"
},
{
"input": "230 1234 9124 23",
"output": "10"
},
{
"input": "11 1 1 1",
"output": "11"
},
{
"input": "6246 8489 1227 9",
"output": "4858"
},
{
"input": "9 20 5 7",
"output": "6"
}
] | 1,650,349,203 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 62 | 409,600 | #!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
k,n,s,p = map(int, wtf[0].split())
sp = math.ceil(n/s)
pp = (sp/p)
ans = math.ceil(k*pp)
print(ans)
| Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
Input Specification:
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output Specification:
Print a single integer — the minimum number of packs they should buy.
Demo Input:
['5 3 2 3\n', '5 3 100 1\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | ```python
#!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
k,n,s,p = map(int, wtf[0].split())
sp = math.ceil(n/s)
pp = (sp/p)
ans = math.ceil(k*pp)
print(ans)
``` | 3 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,536,339,838 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 278 | 512,000 | import random
y = random.randint(1,6)
w = random.randint(1,6)
if y < w:
y, w = w, y
if y % w == 0:
print('1/' + str(y // w))
else:
print(str(w) + '/' + str(y))
else:
if y % w == 0:
print('1/' + str(y // w))
else:
print(str(w) + '/' + str(y))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
import random
y = random.randint(1,6)
w = random.randint(1,6)
if y < w:
y, w = w, y
if y % w == 0:
print('1/' + str(y // w))
else:
print(str(w) + '/' + str(y))
else:
if y % w == 0:
print('1/' + str(y // w))
else:
print(str(w) + '/' + str(y))
``` | 0 |
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add. | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable. | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
"input": "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n19 16\n17 20\n17 23\n18 22\n18 23\n22 19\n21 20\n23 24",
"output": "215"
},
{
"input": "10 30 1\n4\n1 2\n3 1\n4 1\n1 6\n1 8\n10 1\n2 4\n2 7\n3 4\n3 5\n7 3\n3 9\n10 3\n5 4\n6 4\n7 4\n9 4\n10 4\n6 5\n5 8\n9 5\n10 5\n6 7\n9 6\n10 6\n7 8\n9 7\n10 7\n9 8\n10 8",
"output": "15"
},
{
"input": "10 13 2\n5 10\n2 1\n1 4\n2 3\n2 8\n3 4\n7 3\n4 6\n8 4\n4 9\n6 7\n6 9\n10 6\n7 8",
"output": "23"
},
{
"input": "10 10 3\n2 5 6\n1 3\n4 1\n4 3\n5 3\n3 9\n8 4\n9 4\n5 10\n8 7\n10 8",
"output": "18"
},
{
"input": "10 5 3\n1 5 9\n1 3\n1 8\n2 3\n8 4\n5 7",
"output": "17"
},
{
"input": "6 4 2\n1 4\n1 2\n2 3\n4 5\n5 6",
"output": "2"
},
{
"input": "7 8 2\n1 4\n1 2\n2 3\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7",
"output": "1"
},
{
"input": "5 2 3\n1 3 4\n1 5\n2 4",
"output": "0"
},
{
"input": "5 3 2\n1 2\n2 3\n2 4\n1 5",
"output": "1"
},
{
"input": "9 5 2\n1 5\n1 2\n2 3\n3 4\n5 6\n6 7",
"output": "13"
},
{
"input": "6 4 1\n1\n2 3\n3 4\n4 5\n5 6",
"output": "11"
},
{
"input": "6 4 2\n1 5\n1 2\n2 3\n3 4\n5 6",
"output": "3"
},
{
"input": "7 3 3\n1 5 6\n1 2\n1 3\n6 7",
"output": "4"
},
{
"input": "5 2 2\n1 2\n1 3\n2 4",
"output": "2"
},
{
"input": "11 7 2\n1 4\n1 2\n1 3\n4 5\n4 6\n5 6\n9 10\n1 11",
"output": "24"
},
{
"input": "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10",
"output": "89"
}
] | 1,514,935,649 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 514 | 5,632,000 | class Union:
def __init__(self, n):
self.ancestors = [i for i in range(n+1)]
self.size = [0]*(n+1)
def get_root(self, node):
if self.ancestors[node] == node:
return node
self.ancestors[node] = self.get_root(self.ancestors[node])
return self.ancestors[node]
def merge(self, a, b):
a, b = self.get_root(a), self.get_root(b)
self.ancestors[a] = b
def combination(number):
return (number * (number - 1)) >> 1
n, m, k = map(int, input().split())
biggest, others, res = 0, n, -m
homes = list(map(int, input().split()))
union = Union(n)
for _ in range(m):
a, b = map(int, input().split())
union.merge(a, b)
for i in range(1, n+1):
union.size[union.get_root(i)] += 1
for home in homes:
size = union.size[union.get_root(home)]
biggest = max(biggest, size)
res += combination(size)
others -= size
res -= combination(biggest)
res += combination(biggest + others)
print(res) | Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Input Specification:
The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable.
Output Specification:
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
Demo Input:
['4 1 2\n1 3\n1 2\n', '3 3 1\n2\n1 2\n1 3\n2 3\n']
Demo Output:
['2\n', '0\n']
Note:
For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | ```python
class Union:
def __init__(self, n):
self.ancestors = [i for i in range(n+1)]
self.size = [0]*(n+1)
def get_root(self, node):
if self.ancestors[node] == node:
return node
self.ancestors[node] = self.get_root(self.ancestors[node])
return self.ancestors[node]
def merge(self, a, b):
a, b = self.get_root(a), self.get_root(b)
self.ancestors[a] = b
def combination(number):
return (number * (number - 1)) >> 1
n, m, k = map(int, input().split())
biggest, others, res = 0, n, -m
homes = list(map(int, input().split()))
union = Union(n)
for _ in range(m):
a, b = map(int, input().split())
union.merge(a, b)
for i in range(1, n+1):
union.size[union.get_root(i)] += 1
for home in homes:
size = union.size[union.get_root(home)]
biggest = max(biggest, size)
res += combination(size)
others -= size
res -= combination(biggest)
res += combination(biggest + others)
print(res)
``` | 3 |
|
906 | C | Party | PROGRAMMING | 2,400 | [
"bitmasks",
"brute force",
"dp",
"graphs"
] | null | null | Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests *A*, who pairwise introduces all of his friends to each other. After this action any two friends of *A* become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=22; ) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next *m* lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*; *u*<=≠<=*v*), which means that people with numbers *u* and *v* are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected. | In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them. | [
"5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n",
"4 4\n1 2\n1 3\n1 4\n3 4\n"
] | [
"2\n2 3 ",
"1\n1 "
] | In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step. | 1,250 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5",
"output": "2\n2 3 "
},
{
"input": "4 4\n1 2\n1 3\n1 4\n3 4",
"output": "1\n1 "
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "0"
},
{
"input": "3 2\n1 3\n2 3",
"output": "1\n3 "
},
{
"input": "22 31\n5 11\n6 3\n10 1\n18 20\n3 21\n12 10\n15 19\n1 17\n17 18\n2 21\n21 7\n2 15\n3 2\n19 6\n2 19\n13 16\n21 19\n13 5\n19 3\n12 22\n9 20\n14 11\n15 21\n7 8\n2 6\n15 6\n6 21\n15 3\n4 22\n14 8\n16 9",
"output": "16\n1 5 7 8 9 10 11 12 13 14 16 17 18 20 21 22 "
},
{
"input": "22 36\n6 15\n6 9\n14 18\n8 6\n5 18\n3 12\n16 22\n11 2\n7 1\n17 3\n10 20\n8 11\n5 21\n4 11\n9 11\n20 1\n12 4\n8 19\n8 9\n15 2\n6 19\n13 17\n8 2\n11 15\n9 15\n15 19\n16 13\n15 8\n19 11\n6 2\n9 19\n6 11\n9 2\n19 2\n10 14\n22 21",
"output": "15\n1 3 4 5 10 11 12 13 14 16 17 18 20 21 22 "
},
{
"input": "22 22\n19 20\n11 21\n7 4\n14 3\n22 8\n13 6\n8 6\n16 13\n18 14\n17 9\n19 4\n21 1\n16 3\n12 20\n11 18\n5 15\n10 15\n1 10\n5 17\n22 2\n7 2\n9 12",
"output": "20\n1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "22 21\n10 15\n22 8\n21 1\n16 13\n16 3\n7 2\n5 15\n1 10\n17 9\n11 18\n7 4\n18 14\n5 17\n14 3\n19 20\n8 6\n12 20\n11 21\n19 4\n13 6\n22 2",
"output": "20\n1 2 3 4 5 6 7 8 10 11 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "22 21\n14 2\n7 8\n17 6\n11 20\n5 16\n1 2\n22 8\n4 3\n13 18\n3 2\n6 1\n21 3\n11 4\n6 9\n3 12\n4 5\n15 2\n14 19\n11 13\n5 7\n1 10",
"output": "11\n1 2 3 4 5 6 7 8 11 13 14 "
},
{
"input": "22 21\n7 8\n10 14\n21 2\n5 18\n22 8\n2 4\n2 3\n3 13\n11 10\n19 2\n17 20\n10 5\n15 11\n7 4\n17 13\n5 1\n6 4\n16 14\n9 2\n2 1\n10 12",
"output": "12\n1 2 3 4 5 7 8 10 11 13 14 17 "
},
{
"input": "22 66\n15 20\n15 4\n2 22\n8 22\n2 4\n8 2\n5 7\n18 8\n10 21\n22 20\n18 7\n2 20\n5 1\n20 19\n21 4\n8 4\n20 5\n7 8\n7 4\n21 15\n21 22\n7 20\n5 22\n21 7\n5 18\n18 21\n19 7\n15 7\n21 8\n18 15\n18 16\n21 19\n19 5\n21 2\n5 15\n8 3\n7 22\n2 15\n9 2\n20 4\n15 22\n19 18\n19 15\n15 13\n7 2\n15 8\n21 5\n18 2\n5 8\n19 2\n5 4\n19 8\n12 7\n8 20\n4 11\n20 18\n5 2\n21 20\n19 17\n4 18\n22 19\n22 14\n4 22\n20 6\n18 22\n19 4",
"output": "11\n2 4 5 7 8 15 18 19 20 21 22 "
},
{
"input": "22 66\n12 18\n4 12\n15 21\n12 1\n1 18\n2 5\n9 10\n20 15\n18 10\n2 1\n1 14\n20 5\n12 9\n5 12\n14 9\n1 5\n2 20\n15 2\n5 14\n15 1\n17 2\n17 9\n20 18\n3 9\n2 9\n15 5\n14 17\n14 16\n12 14\n2 14\n12 10\n7 2\n20 22\n5 10\n17 19\n14 15\n15 9\n20 1\n15 17\n20 10\n20 9\n2 10\n11 10\n17 10\n12 20\n5 13\n17 1\n15 10\n1 8\n18 15\n5 17\n12 15\n14 20\n12 2\n17 12\n17 20\n14 10\n18 2\n9 18\n18 14\n18 6\n18 17\n9 5\n18 5\n1 9\n10 1",
"output": "11\n1 2 5 9 10 12 14 15 17 18 20 "
},
{
"input": "22 66\n20 9\n3 10\n2 14\n19 14\n16 20\n14 18\n15 10\n21 2\n7 14\n10 2\n14 11\n3 2\n15 20\n20 18\n3 14\n9 7\n18 2\n3 9\n14 10\n7 11\n20 14\n14 15\n2 7\n14 9\n21 1\n18 12\n21 15\n10 18\n18 11\n21 7\n3 21\n18 15\n10 20\n2 8\n15 7\n9 10\n4 11\n3 7\n10 17\n9 18\n20 3\n18 21\n10 7\n9 11\n10 11\n3 15\n10 21\n6 3\n20 2\n3 11\n7 18\n21 14\n21 9\n11 20\n15 13\n21 20\n2 15\n11 15\n7 5\n9 22\n9 15\n3 18\n9 2\n21 11\n20 7\n11 2",
"output": "11\n2 3 7 9 10 11 14 15 18 20 21 "
},
{
"input": "22 66\n17 7\n2 11\n19 17\n14 17\n7 14\n9 1\n12 19\n7 9\n14 18\n15 20\n7 12\n14 21\n6 15\n4 2\n6 22\n7 19\n12 9\n14 19\n10 18\n9 2\n14 12\n18 2\n15 14\n7 2\n17 13\n6 18\n14 2\n4 7\n9 19\n3 12\n17 12\n2 12\n18 7\n17 15\n4 6\n17 4\n4 8\n4 19\n7 5\n15 9\n7 15\n18 4\n14 4\n4 12\n4 9\n2 19\n14 6\n16 19\n9 14\n18 9\n19 15\n15 12\n4 15\n2 15\n7 6\n9 6\n15 18\n19 6\n17 6\n17 18\n6 12\n18 19\n17 9\n12 18\n6 2\n2 17",
"output": "11\n2 4 6 7 9 12 14 15 17 18 19 "
},
{
"input": "22 66\n10 19\n15 6\n2 10\n9 19\n6 5\n14 10\n15 19\n3 14\n10 9\n11 2\n6 8\n18 8\n18 7\n19 14\n18 5\n1 15\n18 2\n21 8\n10 18\n9 18\n19 5\n19 18\n9 15\n6 16\n5 12\n21 5\n21 2\n6 19\n14 6\n10 13\n14 9\n2 14\n6 9\n10 15\n8 5\n9 2\n18 21\n15 2\n21 10\n8 2\n9 8\n6 21\n6 10\n5 2\n8 19\n18 15\n5 9\n14 21\n14 18\n19 21\n8 14\n15 21\n14 15\n8 10\n6 2\n14 5\n5 15\n20 8\n10 5\n15 8\n19 2\n22 21\n4 9\n9 21\n19 17\n18 6",
"output": "11\n2 5 6 8 9 10 14 15 18 19 21 "
},
{
"input": "22 66\n9 22\n9 7\n18 3\n4 1\n4 8\n22 7\n4 7\n16 8\n22 12\n17 3\n20 17\n9 1\n16 20\n4 3\n12 7\n22 16\n16 17\n3 7\n22 13\n1 8\n8 22\n9 16\n9 4\n8 17\n8 20\n7 17\n8 15\n20 7\n16 3\n8 7\n9 17\n7 16\n8 12\n16 4\n2 4\n16 1\n3 22\n1 12\n20 4\n22 1\n20 9\n17 12\n12 9\n14 20\n20 1\n4 22\n12 20\n11 17\n5 9\n20 22\n12 19\n10 1\n17 22\n20 3\n7 6\n12 3\n21 16\n8 9\n17 1\n17 4\n7 1\n3 1\n16 12\n9 3\n3 8\n12 4",
"output": "11\n1 3 4 7 8 9 12 16 17 20 22 "
},
{
"input": "22 66\n16 14\n10 22\n13 15\n3 18\n18 15\n21 13\n7 2\n21 22\n4 14\n15 4\n16 3\n3 10\n4 20\n4 16\n19 14\n18 14\n10 14\n16 7\n21 15\n13 3\n10 15\n22 7\n3 15\n18 11\n13 10\n22 4\n13 12\n1 10\n3 17\n4 21\n13 22\n4 13\n22 14\n18 21\n13 16\n3 22\n22 18\n13 18\n7 10\n14 3\n10 21\n22 9\n21 16\n21 7\n3 4\n22 16\n16 10\n18 10\n6 21\n8 16\n22 15\n21 14\n7 13\n7 3\n18 7\n4 10\n7 4\n14 7\n4 18\n16 15\n14 15\n18 16\n15 5\n13 14\n21 3\n15 7",
"output": "11\n3 4 7 10 13 14 15 16 18 21 22 "
},
{
"input": "22 66\n9 20\n16 1\n1 12\n20 17\n14 17\n1 3\n13 20\n1 17\n17 8\n3 12\n15 20\n6 1\n13 9\n20 3\n9 21\n3 11\n15 19\n22 13\n13 12\n21 10\n17 21\n8 13\n3 9\n16 12\n5 20\n20 21\n16 21\n15 1\n15 3\n1 21\n8 2\n16 20\n20 8\n12 9\n21 15\n7 9\n8 15\n8 1\n12 21\n17 16\n15 9\n17 9\n3 17\n1 9\n13 3\n15 13\n15 17\n3 8\n21 13\n8 9\n15 12\n21 3\n16 18\n16 13\n1 20\n12 20\n16 8\n8 21\n17 13\n4 12\n8 12\n15 16\n12 17\n13 1\n9 16\n3 16",
"output": "11\n1 3 8 9 12 13 15 16 17 20 21 "
},
{
"input": "22 66\n9 13\n7 8\n7 22\n1 12\n10 13\n18 9\n14 13\n18 17\n12 18\n19 7\n1 10\n17 16\n15 9\n7 10\n19 17\n8 9\n17 14\n6 14\n19 10\n9 7\n18 19\n10 17\n17 7\n14 9\n1 19\n10 9\n9 17\n10 12\n13 21\n8 18\n10 14\n13 19\n4 8\n8 12\n19 3\n14 8\n12 13\n19 8\n18 13\n7 18\n7 1\n12 7\n12 19\n18 20\n11 1\n13 8\n13 17\n1 8\n17 12\n19 14\n13 7\n5 12\n1 17\n12 14\n14 18\n8 17\n8 10\n18 1\n9 19\n14 1\n13 1\n1 9\n7 14\n9 12\n18 10\n10 2",
"output": "11\n1 7 8 9 10 12 13 14 17 18 19 "
},
{
"input": "22 66\n11 19\n11 22\n2 22\n6 21\n6 1\n22 5\n13 2\n13 19\n13 22\n6 10\n1 21\n19 17\n6 17\n16 21\n22 19\n19 16\n17 13\n21 19\n16 11\n15 16\n1 11\n21 10\n12 11\n22 6\n1 22\n13 11\n10 16\n11 10\n19 1\n10 19\n10 2\n6 16\n13 21\n17 11\n7 1\n21 2\n22 16\n21 8\n17 10\n21 11\n1 2\n10 1\n10 22\n19 20\n17 18\n1 17\n13 10\n16 13\n2 11\n22 17\n1 16\n2 14\n10 9\n16 2\n21 17\n4 6\n19 6\n22 21\n17 2\n13 6\n6 11\n6 2\n13 1\n3 13\n17 16\n2 19",
"output": "11\n1 2 6 10 11 13 16 17 19 21 22 "
},
{
"input": "22 66\n22 7\n22 3\n16 6\n16 1\n8 17\n15 18\n13 18\n8 1\n12 15\n12 5\n16 7\n8 6\n22 12\n5 17\n10 7\n15 6\n6 18\n17 19\n18 16\n16 5\n22 17\n15 17\n22 16\n6 7\n1 11\n16 12\n8 12\n7 12\n17 6\n17 1\n6 5\n7 17\n1 5\n15 5\n17 18\n15 7\n15 22\n12 4\n16 15\n6 21\n7 18\n8 15\n12 1\n15 1\n16 8\n1 6\n7 5\n1 18\n8 18\n15 2\n7 8\n22 5\n22 18\n1 7\n16 20\n18 5\n5 8\n14 8\n17 12\n18 12\n9 5\n1 22\n6 22\n6 12\n16 17\n22 8",
"output": "11\n1 5 6 7 8 12 15 16 17 18 22 "
},
{
"input": "22 66\n1 13\n12 21\n15 21\n5 15\n16 12\n8 13\n3 20\n13 9\n15 2\n2 5\n3 17\n1 2\n11 20\n11 2\n3 12\n15 12\n2 3\n20 13\n18 21\n20 2\n15 3\n3 21\n20 22\n9 20\n20 12\n12 5\n9 11\n21 2\n20 5\n15 9\n13 11\n20 21\n12 11\n13 15\n15 20\n5 19\n13 5\n11 7\n3 11\n21 11\n12 13\n10 9\n21 13\n1 15\n13 3\n1 3\n12 1\n5 1\n1 20\n21 9\n21 1\n12 9\n21 5\n11 15\n3 5\n2 9\n3 9\n5 11\n11 1\n14 15\n2 4\n5 9\n6 1\n2 12\n9 1\n2 13",
"output": "11\n1 2 3 5 9 11 12 13 15 20 21 "
},
{
"input": "22 66\n15 9\n22 8\n12 22\n12 15\n14 11\n11 17\n5 15\n14 10\n12 17\n14 18\n18 12\n14 22\n19 8\n12 11\n12 21\n22 13\n15 11\n6 17\n18 15\n22 19\n8 4\n2 13\n19 12\n19 14\n18 17\n22 1\n11 19\n15 22\n19 17\n5 12\n11 5\n8 18\n15 19\n8 15\n13 18\n14 13\n5 14\n5 17\n13 17\n13 19\n17 15\n18 22\n13 15\n11 13\n12 13\n8 5\n19 18\n8 12\n11 18\n18 5\n14 17\n5 19\n14 12\n13 8\n17 22\n11 22\n8 14\n16 5\n3 19\n15 14\n17 8\n18 20\n5 13\n11 8\n11 7\n22 5",
"output": "11\n5 8 11 12 13 14 15 17 18 19 22 "
},
{
"input": "22 38\n19 21\n19 6\n1 7\n8 17\n5 1\n14 13\n15 4\n20 3\n19 8\n22 6\n11 16\n9 15\n22 20\n21 15\n12 13\n18 7\n19 5\n1 22\n3 8\n19 1\n22 13\n19 17\n4 2\n5 3\n21 7\n12 10\n7 15\n20 21\n18 17\n10 5\n8 9\n13 20\n18 9\n18 22\n15 1\n5 15\n2 8\n11 21",
"output": "9\n2 5 7 8 11 13 19 20 21 "
},
{
"input": "22 45\n4 1\n8 6\n12 13\n15 22\n20 8\n16 4\n3 20\n13 9\n6 5\n18 20\n16 22\n14 3\n1 14\n7 17\n7 3\n17 6\n11 19\n19 22\n5 11\n13 11\n17 11\n8 15\n10 17\n6 2\n2 22\n18 13\n18 9\n16 11\n10 7\n2 18\n22 4\n1 16\n9 3\n9 8\n9 11\n3 15\n14 4\n13 16\n7 15\n6 3\n4 20\n2 19\n10 1\n16 9\n21 14",
"output": "7\n1 2 3 6 9 13 14 "
},
{
"input": "22 60\n14 6\n16 12\n6 21\n11 16\n2 17\n4 8\n18 11\n3 5\n13 3\n18 9\n8 19\n3 16\n19 13\n22 13\n10 15\n3 1\n15 4\n5 18\n8 17\n2 20\n15 19\n15 12\n14 2\n7 18\n5 19\n10 5\n22 8\n9 8\n14 7\n1 4\n12 6\n9 14\n4 11\n11 2\n16 1\n5 12\n13 4\n22 9\n22 15\n22 10\n11 19\n10 2\n11 5\n2 9\n5 4\n9 3\n21 22\n10 19\n16 8\n13 17\n8 7\n18 20\n10 12\n12 3\n4 10\n14 13\n3 6\n12 2\n1 8\n15 5",
"output": "5\n2 3 8 9 22 "
},
{
"input": "22 80\n8 22\n5 18\n17 18\n10 22\n9 15\n12 10\n4 21\n2 12\n21 16\n21 7\n13 6\n5 21\n20 1\n11 4\n19 16\n18 16\n17 5\n22 20\n18 4\n6 14\n3 4\n16 11\n1 12\n16 20\n19 4\n17 8\n1 9\n12 3\n8 6\n8 9\n7 1\n7 2\n14 8\n4 12\n20 21\n21 13\n11 7\n15 19\n12 20\n17 13\n13 22\n15 4\n19 12\n18 11\n20 8\n12 6\n20 14\n7 4\n22 11\n11 2\n9 7\n22 1\n10 9\n10 4\n12 7\n17 7\n11 1\n8 16\n20 19\n20 6\n11 10\n4 22\n7 8\n4 9\n17 19\n5 11\n13 10\n6 2\n13 9\n6 19\n19 9\n7 22\n15 7\n15 22\n2 4\n3 16\n13 18\n10 2\n7 16\n2 3",
"output": "4\n2 6 7 11 "
},
{
"input": "22 44\n3 22\n1 9\n14 21\n10 17\n3 19\n12 20\n14 17\n6 4\n16 1\n8 22\n2 5\n15 2\n10 14\n7 14\n12 4\n21 16\n1 6\n18 8\n22 19\n22 7\n15 5\n16 9\n21 1\n13 2\n13 15\n8 3\n20 15\n19 10\n19 7\n9 12\n11 8\n6 12\n7 10\n5 11\n4 13\n18 11\n17 16\n11 3\n20 13\n5 18\n9 6\n17 21\n2 18\n4 20",
"output": "10\n1 2 4 6 8 10 13 16 17 18 "
},
{
"input": "22 66\n5 7\n18 15\n21 10\n12 8\n21 22\n17 2\n13 18\n11 6\n7 1\n5 1\n15 6\n13 17\n6 21\n5 4\n19 4\n14 11\n15 11\n4 13\n2 11\n2 6\n10 22\n17 18\n7 4\n19 5\n22 12\n1 13\n11 21\n10 9\n17 14\n3 7\n18 2\n4 17\n20 19\n16 21\n9 20\n3 19\n2 15\n8 19\n21 12\n16 22\n3 5\n10 12\n22 20\n1 18\n16 10\n4 1\n9 3\n8 5\n12 20\n22 9\n6 16\n18 14\n8 3\n15 16\n11 16\n12 9\n7 13\n6 10\n14 15\n9 8\n19 7\n1 17\n13 14\n14 2\n20 3\n20 8",
"output": "6\n2 3 6 7 9 10 "
},
{
"input": "22 40\n2 3\n11 13\n7 10\n6 8\n2 4\n14 16\n7 9\n13 16\n10 11\n1 4\n19 21\n18 19\n6 7\n5 8\n14 15\n9 11\n11 14\n8 9\n3 5\n3 6\n18 20\n10 12\n9 12\n17 20\n17 19\n1 3\n16 18\n4 6\n4 5\n12 14\n19 22\n13 15\n5 7\n20 22\n15 18\n12 13\n8 10\n15 17\n16 17\n20 21",
"output": "9\n3 5 7 9 11 13 15 17 19 "
},
{
"input": "22 57\n5 7\n11 15\n18 19\n9 12\n18 20\n10 15\n9 11\n15 16\n6 8\n5 9\n14 17\n9 10\n16 20\n5 8\n4 9\n12 15\n14 16\n7 11\n13 17\n13 18\n19 22\n10 13\n6 7\n4 7\n16 21\n8 10\n15 18\n21 22\n10 14\n3 6\n11 14\n7 12\n1 6\n17 19\n12 13\n3 4\n13 16\n2 5\n18 21\n17 21\n3 5\n20 22\n1 5\n8 12\n17 20\n7 10\n1 4\n2 6\n8 11\n12 14\n16 19\n11 13\n2 4\n14 18\n15 17\n4 8\n6 9",
"output": "6\n4 7 10 13 16 19 "
},
{
"input": "22 72\n2 5\n6 9\n9 14\n16 19\n14 19\n15 20\n12 15\n10 16\n8 10\n4 7\n10 13\n15 18\n3 5\n2 7\n16 18\n1 6\n6 11\n11 14\n15 19\n19 22\n5 9\n7 12\n13 19\n2 6\n11 16\n11 13\n6 10\n11 15\n12 16\n9 16\n5 10\n1 8\n12 13\n8 12\n3 7\n16 20\n4 6\n3 6\n7 10\n20 22\n18 22\n5 12\n17 22\n14 18\n4 8\n14 17\n9 15\n3 8\n5 11\n7 9\n10 14\n4 5\n1 5\n18 21\n8 9\n8 11\n19 21\n9 13\n2 8\n10 15\n1 7\n14 20\n12 14\n13 18\n20 21\n15 17\n16 17\n6 12\n13 20\n7 11\n17 21\n13 17",
"output": "4\n5 9 13 17 "
}
] | 1,539,272,369 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | def minindex(arr):
r = 0
min = float('inf')
i = 0
for e in arr:
if(min > e):
min = e
r = i
i += 1
return r
def maxindex(arr):
r = 0
max = float('-inf')
i = 0
for e in arr:
if(max < e):
max = e
r = i
i += 1
return r
def lenh(arr,i):
if len(addedarr) and (i not in addedarr):
return float('-inf')
r = 0
for e in arr:
r += (e not in addedarr)
return r
n,m = (int(e) for e in input().split(' '))
arr = [[] for i in range(n)]
for i in range(m):
ind1,ind2 = (int(e)-1 for e in input().split(' '))
arr[ind1].append(ind2)
arr[ind2].append(ind1)
res = []
addedarr = set()
while len(addedarr)<n:
i = maxindex(lenh(e,i) for i,e in enumerate(arr))
res.append(i)
addedarr |= set(arr[i])
addedarr.add(i)
print(len(res))
for e in res:
print(e+1,end=' ')
"""
5 6
1 2
1 3
2 3
2 5
3 4
4 5
2
2 3
"""
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests *A*, who pairwise introduces all of his friends to each other. After this action any two friends of *A* become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=22; ) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next *m* lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*; *u*<=≠<=*v*), which means that people with numbers *u* and *v* are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
Output Specification:
In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them.
Demo Input:
['5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n', '4 4\n1 2\n1 3\n1 4\n3 4\n']
Demo Output:
['2\n2 3 ', '1\n1 ']
Note:
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step. | ```python
def minindex(arr):
r = 0
min = float('inf')
i = 0
for e in arr:
if(min > e):
min = e
r = i
i += 1
return r
def maxindex(arr):
r = 0
max = float('-inf')
i = 0
for e in arr:
if(max < e):
max = e
r = i
i += 1
return r
def lenh(arr,i):
if len(addedarr) and (i not in addedarr):
return float('-inf')
r = 0
for e in arr:
r += (e not in addedarr)
return r
n,m = (int(e) for e in input().split(' '))
arr = [[] for i in range(n)]
for i in range(m):
ind1,ind2 = (int(e)-1 for e in input().split(' '))
arr[ind1].append(ind2)
arr[ind2].append(ind1)
res = []
addedarr = set()
while len(addedarr)<n:
i = maxindex(lenh(e,i) for i,e in enumerate(arr))
res.append(i)
addedarr |= set(arr[i])
addedarr.add(i)
print(len(res))
for e in res:
print(e+1,end=' ')
"""
5 6
1 2
1 3
2 3
2 5
3 4
4 5
2
2 3
"""
``` | 0 |
|
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. | The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"output": "100000000"
},
{
"input": "900000000",
"output": "100000000"
},
{
"input": "999999999",
"output": "1"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "9999999",
"output": "1"
},
{
"input": "100000001",
"output": "99999999"
},
{
"input": "3660",
"output": "340"
},
{
"input": "21",
"output": "9"
},
{
"input": "900000001",
"output": "99999999"
},
{
"input": "62911",
"output": "7089"
},
{
"input": "11",
"output": "9"
},
{
"input": "940302010",
"output": "59697990"
},
{
"input": "91",
"output": "9"
},
{
"input": "101",
"output": "99"
},
{
"input": "1090",
"output": "910"
},
{
"input": "987654321",
"output": "12345679"
},
{
"input": "703450474",
"output": "96549526"
},
{
"input": "1091",
"output": "909"
},
{
"input": "89",
"output": "1"
},
{
"input": "109",
"output": "91"
},
{
"input": "190",
"output": "10"
},
{
"input": "19",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "482",
"output": "18"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "6",
"output": "1"
},
{
"input": "7",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "11",
"output": "9"
},
{
"input": "12",
"output": "8"
},
{
"input": "13",
"output": "7"
},
{
"input": "14",
"output": "6"
},
{
"input": "15",
"output": "5"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "3"
},
{
"input": "18",
"output": "2"
},
{
"input": "19",
"output": "1"
},
{
"input": "20",
"output": "10"
},
{
"input": "21",
"output": "9"
},
{
"input": "22",
"output": "8"
},
{
"input": "23",
"output": "7"
},
{
"input": "24",
"output": "6"
},
{
"input": "25",
"output": "5"
},
{
"input": "26",
"output": "4"
},
{
"input": "27",
"output": "3"
},
{
"input": "28",
"output": "2"
},
{
"input": "29",
"output": "1"
},
{
"input": "30",
"output": "10"
},
{
"input": "31",
"output": "9"
},
{
"input": "32",
"output": "8"
},
{
"input": "33",
"output": "7"
},
{
"input": "34",
"output": "6"
},
{
"input": "35",
"output": "5"
},
{
"input": "36",
"output": "4"
},
{
"input": "37",
"output": "3"
},
{
"input": "38",
"output": "2"
},
{
"input": "39",
"output": "1"
},
{
"input": "40",
"output": "10"
},
{
"input": "41",
"output": "9"
},
{
"input": "42",
"output": "8"
},
{
"input": "43",
"output": "7"
},
{
"input": "44",
"output": "6"
},
{
"input": "45",
"output": "5"
},
{
"input": "46",
"output": "4"
},
{
"input": "47",
"output": "3"
},
{
"input": "48",
"output": "2"
},
{
"input": "49",
"output": "1"
},
{
"input": "50",
"output": "10"
},
{
"input": "51",
"output": "9"
},
{
"input": "52",
"output": "8"
},
{
"input": "53",
"output": "7"
},
{
"input": "54",
"output": "6"
},
{
"input": "55",
"output": "5"
},
{
"input": "56",
"output": "4"
},
{
"input": "57",
"output": "3"
},
{
"input": "58",
"output": "2"
},
{
"input": "59",
"output": "1"
},
{
"input": "60",
"output": "10"
},
{
"input": "61",
"output": "9"
},
{
"input": "62",
"output": "8"
},
{
"input": "63",
"output": "7"
},
{
"input": "64",
"output": "6"
},
{
"input": "65",
"output": "5"
},
{
"input": "66",
"output": "4"
},
{
"input": "67",
"output": "3"
},
{
"input": "68",
"output": "2"
},
{
"input": "69",
"output": "1"
},
{
"input": "70",
"output": "10"
},
{
"input": "71",
"output": "9"
},
{
"input": "72",
"output": "8"
},
{
"input": "73",
"output": "7"
},
{
"input": "74",
"output": "6"
},
{
"input": "75",
"output": "5"
},
{
"input": "76",
"output": "4"
},
{
"input": "77",
"output": "3"
},
{
"input": "78",
"output": "2"
},
{
"input": "79",
"output": "1"
},
{
"input": "80",
"output": "10"
},
{
"input": "81",
"output": "9"
},
{
"input": "82",
"output": "8"
},
{
"input": "83",
"output": "7"
},
{
"input": "84",
"output": "6"
},
{
"input": "85",
"output": "5"
},
{
"input": "86",
"output": "4"
},
{
"input": "87",
"output": "3"
},
{
"input": "88",
"output": "2"
},
{
"input": "89",
"output": "1"
},
{
"input": "90",
"output": "10"
},
{
"input": "91",
"output": "9"
},
{
"input": "92",
"output": "8"
},
{
"input": "93",
"output": "7"
},
{
"input": "94",
"output": "6"
},
{
"input": "95",
"output": "5"
},
{
"input": "96",
"output": "4"
},
{
"input": "97",
"output": "3"
},
{
"input": "98",
"output": "2"
},
{
"input": "99",
"output": "1"
},
{
"input": "100",
"output": "100"
},
{
"input": "100",
"output": "100"
},
{
"input": "100",
"output": "100"
},
{
"input": "1000",
"output": "1000"
},
{
"input": "1000",
"output": "1000"
},
{
"input": "1000",
"output": "1000"
},
{
"input": "10000",
"output": "10000"
},
{
"input": "10000",
"output": "10000"
},
{
"input": "101",
"output": "99"
},
{
"input": "110",
"output": "90"
},
{
"input": "1001",
"output": "999"
},
{
"input": "1100",
"output": "900"
},
{
"input": "1010",
"output": "990"
},
{
"input": "10010",
"output": "9990"
},
{
"input": "10100",
"output": "9900"
},
{
"input": "102",
"output": "98"
},
{
"input": "120",
"output": "80"
},
{
"input": "1002",
"output": "998"
},
{
"input": "1200",
"output": "800"
},
{
"input": "1020",
"output": "980"
},
{
"input": "10020",
"output": "9980"
},
{
"input": "10200",
"output": "9800"
},
{
"input": "108",
"output": "92"
},
{
"input": "180",
"output": "20"
},
{
"input": "1008",
"output": "992"
},
{
"input": "1800",
"output": "200"
},
{
"input": "1080",
"output": "920"
},
{
"input": "10080",
"output": "9920"
},
{
"input": "10800",
"output": "9200"
},
{
"input": "109",
"output": "91"
},
{
"input": "190",
"output": "10"
},
{
"input": "1009",
"output": "991"
},
{
"input": "1900",
"output": "100"
},
{
"input": "1090",
"output": "910"
},
{
"input": "10090",
"output": "9910"
},
{
"input": "10900",
"output": "9100"
},
{
"input": "200",
"output": "100"
},
{
"input": "200",
"output": "100"
},
{
"input": "2000",
"output": "1000"
},
{
"input": "2000",
"output": "1000"
},
{
"input": "2000",
"output": "1000"
},
{
"input": "20000",
"output": "10000"
},
{
"input": "20000",
"output": "10000"
},
{
"input": "201",
"output": "99"
},
{
"input": "210",
"output": "90"
},
{
"input": "2001",
"output": "999"
},
{
"input": "2100",
"output": "900"
},
{
"input": "2010",
"output": "990"
},
{
"input": "20010",
"output": "9990"
},
{
"input": "20100",
"output": "9900"
},
{
"input": "202",
"output": "98"
},
{
"input": "220",
"output": "80"
},
{
"input": "2002",
"output": "998"
},
{
"input": "2200",
"output": "800"
},
{
"input": "2020",
"output": "980"
},
{
"input": "20020",
"output": "9980"
},
{
"input": "20200",
"output": "9800"
},
{
"input": "208",
"output": "92"
},
{
"input": "280",
"output": "20"
},
{
"input": "2008",
"output": "992"
},
{
"input": "2800",
"output": "200"
},
{
"input": "2080",
"output": "920"
},
{
"input": "20080",
"output": "9920"
},
{
"input": "20800",
"output": "9200"
},
{
"input": "209",
"output": "91"
},
{
"input": "290",
"output": "10"
},
{
"input": "2009",
"output": "991"
},
{
"input": "2900",
"output": "100"
},
{
"input": "2090",
"output": "910"
},
{
"input": "20090",
"output": "9910"
},
{
"input": "20900",
"output": "9100"
},
{
"input": "800",
"output": "100"
},
{
"input": "800",
"output": "100"
},
{
"input": "8000",
"output": "1000"
},
{
"input": "8000",
"output": "1000"
},
{
"input": "8000",
"output": "1000"
},
{
"input": "80000",
"output": "10000"
},
{
"input": "80000",
"output": "10000"
},
{
"input": "801",
"output": "99"
},
{
"input": "810",
"output": "90"
},
{
"input": "8001",
"output": "999"
},
{
"input": "8100",
"output": "900"
},
{
"input": "8010",
"output": "990"
},
{
"input": "80010",
"output": "9990"
},
{
"input": "80100",
"output": "9900"
},
{
"input": "802",
"output": "98"
},
{
"input": "820",
"output": "80"
},
{
"input": "8002",
"output": "998"
},
{
"input": "8200",
"output": "800"
},
{
"input": "8020",
"output": "980"
},
{
"input": "80020",
"output": "9980"
},
{
"input": "80200",
"output": "9800"
},
{
"input": "808",
"output": "92"
},
{
"input": "880",
"output": "20"
},
{
"input": "8008",
"output": "992"
},
{
"input": "8800",
"output": "200"
},
{
"input": "8080",
"output": "920"
},
{
"input": "80080",
"output": "9920"
},
{
"input": "80800",
"output": "9200"
},
{
"input": "809",
"output": "91"
},
{
"input": "890",
"output": "10"
},
{
"input": "8009",
"output": "991"
},
{
"input": "8900",
"output": "100"
},
{
"input": "8090",
"output": "910"
},
{
"input": "80090",
"output": "9910"
},
{
"input": "80900",
"output": "9100"
},
{
"input": "900",
"output": "100"
},
{
"input": "900",
"output": "100"
},
{
"input": "9000",
"output": "1000"
},
{
"input": "9000",
"output": "1000"
},
{
"input": "9000",
"output": "1000"
},
{
"input": "90000",
"output": "10000"
},
{
"input": "90000",
"output": "10000"
},
{
"input": "901",
"output": "99"
},
{
"input": "910",
"output": "90"
},
{
"input": "9001",
"output": "999"
},
{
"input": "9100",
"output": "900"
},
{
"input": "9010",
"output": "990"
},
{
"input": "90010",
"output": "9990"
},
{
"input": "90100",
"output": "9900"
},
{
"input": "902",
"output": "98"
},
{
"input": "920",
"output": "80"
},
{
"input": "9002",
"output": "998"
},
{
"input": "9200",
"output": "800"
},
{
"input": "9020",
"output": "980"
},
{
"input": "90020",
"output": "9980"
},
{
"input": "90200",
"output": "9800"
},
{
"input": "908",
"output": "92"
},
{
"input": "980",
"output": "20"
},
{
"input": "9008",
"output": "992"
},
{
"input": "9800",
"output": "200"
},
{
"input": "9080",
"output": "920"
},
{
"input": "90080",
"output": "9920"
},
{
"input": "90800",
"output": "9200"
},
{
"input": "909",
"output": "91"
},
{
"input": "990",
"output": "10"
},
{
"input": "9009",
"output": "991"
},
{
"input": "9900",
"output": "100"
},
{
"input": "9090",
"output": "910"
},
{
"input": "90090",
"output": "9910"
},
{
"input": "90900",
"output": "9100"
},
{
"input": "92651241",
"output": "7348759"
}
] | 1,681,842,590 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 271 | 108 | 0 | def is_ok(n):
return len([i for i in str(n) if i != '0']) == 1
n = int(input())
if is_ok(n + 1):
print(1)
else:
n_ = int(str(int(str(n)[0]) + 1) + '0' * (len(str(n)) - 1))
print(n_ - n)
| Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output Specification:
Output amount of years from the current year to the next lucky one.
Demo Input:
['4\n', '201\n', '4000\n']
Demo Output:
['1\n', '99\n', '1000\n']
Note:
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | ```python
def is_ok(n):
return len([i for i in str(n) if i != '0']) == 1
n = int(input())
if is_ok(n + 1):
print(1)
else:
n_ = int(str(int(str(n)[0]) + 1) + '0' * (len(str(n)) - 1))
print(n_ - n)
``` | 3 |
|
197 | B | Limit | PROGRAMMING | 1,400 | [
"math"
] | null | null | You are given two polynomials:
- *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*.
Calculate limit . | The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=100) — degrees of polynomials *P*(*x*) and *Q*(*x*) correspondingly.
The second line contains *n*<=+<=1 space-separated integers — the factors of polynomial *P*(*x*): *a*0, *a*1, ..., *a**n*<=-<=1, *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100,<=*a*0<=≠<=0).
The third line contains *m*<=+<=1 space-separated integers — the factors of polynomial *Q*(*x*): *b*0, *b*1, ..., *b**m*<=-<=1, *b**m* (<=-<=100<=≤<=*b**i*<=≤<=100,<=*b*0<=≠<=0). | If the limit equals <=+<=∞, print "Infinity" (without quotes). If the limit equals <=-<=∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where *p* is the — numerator, *q* (*q*<=><=0) is the denominator of the fraction. | [
"2 1\n1 1 1\n2 5\n",
"1 0\n-1 3\n2\n",
"0 1\n1\n1 0\n",
"2 2\n2 1 6\n4 5 -7\n",
"1 1\n9 0\n-5 2\n"
] | [
"Infinity\n",
"-Infinity\n",
"0/1\n",
"1/2\n",
"-9/5\n"
] | Let's consider all samples:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c28febca257452afdfcbd6984ba8623911f9bdbc.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e55ecd04e54a45e5e0092ec9a5c1ea03bb29255.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2c95fb684d373fcc1a481cfabeda4d5c2f3673ee.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4dc40cb8b3cd6375c42445366e50369649a2801a.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c6455aba35cfb3c4397505121d1f77afcd17c98e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function | 500 | [
{
"input": "2 1\n1 1 1\n2 5",
"output": "Infinity"
},
{
"input": "1 0\n-1 3\n2",
"output": "-Infinity"
},
{
"input": "0 1\n1\n1 0",
"output": "0/1"
},
{
"input": "2 2\n2 1 6\n4 5 -7",
"output": "1/2"
},
{
"input": "1 1\n9 0\n-5 2",
"output": "-9/5"
},
{
"input": "1 2\n5 3\n-3 2 -1",
"output": "0/1"
},
{
"input": "1 2\n-4 8\n-2 5 -3",
"output": "0/1"
},
{
"input": "3 2\n4 3 1 2\n-5 7 0",
"output": "-Infinity"
},
{
"input": "2 1\n-3 5 1\n-8 0",
"output": "Infinity"
},
{
"input": "1 1\n-5 7\n3 1",
"output": "-5/3"
},
{
"input": "2 2\n-4 2 1\n-5 8 -19",
"output": "4/5"
},
{
"input": "0 100\n1\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 100",
"output": "0/1"
},
{
"input": "100 0\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 100\n1",
"output": "Infinity"
},
{
"input": "0 0\n36\n-54",
"output": "-2/3"
},
{
"input": "0 0\n36\n-8",
"output": "-9/2"
},
{
"input": "0 0\n-6\n-8",
"output": "3/4"
},
{
"input": "0 2\n-3\n1 4 6",
"output": "0/1"
},
{
"input": "0 0\n-21\n13",
"output": "-21/13"
},
{
"input": "0 0\n-34\n21",
"output": "-34/21"
},
{
"input": "0 0\n-55\n34",
"output": "-55/34"
},
{
"input": "33 100\n-15 -90 -84 57 67 60 -40 -82 83 -80 43 -15 -36 -14 -37 -49 42 -79 49 -7 -12 53 -44 -21 87 -91 -73 -27 13 65 5 74 -21 -52\n-67 -17 36 -46 -5 31 -45 -35 -49 13 -7 -82 92 -55 -67 -96 31 -70 76 24 -29 26 96 19 -40 99 -26 74 -17 -56 -72 24 -71 -62 10 -56 -74 75 -48 -98 -67 -26 47 7 63 -38 99 66 -25 -31 -24 -42 -49 -27 -45 -2 -37 -16 5 -21 97 33 85 -33 93 30 84 73 -48 18 -36 71 -38 -41 28 1 -7 -15 60 59 -20 -38 -86 90 2 -12 72 -43 26 76 97 7 -2 -47 -4 100 -40 -48 53 -54 0",
"output": "0/1"
},
{
"input": "39 87\n78 -50 18 -32 -12 -65 83 41 -6 53 -26 64 -19 -53 -61 91 -49 -66 67 69 100 -39 95 99 86 -67 -66 63 48 26 -4 95 -54 -71 26 -74 -93 79 -91 -45\n-18 23 48 59 76 82 95 2 -26 18 -39 -74 44 -92 40 -44 1 -97 -100 -63 -54 -3 -86 85 28 -50 41 -53 -74 -29 -91 87 27 -42 -90 -15 -26 -15 -100 -70 -10 -41 16 85 71 -39 -31 -65 80 98 9 23 -40 14 -88 15 -34 10 -67 -94 -58 -24 75 48 -42 56 -77 -13 -25 -79 -100 -57 89 45 22 85 78 -93 -79 69 63 44 74 94 35 -65 -12 -88",
"output": "0/1"
},
{
"input": "47 56\n31 -99 -97 6 -45 -5 89 35 -77 69 57 91 -32 -66 -36 16 30 61 -36 32 48 67 5 -85 65 -11 -51 -63 -51 -16 39 -26 -60 -28 91 43 -90 32 44 83 70 -53 51 56 68 -81 76 79\n61 -21 -75 -36 -24 -19 80 26 -28 93 27 72 -39 -46 -38 68 -29 -16 -63 84 -13 64 55 63 77 5 68 70 15 99 12 -69 50 -48 -82 -3 52 -54 68 91 -37 -100 -5 74 24 91 -1 74 28 29 -87 -13 -88 82 -13 58 23",
"output": "0/1"
},
{
"input": "9 100\n-34 88 33 -80 87 31 -53 -3 8 -70\n31 -25 46 78 8 82 -92 -36 -30 85 -93 86 -87 75 8 -71 44 -41 -83 19 89 -28 81 42 79 86 41 -23 64 -31 46 24 -79 23 71 63 99 90 -16 -70 -1 88 10 65 3 -99 95 52 -80 53 -24 -43 -30 -7 51 40 -47 44 -10 -18 -61 -67 -84 37 45 93 -5 68 32 3 -61 -100 38 -21 -91 90 83 -45 75 89 17 -44 75 14 -28 1 -84 -100 -36 84 -40 88 -84 -54 2 -32 92 -49 77 85 91",
"output": "0/1"
},
{
"input": "28 87\n-77 49 37 46 -92 65 89 100 53 76 -43 47 -80 -46 -94 -4 20 46 81 -41 86 25 69 60 15 -78 -98 -7 -42\n-85 96 59 -40 90 -72 41 -17 -40 -15 -98 66 47 9 -33 -63 59 -25 -31 25 -94 35 28 -36 -41 -38 -38 -54 -40 90 7 -10 98 -19 54 -10 46 -58 -88 -21 90 82 37 -70 -98 -63 41 75 -50 -59 -69 79 -93 -3 -45 14 76 28 -28 -98 -44 -39 71 44 90 91 0 45 7 65 68 39 -27 58 68 -47 -41 100 14 -95 -80 69 -88 -51 -89 -70 -23 95",
"output": "0/1"
},
{
"input": "100 4\n-5 -93 89 -26 -79 14 -28 13 -45 69 50 -84 21 -68 62 30 -26 99 -12 39 20 -74 -39 -41 -28 -72 -55 28 20 31 -92 -20 76 -65 57 72 -36 4 33 -28 -19 -41 -40 40 84 -36 -83 75 -74 -80 32 -50 -56 72 16 75 57 90 -19 -10 67 -71 69 -48 -48 23 37 -31 -64 -86 20 67 97 14 82 -41 2 87 65 -81 -27 9 -79 -1 -5 84 -8 29 -34 31 82 40 21 -53 -31 -45 17 -33 79 50 -94\n56 -4 -90 36 84",
"output": "-Infinity"
},
{
"input": "77 51\n89 45 -33 -87 33 -61 -79 40 -76 16 -17 31 27 25 99 82 51 -40 85 -66 19 89 -62 24 -61 -53 -77 17 21 83 53 -18 -56 75 9 -78 33 -11 -6 96 -33 -2 -57 97 30 20 -41 42 -13 45 -99 67 37 -20 51 -33 88 -62 2 40 17 36 45 71 4 -44 24 20 -2 29 -12 -84 -7 -84 -38 48 -73 79\n60 -43 60 1 90 -1 19 -18 -21 31 -76 51 79 91 12 39 -33 -14 71 -90 -65 -93 -58 93 49 17 77 19 32 -8 14 58 -9 85 -95 -73 0 85 -91 -99 -30 -43 61 20 -89 93 53 20 -33 -38 79 54",
"output": "Infinity"
},
{
"input": "84 54\n82 -54 28 68 74 -61 54 98 59 67 -65 -1 16 65 -78 -16 61 -79 2 14 44 96 -62 77 51 87 37 66 65 28 88 -99 -21 -83 24 80 39 64 -65 45 86 -53 -49 94 -75 -31 -42 -1 -35 -18 74 30 31 -40 30 -6 47 58 -71 -21 20 13 75 -79 15 -98 -26 76 99 -77 -9 85 48 51 -87 56 -53 37 47 -3 94 64 -7 74 86\n72 51 -74 20 41 -76 98 58 24 -61 -97 -73 62 29 6 42 -92 -6 -65 89 -32 -9 82 -13 -88 -70 -97 25 -48 12 -54 33 -92 -29 48 60 -21 86 -17 -86 45 -34 -3 -9 -62 12 25 -74 -76 -89 48 55 -30 86 51",
"output": "Infinity"
},
{
"input": "73 15\n-70 78 51 -33 -95 46 87 -33 16 62 67 -85 -57 75 -93 -59 98 -45 -90 -88 9 53 35 37 28 3 40 -87 28 5 18 11 9 1 72 69 -65 -62 1 73 -3 3 35 17 -28 -31 -45 60 64 18 60 38 -47 12 2 -90 -4 33 -51 -55 -54 90 38 -65 39 32 -70 0 -5 3 -12 100 78 55\n46 33 41 52 -89 -9 53 -81 34 -45 -11 -41 14 -28 95 -50",
"output": "-Infinity"
},
{
"input": "33 1\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\n-1 72",
"output": "Infinity"
},
{
"input": "58 58\n-25 40 -34 23 -52 94 -30 -99 -71 -90 -44 -71 69 48 -45 -59 0 66 -70 -96 95 91 82 90 -95 87 3 -77 -77 -26 15 87 -82 5 -24 82 -11 99 35 49 22 44 18 -60 -26 79 67 71 -13 29 -23 9 58 -90 88 18 77 5 -7\n-30 -11 -13 -50 61 -78 11 -74 -73 13 -66 -65 -82 38 58 25 -64 -24 78 -87 6 6 -80 -96 47 -25 -54 10 -41 -22 -50 -1 -6 -22 27 54 -32 30 93 88 -70 -100 -69 -47 -20 -92 -24 70 -93 42 78 42 -35 41 31 75 -67 -62 -83",
"output": "5/6"
},
{
"input": "20 20\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62",
"output": "5/51"
},
{
"input": "69 69\n-90 -63 -21 23 23 -14 -82 65 42 -60 -42 -39 67 34 96 93 -42 -24 21 -80 44 -81 45 -74 -19 -88 39 58 90 87 16 48 -19 -2 36 87 4 -66 -82 -49 -32 -43 -65 12 34 -29 -58 46 -67 -20 -30 91 21 65 15 2 3 -92 -67 -68 39 -24 77 76 -17 -34 5 63 88 83\n-55 98 -79 18 -100 -67 -79 -85 -75 -44 -6 -73 -11 -12 -24 -78 47 -51 25 -29 -34 25 27 11 -87 15 -44 41 -44 46 -67 70 -35 41 62 -36 27 -41 -42 -50 96 31 26 -66 9 74 34 31 25 6 -84 41 74 -7 49 5 35 -5 -71 -37 28 58 -8 -40 -19 -83 -34 64 7 15",
"output": "18/11"
},
{
"input": "0 0\n46\n-33",
"output": "-46/33"
},
{
"input": "67 67\n-8 11 55 80 -26 -38 58 73 -48 -10 35 75 16 -84 55 -51 98 58 -28 98 77 81 51 -86 -46 68 -87 -80 -49 81 96 -97 -42 25 6 -8 -55 -25 93 -29 -33 -6 -26 -85 73 97 63 57 51 92 -6 -8 4 86 46 -45 36 -19 -71 1 71 39 97 -44 -34 -1 2 -46\n91 -32 -76 11 -40 91 -8 -100 73 80 47 82 24 0 -71 82 -93 38 -54 1 -55 -53 90 -86 0 10 -35 49 90 56 25 17 46 -43 13 16 -82 -33 64 -83 -56 22 12 -74 4 -68 85 -27 60 -28 -47 73 -93 69 -37 54 -3 90 -56 56 78 61 7 -79 48 -42 -10 -48",
"output": "-8/91"
},
{
"input": "69 69\n-7 38 -3 -22 65 -78 -65 -99 -76 63 0 -4 -78 -51 54 -61 -53 60 80 34 -96 99 -78 -96 21 -10 -86 33 -9 -81 -19 -2 -76 -3 -66 -80 -55 -21 -50 37 -86 -37 47 44 76 -39 54 -25 41 -86 -3 -25 -67 94 18 67 27 -5 -30 -69 2 -76 7 -97 -52 -35 -55 -20 92 2\n90 -94 37 41 -27 -54 96 -15 -60 -29 -75 -93 -57 62 48 -88 -99 -62 4 -9 85 33 65 -95 -30 16 -29 -89 -33 -83 -35 -21 53 -52 80 -40 76 -33 86 47 18 43 -67 -36 -99 -42 1 -94 -78 34 -41 73 96 2 -60 29 68 -96 -21 -61 -98 -67 1 40 85 55 66 -25 -50 -83",
"output": "-7/90"
},
{
"input": "17 17\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39",
"output": "2/1"
},
{
"input": "1 1\n36 -49\n-32 -40",
"output": "-9/8"
},
{
"input": "1 1\n1 1\n1 1",
"output": "1/1"
},
{
"input": "1 1\n-2 1\n4 1",
"output": "-1/2"
},
{
"input": "0 0\n2\n1",
"output": "2/1"
},
{
"input": "0 0\n4\n-3",
"output": "-4/3"
},
{
"input": "0 0\n2\n2",
"output": "1/1"
},
{
"input": "0 0\n17\n-10",
"output": "-17/10"
},
{
"input": "0 0\n-1\n2",
"output": "-1/2"
},
{
"input": "0 0\n1\n1",
"output": "1/1"
},
{
"input": "0 0\n50\n20",
"output": "5/2"
},
{
"input": "0 0\n20\n20",
"output": "1/1"
},
{
"input": "0 0\n4\n-2",
"output": "-2/1"
},
{
"input": "0 0\n4\n-6",
"output": "-2/3"
},
{
"input": "0 0\n1\n-2",
"output": "-1/2"
},
{
"input": "0 0\n4\n2",
"output": "2/1"
},
{
"input": "0 0\n2\n-4",
"output": "-1/2"
},
{
"input": "1 1\n4 1\n2 1",
"output": "2/1"
},
{
"input": "2 2\n-13 1 3\n6 3 2",
"output": "-13/6"
},
{
"input": "99 99\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\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/2"
},
{
"input": "0 0\n5\n5",
"output": "1/1"
},
{
"input": "0 0\n2\n-1",
"output": "-2/1"
}
] | 1,659,365,712 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n, m = input().split()
n = int(n)
m = int(m)
a = input().split()
a = [int(x) for x in a]
b = input().split()
b = [int(x) for x in b]
def hcf(x, y):
x = abs(x)
y = abs(y)
for t in range(min(x,y)):
if x%t == 0 and y%t==0:
hcf = t
return hcf
if n > m:
if a[0]/b[0]>0:
print('Infinity')
else:
print('-Infinity')
elif m > n:
print(0)
else:
k = hcf(a[0], b[0])
if b[0] < 0:
b[0] = abs(b[0])
a[0] = (-1)*a[0]
print (a[0]//k+'/'+b[0]//k) | Title: Limit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two polynomials:
- *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*.
Calculate limit .
Input Specification:
The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=100) — degrees of polynomials *P*(*x*) and *Q*(*x*) correspondingly.
The second line contains *n*<=+<=1 space-separated integers — the factors of polynomial *P*(*x*): *a*0, *a*1, ..., *a**n*<=-<=1, *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100,<=*a*0<=≠<=0).
The third line contains *m*<=+<=1 space-separated integers — the factors of polynomial *Q*(*x*): *b*0, *b*1, ..., *b**m*<=-<=1, *b**m* (<=-<=100<=≤<=*b**i*<=≤<=100,<=*b*0<=≠<=0).
Output Specification:
If the limit equals <=+<=∞, print "Infinity" (without quotes). If the limit equals <=-<=∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where *p* is the — numerator, *q* (*q*<=><=0) is the denominator of the fraction.
Demo Input:
['2 1\n1 1 1\n2 5\n', '1 0\n-1 3\n2\n', '0 1\n1\n1 0\n', '2 2\n2 1 6\n4 5 -7\n', '1 1\n9 0\n-5 2\n']
Demo Output:
['Infinity\n', '-Infinity\n', '0/1\n', '1/2\n', '-9/5\n']
Note:
Let's consider all samples:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c28febca257452afdfcbd6984ba8623911f9bdbc.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e55ecd04e54a45e5e0092ec9a5c1ea03bb29255.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2c95fb684d373fcc1a481cfabeda4d5c2f3673ee.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4dc40cb8b3cd6375c42445366e50369649a2801a.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c6455aba35cfb3c4397505121d1f77afcd17c98e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function | ```python
n, m = input().split()
n = int(n)
m = int(m)
a = input().split()
a = [int(x) for x in a]
b = input().split()
b = [int(x) for x in b]
def hcf(x, y):
x = abs(x)
y = abs(y)
for t in range(min(x,y)):
if x%t == 0 and y%t==0:
hcf = t
return hcf
if n > m:
if a[0]/b[0]>0:
print('Infinity')
else:
print('-Infinity')
elif m > n:
print(0)
else:
k = hcf(a[0], b[0])
if b[0] < 0:
b[0] = abs(b[0])
a[0] = (-1)*a[0]
print (a[0]//k+'/'+b[0]//k)
``` | 0 |
|
869 | C | The Intriguing Obsession | PROGRAMMING | 1,800 | [
"combinatorics",
"dp",
"math"
] | null | null | — This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of *a*, *b* and *c* distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998<=244<=353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other. | The first and only line of input contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=5<=000) — the number of islands in the red, blue and purple clusters, respectively. | Output one line containing an integer — the number of different ways to build bridges, modulo 998<=244<=353. | [
"1 1 1\n",
"1 2 2\n",
"1 3 5\n",
"6 2 9\n"
] | [
"8\n",
"63\n",
"3264\n",
"813023575\n"
] | In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2<sup class="upper-index">3</sup> = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively. | 1,500 | [
{
"input": "1 1 1",
"output": "8"
},
{
"input": "1 2 2",
"output": "63"
},
{
"input": "1 3 5",
"output": "3264"
},
{
"input": "6 2 9",
"output": "813023575"
},
{
"input": "7 3 7",
"output": "807577560"
},
{
"input": "135 14 39",
"output": "414849507"
},
{
"input": "5000 5000 5000",
"output": "986778560"
},
{
"input": "2 1 1",
"output": "18"
},
{
"input": "1 1 3",
"output": "32"
},
{
"input": "1 2 3",
"output": "156"
},
{
"input": "4 1 2",
"output": "315"
},
{
"input": "5 9 4",
"output": "661093467"
},
{
"input": "4 2 5",
"output": "326151"
},
{
"input": "9 4 10",
"output": "391175867"
},
{
"input": "16 8 29",
"output": "349763770"
},
{
"input": "17 46 45",
"output": "518654435"
},
{
"input": "28 47 1",
"output": "517406193"
},
{
"input": "94 87 10",
"output": "846321893"
},
{
"input": "84 29 61",
"output": "391253501"
},
{
"input": "179 856 377",
"output": "518957210"
},
{
"input": "1925 1009 273",
"output": "207866159"
},
{
"input": "1171 2989 2853",
"output": "234725427"
},
{
"input": "3238 2923 4661",
"output": "636587126"
},
{
"input": "1158 506 4676",
"output": "6109065"
},
{
"input": "4539 2805 2702",
"output": "356944655"
},
{
"input": "4756 775 3187",
"output": "56242066"
},
{
"input": "4998 4998 4998",
"output": "259368717"
},
{
"input": "4996 1 5000",
"output": "196902859"
},
{
"input": "2048 4096 1024",
"output": "445542375"
},
{
"input": "5000 1 1",
"output": "50020002"
}
] | 1,686,237,059 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 421 | 36,761,600 | import math
import random
import time
from collections import defaultdict
alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26}
alfabet_2={'1':"a", '2':"b", '3':"c", '4':"d", '5':"e", '6':"f", '7':"g", '8':"h", '9':"i", '10':"j", '11':"k", '12':"l", '13':"m", '14':"n", '15':"o", '16':"p", '17':"q", '18':"r", '19':"s", '20':"t", '21':"u", '22':"v", '23':"w", '24':"x", '25':"y", '26':"z"}
def prime_generator(nr_elemente_prime):
vector_prime=[-1]*nr_elemente_prime
vector_rasp=[0]*nr_elemente_prime
vector_prime[1]=1
vector_rasp[1]=1
#primes sieve
contor=2
for i in range(2,nr_elemente_prime):
if vector_prime[i]==-1:
vector_prime[i]=1
vector_rasp[contor]=i
contor=contor+1
for j in range(i+i,nr_elemente_prime,i):
if vector_prime[j]==-1:
vector_prime[j]=i
#print(i,j)
set_prime=set(vector_rasp)
set_prime.remove(0)
set_prime.remove(1)
answ_prime=list(set_prime)
answ_prime.sort()
return answ_prime
def binary_search(vector,valoarea):
left=0
right=len(vector)-1
while left<=right:
centru=(left+right)//2
# print(left,right,centru,vector[centru])
if vector[centru]<=valoarea:
left=centru+1
else:
right=centru-1
# print(left,right,centru,vector[centru])
return left
def main():
answ=[]
pp=10**9
#teste=int(input())
vector_factorial=[]
vector_factorial.append(1)
vector_factorial.append(1)
rest=998244353
#print(vector_factorial)
for i in range(2,5001):
#print("i=",i,vector_factorial[i-1])
val=i*vector_factorial[i-1]
#print("val=",val)
vector_factorial.append(val)
for gg in range(1):
#stringul=input()
#n=len(stringul)
#answer=''
#n=int(input())
a,b,c=list(map(int,input().split()))
#ab
rest= 998244353
total_ab=1
min_ab=min(a,b)
max_ab=max(a,b)
factorial=1
partial_max=max_ab
partial_min=min_ab
total_ab+=(max_ab*min_ab)
#print("min ab=",min_ab)
# print(math.comb(39,6))
for i in range(2,min_ab+1):
#print("i=",i)
factorial=vector_factorial[i]
partial_max=partial_max*(max_ab+1-i)//i
partial_min=partial_min*(min_ab+1-i)//i
c2=partial_max%rest
c1=partial_min%rest
total_ab+=(c1%rest*c2%rest*factorial%rest)%rest
#print(i,total_ab,vector_factorial[min_ab],vector_factorial[min_ab-i])
#print("i=",i,total_ab)
# print("total ab=",total_ab)
total_bc=1
min_ab=min(b,c)
max_ab=max(b,c)
partial_max=max_ab
partial_min=min_ab
factorial=1
total_bc+=(max_ab*min_ab)
for i in range(2,min_ab+1):
factorial=vector_factorial[i]
partial_max=partial_max*(max_ab+1-i)//i
partial_min=partial_min*(min_ab+1-i)//i
c2=partial_max%rest
c1=partial_min%rest
total_bc+=(c1%rest*c2%rest*factorial%rest)%rest
# print("total_bc=",total_bc)
total_ca=1
min_ab=min(a,c)
max_ab=max(a,c)
partial_max=max_ab
partial_min=min_ab
factorial=1
numitor_max=1
numitor_min=1
numarator_max=max_ab
numarator_min=min_ab
total_ca+=(max_ab*min_ab)
for i in range(2,min_ab+1):
factorial=vector_factorial[i]
partial_max=partial_max*(max_ab+1-i)//i
partial_min=partial_min*(min_ab+1-i)//i
c2=partial_max%rest
c1=partial_min%rest
total_ca+=(c1%rest*c2%rest*factorial%rest)%rest
answ=((total_ab*total_bc)%rest * total_ca)%rest
#print(total_ab,total_bc,total_ca)
print(int(answ))
main() | Title: The Intriguing Obsession
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of *a*, *b* and *c* distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998<=244<=353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input Specification:
The first and only line of input contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=5<=000) — the number of islands in the red, blue and purple clusters, respectively.
Output Specification:
Output one line containing an integer — the number of different ways to build bridges, modulo 998<=244<=353.
Demo Input:
['1 1 1\n', '1 2 2\n', '1 3 5\n', '6 2 9\n']
Demo Output:
['8\n', '63\n', '3264\n', '813023575\n']
Note:
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2<sup class="upper-index">3</sup> = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively. | ```python
import math
import random
import time
from collections import defaultdict
alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26}
alfabet_2={'1':"a", '2':"b", '3':"c", '4':"d", '5':"e", '6':"f", '7':"g", '8':"h", '9':"i", '10':"j", '11':"k", '12':"l", '13':"m", '14':"n", '15':"o", '16':"p", '17':"q", '18':"r", '19':"s", '20':"t", '21':"u", '22':"v", '23':"w", '24':"x", '25':"y", '26':"z"}
def prime_generator(nr_elemente_prime):
vector_prime=[-1]*nr_elemente_prime
vector_rasp=[0]*nr_elemente_prime
vector_prime[1]=1
vector_rasp[1]=1
#primes sieve
contor=2
for i in range(2,nr_elemente_prime):
if vector_prime[i]==-1:
vector_prime[i]=1
vector_rasp[contor]=i
contor=contor+1
for j in range(i+i,nr_elemente_prime,i):
if vector_prime[j]==-1:
vector_prime[j]=i
#print(i,j)
set_prime=set(vector_rasp)
set_prime.remove(0)
set_prime.remove(1)
answ_prime=list(set_prime)
answ_prime.sort()
return answ_prime
def binary_search(vector,valoarea):
left=0
right=len(vector)-1
while left<=right:
centru=(left+right)//2
# print(left,right,centru,vector[centru])
if vector[centru]<=valoarea:
left=centru+1
else:
right=centru-1
# print(left,right,centru,vector[centru])
return left
def main():
answ=[]
pp=10**9
#teste=int(input())
vector_factorial=[]
vector_factorial.append(1)
vector_factorial.append(1)
rest=998244353
#print(vector_factorial)
for i in range(2,5001):
#print("i=",i,vector_factorial[i-1])
val=i*vector_factorial[i-1]
#print("val=",val)
vector_factorial.append(val)
for gg in range(1):
#stringul=input()
#n=len(stringul)
#answer=''
#n=int(input())
a,b,c=list(map(int,input().split()))
#ab
rest= 998244353
total_ab=1
min_ab=min(a,b)
max_ab=max(a,b)
factorial=1
partial_max=max_ab
partial_min=min_ab
total_ab+=(max_ab*min_ab)
#print("min ab=",min_ab)
# print(math.comb(39,6))
for i in range(2,min_ab+1):
#print("i=",i)
factorial=vector_factorial[i]
partial_max=partial_max*(max_ab+1-i)//i
partial_min=partial_min*(min_ab+1-i)//i
c2=partial_max%rest
c1=partial_min%rest
total_ab+=(c1%rest*c2%rest*factorial%rest)%rest
#print(i,total_ab,vector_factorial[min_ab],vector_factorial[min_ab-i])
#print("i=",i,total_ab)
# print("total ab=",total_ab)
total_bc=1
min_ab=min(b,c)
max_ab=max(b,c)
partial_max=max_ab
partial_min=min_ab
factorial=1
total_bc+=(max_ab*min_ab)
for i in range(2,min_ab+1):
factorial=vector_factorial[i]
partial_max=partial_max*(max_ab+1-i)//i
partial_min=partial_min*(min_ab+1-i)//i
c2=partial_max%rest
c1=partial_min%rest
total_bc+=(c1%rest*c2%rest*factorial%rest)%rest
# print("total_bc=",total_bc)
total_ca=1
min_ab=min(a,c)
max_ab=max(a,c)
partial_max=max_ab
partial_min=min_ab
factorial=1
numitor_max=1
numitor_min=1
numarator_max=max_ab
numarator_min=min_ab
total_ca+=(max_ab*min_ab)
for i in range(2,min_ab+1):
factorial=vector_factorial[i]
partial_max=partial_max*(max_ab+1-i)//i
partial_min=partial_min*(min_ab+1-i)//i
c2=partial_max%rest
c1=partial_min%rest
total_ca+=(c1%rest*c2%rest*factorial%rest)%rest
answ=((total_ab*total_bc)%rest * total_ca)%rest
#print(total_ab,total_bc,total_ca)
print(int(answ))
main()
``` | 3 |
|
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,439,747,696 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 6,041,600 | n = int(input())
a = sorted(map(int, input().split()))
res = sum(a[:-1])
for i in range(n):
res += sum(a[i:])
print(res) | Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | ```python
n = int(input())
a = sorted(map(int, input().split()))
res = sum(a[:-1])
for i in range(n):
res += sum(a[i:])
print(res)
``` | 0 |
|
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0.
As usual, Alyona has some troubles and asks you to help. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case. | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
"output": "30"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1000000",
"output": "200000"
},
{
"input": "1000000 1",
"output": "200000"
},
{
"input": "1000000 1000000",
"output": "200000000000"
},
{
"input": "944 844",
"output": "159348"
},
{
"input": "368 984",
"output": "72423"
},
{
"input": "792 828",
"output": "131155"
},
{
"input": "920 969",
"output": "178296"
},
{
"input": "640 325",
"output": "41600"
},
{
"input": "768 170",
"output": "26112"
},
{
"input": "896 310",
"output": "55552"
},
{
"input": "320 154",
"output": "9856"
},
{
"input": "744 999",
"output": "148652"
},
{
"input": "630 843",
"output": "106218"
},
{
"input": "54 688",
"output": "7431"
},
{
"input": "478 828",
"output": "79157"
},
{
"input": "902 184",
"output": "33194"
},
{
"input": "31 29",
"output": "180"
},
{
"input": "751 169",
"output": "25384"
},
{
"input": "879 14",
"output": "2462"
},
{
"input": "7 858",
"output": "1201"
},
{
"input": "431 702",
"output": "60512"
},
{
"input": "855 355",
"output": "60705"
},
{
"input": "553 29",
"output": "3208"
},
{
"input": "721767 525996",
"output": "75929310986"
},
{
"input": "805191 74841",
"output": "12052259926"
},
{
"input": "888615 590981",
"output": "105030916263"
},
{
"input": "4743 139826",
"output": "132638943"
},
{
"input": "88167 721374",
"output": "12720276292"
},
{
"input": "171591 13322",
"output": "457187060"
},
{
"input": "287719 562167",
"output": "32349225415"
},
{
"input": "371143 78307",
"output": "5812618980"
},
{
"input": "487271 627151",
"output": "61118498984"
},
{
"input": "261436 930642",
"output": "48660664382"
},
{
"input": "377564 446782",
"output": "33737759810"
},
{
"input": "460988 28330",
"output": "2611958008"
},
{
"input": "544412 352983",
"output": "38433636199"
},
{
"input": "660540 869123",
"output": "114818101284"
},
{
"input": "743964 417967",
"output": "62190480238"
},
{
"input": "827388 966812",
"output": "159985729411"
},
{
"input": "910812 515656",
"output": "93933134534"
},
{
"input": "26940 64501",
"output": "347531388"
},
{
"input": "110364 356449",
"output": "7867827488"
},
{
"input": "636358 355531",
"output": "45248999219"
},
{
"input": "752486 871672",
"output": "131184195318"
},
{
"input": "803206 420516",
"output": "67552194859"
},
{
"input": "919334 969361",
"output": "178233305115"
},
{
"input": "35462 261309",
"output": "1853307952"
},
{
"input": "118887 842857",
"output": "20040948031"
},
{
"input": "202311 358998",
"output": "14525848875"
},
{
"input": "285735 907842",
"output": "51880446774"
},
{
"input": "401863 456686",
"output": "36705041203"
},
{
"input": "452583 972827",
"output": "88056992428"
},
{
"input": "235473 715013",
"output": "33673251230"
},
{
"input": "318897 263858",
"output": "16828704925"
},
{
"input": "402321 812702",
"output": "65393416268"
},
{
"input": "518449 361546",
"output": "37488632431"
},
{
"input": "634577 910391",
"output": "115542637921"
},
{
"input": "685297 235043",
"output": "32214852554"
},
{
"input": "801425 751183",
"output": "120403367155"
},
{
"input": "884849 300028",
"output": "53095895155"
},
{
"input": "977 848872",
"output": "165869588"
},
{
"input": "51697 397716",
"output": "4112144810"
},
{
"input": "834588 107199",
"output": "17893399803"
},
{
"input": "918012 688747",
"output": "126455602192"
},
{
"input": "1436 237592",
"output": "68236422"
},
{
"input": "117564 753732",
"output": "17722349770"
},
{
"input": "200988 302576",
"output": "12162829017"
},
{
"input": "284412 818717",
"output": "46570587880"
},
{
"input": "400540 176073",
"output": "14104855884"
},
{
"input": "483964 724917",
"output": "70166746198"
},
{
"input": "567388 241058",
"output": "27354683301"
},
{
"input": "650812 789902",
"output": "102815540084"
},
{
"input": "400999 756281",
"output": "60653584944"
},
{
"input": "100 101",
"output": "2020"
},
{
"input": "100 102",
"output": "2040"
},
{
"input": "103 100",
"output": "2060"
},
{
"input": "100 104",
"output": "2080"
},
{
"input": "3 4",
"output": "3"
},
{
"input": "11 23",
"output": "50"
},
{
"input": "8 14",
"output": "23"
},
{
"input": "23423 34234",
"output": "160372597"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "999999 999999",
"output": "199999600001"
},
{
"input": "82 99",
"output": "1624"
},
{
"input": "21 18",
"output": "75"
},
{
"input": "234 234",
"output": "10952"
},
{
"input": "4 4",
"output": "4"
},
{
"input": "6 13",
"output": "15"
},
{
"input": "3 9",
"output": "6"
},
{
"input": "99999 99999",
"output": "1999960001"
},
{
"input": "34 33",
"output": "225"
},
{
"input": "2 2",
"output": "0"
},
{
"input": "333 1",
"output": "66"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "8 2",
"output": "3"
},
{
"input": "2179 2218",
"output": "966605"
},
{
"input": "1000000 999999",
"output": "199999800000"
},
{
"input": "873828 774207",
"output": "135304750879"
},
{
"input": "13 19",
"output": "50"
},
{
"input": "1648 576469",
"output": "190004183"
},
{
"input": "11 13",
"output": "28"
},
{
"input": "5 8",
"output": "8"
},
{
"input": "650074 943659",
"output": "122689636154"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "54 43",
"output": "465"
},
{
"input": "14 9",
"output": "26"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "543 534",
"output": "57993"
},
{
"input": "321 123",
"output": "7896"
},
{
"input": "21 3",
"output": "12"
},
{
"input": "2 1",
"output": "0"
},
{
"input": "4 3",
"output": "3"
},
{
"input": "47474 74747",
"output": "709707816"
},
{
"input": "4 9",
"output": "8"
},
{
"input": "7 4",
"output": "6"
},
{
"input": "9 4",
"output": "8"
},
{
"input": "12414 4214",
"output": "10462520"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "253 821",
"output": "41542"
},
{
"input": "2 4",
"output": "2"
}
] | 1,689,683,859 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 128 | 77 | 1,536,000 | n, m = map(int, input().split())
li = [0] * 5
for i in range(1, m + 1):
if i % 5 == 0:
li[0] += 1
elif i % 5 == 1:
li[1] += 1
elif i % 5 == 2:
li[2] += 1
elif i % 5 == 3:
li[3] += 1
elif i % 5 == 4:
li[4] += 1
ans = n // 5 * sum(li)
if n % 5 == 0:
pass
elif n % 5 == 1:
ans += li[4]
elif n % 5 == 2:
ans += li[3] + li[4]
elif n % 5 == 3:
ans += li[3] + li[4] + li[2]
elif n % 5 == 4:
ans += li[3] + li[4] + li[2] + li[1]
print(ans) | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0.
As usual, Alyona has some troubles and asks you to help.
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000).
Output Specification:
Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5.
Demo Input:
['6 12\n', '11 14\n', '1 5\n', '3 8\n', '5 7\n', '21 21\n']
Demo Output:
['14\n', '31\n', '1\n', '5\n', '7\n', '88\n']
Note:
Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case. | ```python
n, m = map(int, input().split())
li = [0] * 5
for i in range(1, m + 1):
if i % 5 == 0:
li[0] += 1
elif i % 5 == 1:
li[1] += 1
elif i % 5 == 2:
li[2] += 1
elif i % 5 == 3:
li[3] += 1
elif i % 5 == 4:
li[4] += 1
ans = n // 5 * sum(li)
if n % 5 == 0:
pass
elif n % 5 == 1:
ans += li[4]
elif n % 5 == 2:
ans += li[3] + li[4]
elif n % 5 == 3:
ans += li[3] + li[4] + li[2]
elif n % 5 == 4:
ans += li[3] + li[4] + li[2] + li[1]
print(ans)
``` | 3 |
|
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": "9"
}
] | 1,594,495,171 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 171 | 11,366,400 | def call(l):
x,y=0,len(l)-1
s1=l[0]
n=len(l)
s2,s2p=l[n-1],0
yo=[0]
while(x<y):
#print(s1,s2,s2p,x,y)
if(s1==s2):
yo.append(s1)
if(s1==s2p):
yo.append(s1)
s2p=s2
if(y-x==2):
x=x+1
s1=s1+l[x]
else:
(x,y)=(x+1,y-1)
s1=s1+l[x]
s2=s2+l[y]
return max(yo)
n=int(input())
l=list(map(int,input().split()))
n=len(l)
x=call(l)
print(x)
| Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.
Output Specification:
Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
Demo Input:
['5\n1 3 1 1 4\n', '5\n1 3 2 1 4\n', '3\n4 1 2\n']
Demo Output:
['5\n', '4\n', '0\n']
Note:
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | ```python
def call(l):
x,y=0,len(l)-1
s1=l[0]
n=len(l)
s2,s2p=l[n-1],0
yo=[0]
while(x<y):
#print(s1,s2,s2p,x,y)
if(s1==s2):
yo.append(s1)
if(s1==s2p):
yo.append(s1)
s2p=s2
if(y-x==2):
x=x+1
s1=s1+l[x]
else:
(x,y)=(x+1,y-1)
s1=s1+l[x]
s2=s2+l[y]
return max(yo)
n=int(input())
l=list(map(int,input().split()))
n=len(l)
x=call(l)
print(x)
``` | 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,660,996,616 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, m, a = int(input())
counter = 0
if (m*n) > (a*a) and (m*n) % (a*a) != 0:
counter += 1
while s1 > 0:
s1 -= s2
counter += 1
print(counter) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n, m, a = int(input())
counter = 0
if (m*n) > (a*a) and (m*n) % (a*a) != 0:
counter += 1
while s1 > 0:
s1 -= s2
counter += 1
print(counter)
``` | -1 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
"input": "4744000695826",
"output": "YES"
},
{
"input": "10000000004744744",
"output": "YES"
},
{
"input": "446486416781684178",
"output": "YES"
},
{
"input": "999999999",
"output": "NO"
},
{
"input": "7777",
"output": "YES"
},
{
"input": "87414417444",
"output": "NO"
},
{
"input": "111222333444555667",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "4700",
"output": "NO"
},
{
"input": "3794555488744477",
"output": "NO"
},
{
"input": "444444444444444444",
"output": "NO"
},
{
"input": "474447447774444774",
"output": "NO"
},
{
"input": "777777777777777",
"output": "NO"
},
{
"input": "34777745021000000",
"output": "NO"
},
{
"input": "963",
"output": "NO"
},
{
"input": "855474448854788540",
"output": "NO"
},
{
"input": "999999999999994744",
"output": "YES"
},
{
"input": "400000000474",
"output": "YES"
},
{
"input": "123456789123456789",
"output": "YES"
},
{
"input": "740577777584945874",
"output": "NO"
},
{
"input": "7777777",
"output": "YES"
},
{
"input": "4444000111222333",
"output": "YES"
},
{
"input": "9847745885202111",
"output": "YES"
},
{
"input": "123456000000",
"output": "NO"
},
{
"input": "4744447444444",
"output": "NO"
},
{
"input": "7477",
"output": "YES"
},
{
"input": "4747477",
"output": "YES"
},
{
"input": "777777777444444444",
"output": "NO"
}
] | 1,698,693,274 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = input()
yesNo = "No"
s = 0
for i in n:
if i == "4" or i == "7":
s += 1
if s == 4 or s == 7:
yesNo = "Yes"
print(yesNo) | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output Specification:
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Demo Input:
['40047\n', '7747774\n', '1000000000000000000\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | ```python
n = input()
yesNo = "No"
s = 0
for i in n:
if i == "4" or i == "7":
s += 1
if s == 4 or s == 7:
yesNo = "Yes"
print(yesNo)
``` | 0 |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,641,366,566 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 310 | 11,161,600 | n1 = int(input())
list1 = []
x = input().split()
for i in x:
list1.append(int(i))
min1 = list1[1] - list1[0]
for i in range(len(list1)-1):
y = abs(list1[i+1]- list1[i])
if y <= min1:
temp = []
min1 = y
temp.append(i)
temp.append(i+1)
if abs(list1[-1]- list1[0]) < min1:
print(1,len(list1))
else:
print(temp[0]+1,temp[1]+1)
| Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n1 = int(input())
list1 = []
x = input().split()
for i in x:
list1.append(int(i))
min1 = list1[1] - list1[0]
for i in range(len(list1)-1):
y = abs(list1[i+1]- list1[i])
if y <= min1:
temp = []
min1 = y
temp.append(i)
temp.append(i+1)
if abs(list1[-1]- list1[0]) < min1:
print(1,len(list1))
else:
print(temp[0]+1,temp[1]+1)
``` | -1 |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ghbdtn",
"output": "Just a legend"
},
{
"input": "a",
"output": "Just a legend"
},
{
"input": "aa",
"output": "Just a legend"
},
{
"input": "ab",
"output": "Just a legend"
},
{
"input": "aaa",
"output": "a"
},
{
"input": "aba",
"output": "Just a legend"
},
{
"input": "aab",
"output": "Just a legend"
},
{
"input": "abb",
"output": "Just a legend"
},
{
"input": "abc",
"output": "Just a legend"
},
{
"input": "aaabaabaaaaab",
"output": "Just a legend"
},
{
"input": "aabaaabaaaaab",
"output": "aab"
},
{
"input": "aaabaaaabab",
"output": "Just a legend"
},
{
"input": "abcabcabcabcabc",
"output": "abcabcabc"
},
{
"input": "aaaaabaaaa",
"output": "aaaa"
},
{
"input": "aaaabaaaaaaa",
"output": "aaaa"
},
{
"input": "ghghghgxghghghg",
"output": "ghghg"
},
{
"input": "kincenvizh",
"output": "Just a legend"
},
{
"input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw",
"output": "Just a legend"
},
{
"input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx",
"output": "Just a legend"
},
{
"input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb",
"output": "nfbdzgdlbjhrlvfryyjb"
},
{
"input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp",
"output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp"
},
{
"input": "abcazabca",
"output": "a"
}
] | 1,656,330,923 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 31,744,000 | from requests import delete
str = input()
l = len(str)
toBeChkd = list(range(1,l-1))
i = 0;lps = 0;check = True
while(check == True):
for j in range(len(toBeChkd)):
if(toBeChkd[j] == l):
toBeChkd[j] = -1
lps = i
elif(toBeChkd[j] == -1):
continue
elif(str[i] == str[toBeChkd[j]]):
toBeChkd[j] += 1
else: toBeChkd[j] = -1
check = False
for e in toBeChkd:
if(e != -1): check = True
i+=1
if(lps == 0):
print("Just a legend")
quit()
ps = str[:lps]
pssb = ""
i=lps
while(i<l-lps-1):
j = 0
while(j<lps and i+j<l-1):
if(str[i+j] == ps[j]):
if(j == len(pssb)):
pssb += ps[j]
else: break
j += 1
i +=1
if(len(pssb) == 0):
print("Just a legend")
else:
print(pssb)
| Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
Input Specification:
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output Specification:
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
Demo Input:
['fixprefixsuffix\n', 'abcdabc\n']
Demo Output:
['fix', 'Just a legend']
Note:
none | ```python
from requests import delete
str = input()
l = len(str)
toBeChkd = list(range(1,l-1))
i = 0;lps = 0;check = True
while(check == True):
for j in range(len(toBeChkd)):
if(toBeChkd[j] == l):
toBeChkd[j] = -1
lps = i
elif(toBeChkd[j] == -1):
continue
elif(str[i] == str[toBeChkd[j]]):
toBeChkd[j] += 1
else: toBeChkd[j] = -1
check = False
for e in toBeChkd:
if(e != -1): check = True
i+=1
if(lps == 0):
print("Just a legend")
quit()
ps = str[:lps]
pssb = ""
i=lps
while(i<l-lps-1):
j = 0
while(j<lps and i+j<l-1):
if(str[i+j] == ps[j]):
if(j == len(pssb)):
pssb += ps[j]
else: break
j += 1
i +=1
if(len(pssb) == 0):
print("Just a legend")
else:
print(pssb)
``` | -1 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,636,995,977 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | yakko, wakko=input().split()
if yakko<wakko:
if wakko=="1":
print("6/6")
elif wakko=="2":
print("5/6")
elif wakko=="3":
print("2/3")
elif wakko=="4":
print("1/2")
elif wakko=="5":
print("1/3")
elif wakko=="6":
print("1/6")
else:
if yakko=="1":
print("6/6")
elif yakko=="2":
print("5/6")
elif yakko=="3":
print("2/3")
elif yakko=="4":
print("1/2")
elif yakko=="5":
print("1/3")
elif yakko=="6":
print("1/6")
# | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
yakko, wakko=input().split()
if yakko<wakko:
if wakko=="1":
print("6/6")
elif wakko=="2":
print("5/6")
elif wakko=="3":
print("2/3")
elif wakko=="4":
print("1/2")
elif wakko=="5":
print("1/3")
elif wakko=="6":
print("1/6")
else:
if yakko=="1":
print("6/6")
elif yakko=="2":
print("5/6")
elif yakko=="3":
print("2/3")
elif yakko=="4":
print("1/2")
elif yakko=="5":
print("1/3")
elif yakko=="6":
print("1/6")
#
``` | 0 |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots . | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3. | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
},
{
"input": "997",
"output": "328"
},
{
"input": "2",
"output": "1"
},
{
"input": "1987",
"output": "660"
},
{
"input": "1993",
"output": "656"
},
{
"input": "1997",
"output": "996"
},
{
"input": "1999",
"output": "648"
},
{
"input": "1297",
"output": "432"
},
{
"input": "163",
"output": "54"
},
{
"input": "1259",
"output": "576"
},
{
"input": "821",
"output": "320"
},
{
"input": "29",
"output": "12"
},
{
"input": "43",
"output": "12"
},
{
"input": "1949",
"output": "972"
},
{
"input": "1879",
"output": "624"
},
{
"input": "1759",
"output": "584"
},
{
"input": "1597",
"output": "432"
},
{
"input": "1619",
"output": "808"
},
{
"input": "1277",
"output": "560"
},
{
"input": "1097",
"output": "544"
},
{
"input": "953",
"output": "384"
},
{
"input": "751",
"output": "200"
},
{
"input": "607",
"output": "200"
},
{
"input": "509",
"output": "252"
},
{
"input": "431",
"output": "168"
},
{
"input": "317",
"output": "156"
},
{
"input": "211",
"output": "48"
},
{
"input": "127",
"output": "36"
},
{
"input": "101",
"output": "40"
},
{
"input": "31",
"output": "8"
}
] | 1,467,795,838 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | p = int(input())
cnt = 0
for i in range(1, p):
pr = True
val = i / i
for j in range(1, p - 1):
if (val * i - 1) % p is 0:
val *= i
pr = False
break
if not pr:
continue
if (val * i - 1) % p is 0:
cnt += 1
print(cnt)
| Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots .
Input Specification:
The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime.
Output Specification:
Output on a single line the number of primitive roots .
Demo Input:
['3\n', '5\n']
Demo Output:
['1\n', '2\n']
Note:
The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3. | ```python
p = int(input())
cnt = 0
for i in range(1, p):
pr = True
val = i / i
for j in range(1, p - 1):
if (val * i - 1) % p is 0:
val *= i
pr = False
break
if not pr:
continue
if (val * i - 1) % p is 0:
cnt += 1
print(cnt)
``` | 0 |
|
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8",
"output": "429.309294877"
},
{
"input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10",
"output": "13629.282573522"
},
{
"input": "2 1\n-20 -10\n-10 -6",
"output": "0.215406592"
},
{
"input": "2 13\n13 -10\n-3 -2",
"output": "4.651021393"
},
{
"input": "2 21\n13 8\n14 10",
"output": "0.939148551"
},
{
"input": "2 75\n-3 12\n1 12",
"output": "6.000000000"
},
{
"input": "2 466\n10 16\n-6 -3",
"output": "231.503997374"
},
{
"input": "2 999\n6 16\n-17 -14",
"output": "755.286284531"
},
{
"input": "2 1000\n-17 -14\n-14 -8",
"output": "134.164078650"
},
{
"input": "3 384\n-4 -19\n-17 -2\n3 4",
"output": "324.722285390"
},
{
"input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5",
"output": "668.956254495"
},
{
"input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15",
"output": "789.212495576"
},
{
"input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18",
"output": "3415.618464093"
},
{
"input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5",
"output": "2113.552527680"
},
{
"input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6",
"output": "2999.497312668"
},
{
"input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4",
"output": "2797.756635934"
},
{
"input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5",
"output": "12766.080247922"
},
{
"input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3",
"output": "36.467924851"
},
{
"input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4",
"output": "9495.010556306"
},
{
"input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14",
"output": "6087.366930474"
},
{
"input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11",
"output": "8929.162822862"
},
{
"input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13",
"output": "16314.207721932"
},
{
"input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11",
"output": "22153.369189802"
}
] | 1,690,628,374 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | from math import sqrt
n, k = [int(i) for i in input().split()]
dur = 0
x, y = [int(i) for i in input().split()]
for i in range(n - 1):
x1, y1 = [int(i) for i in input().split()]
dur += (sqrt((x1 - x) ** 2 + (y1 - y) ** 2)) / 50
x, y = x1, y1
print(dur * k) | Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Output Specification:
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
Demo Input:
['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n']
Demo Output:
['0.200000000', '6.032163204', '3.000000000']
Note:
none | ```python
from math import sqrt
n, k = [int(i) for i in input().split()]
dur = 0
x, y = [int(i) for i in input().split()]
for i in range(n - 1):
x1, y1 = [int(i) for i in input().split()]
dur += (sqrt((x1 - x) ** 2 + (y1 - y) ** 2)) / 50
x, y = x1, y1
print(dur * k)
``` | 3 |
|
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times. | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81 -17 80\n87 23",
"output": "YES"
},
{
"input": "41 366 218 -240\n3456 1234",
"output": "NO"
},
{
"input": "-61972 -39646 -42371 -24854\n573 238",
"output": "NO"
},
{
"input": "-84870 -42042 94570 98028\n8972 23345",
"output": "YES"
},
{
"input": "-58533 -50999 -1007 -59169\n8972 23345",
"output": "NO"
},
{
"input": "-100000 -100000 100000 100000\n100000 100000",
"output": "YES"
},
{
"input": "-100000 -100000 100000 100000\n1 1",
"output": "YES"
},
{
"input": "5 2 5 3\n1 1",
"output": "NO"
},
{
"input": "5 5 5 5\n5 5",
"output": "YES"
},
{
"input": "0 0 1000 1000\n1 1",
"output": "YES"
},
{
"input": "0 0 0 1\n1 1",
"output": "NO"
},
{
"input": "1 1 4 4\n2 2",
"output": "NO"
},
{
"input": "100000 100000 99999 99999\n100000 100000",
"output": "NO"
},
{
"input": "1 1 1 6\n1 5",
"output": "NO"
},
{
"input": "2 9 4 0\n2 3",
"output": "YES"
},
{
"input": "0 0 0 9\n2 3",
"output": "NO"
},
{
"input": "14 88 14 88\n100 500",
"output": "YES"
},
{
"input": "-1 0 3 0\n4 4",
"output": "NO"
},
{
"input": "0 0 8 9\n2 3",
"output": "NO"
},
{
"input": "-2 5 7 -6\n1 1",
"output": "YES"
},
{
"input": "3 7 -8 8\n2 2",
"output": "NO"
},
{
"input": "-4 -8 -6 -1\n1 3",
"output": "NO"
},
{
"input": "0 8 6 2\n1 1",
"output": "YES"
},
{
"input": "-5 -2 -8 -2\n1 1",
"output": "NO"
},
{
"input": "1 4 -5 0\n1 1",
"output": "YES"
},
{
"input": "8 -4 4 -7\n1 2",
"output": "NO"
},
{
"input": "5 2 2 4\n2 2",
"output": "NO"
},
{
"input": "2 0 -4 6\n1 2",
"output": "NO"
},
{
"input": "-2 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "-6 5 10 6\n2 4",
"output": "NO"
},
{
"input": "3 -7 1 -8\n1 2",
"output": "NO"
},
{
"input": "4 1 4 -4\n9 4",
"output": "NO"
},
{
"input": "9 -3 -9 -3\n2 2",
"output": "NO"
},
{
"input": "-6 -6 -10 -5\n6 7",
"output": "NO"
},
{
"input": "-5 -2 2 2\n1 7",
"output": "NO"
},
{
"input": "9 0 8 1\n7 10",
"output": "NO"
},
{
"input": "-1 6 -7 -6\n6 4",
"output": "YES"
},
{
"input": "2 2 -3 -3\n3 1",
"output": "NO"
},
{
"input": "2 -6 7 2\n2 1",
"output": "NO"
},
{
"input": "-6 2 -7 -7\n1 2",
"output": "NO"
},
{
"input": "-5 -5 -1 -5\n2 2",
"output": "YES"
},
{
"input": "0 5 3 -6\n2 2",
"output": "NO"
},
{
"input": "0 -6 2 -1\n1 1",
"output": "NO"
},
{
"input": "-6 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "7 -7 1 -7\n2 2",
"output": "NO"
},
{
"input": "99966 -99952 -99966 99923\n1 1",
"output": "NO"
},
{
"input": "99921 99980 -99956 -99907\n3 4",
"output": "NO"
},
{
"input": "100000 100000 -100000 -100000\n1 1",
"output": "YES"
},
{
"input": "1 0 2 0\n5 1",
"output": "NO"
},
{
"input": "-3 0 -8 0\n7 2",
"output": "NO"
},
{
"input": "-9 4 -5 -1\n8 2",
"output": "NO"
},
{
"input": "-99999 -100000 100000 100000\n1 1",
"output": "NO"
},
{
"input": "0 0 -100 -100\n2 2",
"output": "YES"
},
{
"input": "9 -5 -3 -2\n1 4",
"output": "NO"
},
{
"input": "1 -10 -10 5\n7 5",
"output": "NO"
},
{
"input": "6 -9 -1 -9\n1 9",
"output": "NO"
}
] | 1,670,598,912 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | x1, y1, x2, y2 = map(int, input().split())
x, y = map(int, input().split())
if abs(x1 - x2) % 2 * x != 0 or abs(y2 - y1) % 2 * x != 0:
print("NO")
else:
print("YES")
| Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times.
Input Specification:
The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle.
Output Specification:
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
Demo Input:
['0 0 0 6\n2 3\n', '1 1 3 6\n1 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | ```python
x1, y1, x2, y2 = map(int, input().split())
x, y = map(int, input().split())
if abs(x1 - x2) % 2 * x != 0 or abs(y2 - y1) % 2 * x != 0:
print("NO")
else:
print("YES")
``` | 0 |
|
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,613,457,051 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,150,400 | n = int(input())
arr = list(map(int,input().split()))
arr =sorted(arr)
for i in range(1,3001):
if i!=arr[i-1]:
print(i)
break | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n = int(input())
arr = list(map(int,input().split()))
arr =sorted(arr)
for i in range(1,3001):
if i!=arr[i-1]:
print(i)
break
``` | -1 |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,457,889,275 | 18,875 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 12 | 3,000 | 1,228,800 | n = int(input())
names = []
for i in range(n):
name = input()
if name in names: names.remove(name)
names = [name] + names
for name in names:
print(name)
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
n = int(input())
names = []
for i in range(n):
name = input()
if name in names: names.remove(name)
names = [name] + names
for name in names:
print(name)
``` | 0 |
|
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*? | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "1010101001001111000111110011111000010101011111101010",
"output": "74"
},
{
"input": "1100000010010100111011100011110101111",
"output": "55"
},
{
"input": "11000111111110110110100110110101111100010100110110010",
"output": "74"
},
{
"input": "11100000110100011110101001101111100000011001111000011110000000111110111",
"output": "106"
},
{
"input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111",
"output": "133"
},
{
"input": "1000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "72"
},
{
"input": "10000100000",
"output": "16"
}
] | 1,697,351,929 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | t=input()
if t=="1":
print(0)
else:
cnt=t.count('1')
cnt1=t.count('0')
print(max(cnt*cnt1,cnt1+cnt))
| Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*?
Input Specification:
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Output Specification:
Print the required number of actions.
Demo Input:
['1\n', '1001001\n', '101110\n']
Demo Output:
['0\n', '12\n', '8\n']
Note:
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | ```python
t=input()
if t=="1":
print(0)
else:
cnt=t.count('1')
cnt1=t.count('0')
print(max(cnt*cnt1,cnt1+cnt))
``` | 0 |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide. | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8",
"output": "-1"
},
{
"input": "3\n2 5\n3 4\n2 3",
"output": "1"
},
{
"input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19",
"output": "-1"
},
{
"input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3",
"output": "1"
},
{
"input": "1\n1 100000",
"output": "1"
},
{
"input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5",
"output": "6"
},
{
"input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19",
"output": "-1"
},
{
"input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8",
"output": "-1"
},
{
"input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6",
"output": "37"
},
{
"input": "1\n999999999 1000000000",
"output": "1"
},
{
"input": "3\n1 20\n2 22\n3 18",
"output": "-1"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "2\n100001 100008\n100005 100006",
"output": "1"
},
{
"input": "1\n1000000 10000000",
"output": "1"
},
{
"input": "3\n3 6\n2 4\n1 5",
"output": "-1"
},
{
"input": "2\n3 5\n1 2",
"output": "-1"
}
] | 1,634,142,386 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 1,838 | 20,172,800 | n = int(input())
data = []
while len(data) != n:
data.append(list(map(int, input().split(' '))))
res = -1
minx = data[0][0]
maxx = 0
for i in data:
minx = min(minx, i[0])
maxx = max(maxx, i[1])
for i in range(0, len(data)):
if data[i][0] <= minx and data[i][1] >= maxx:
res = i + 1
print(res) | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide.
Output Specification:
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n']
Demo Output:
['-1\n', '3\n']
Note:
none | ```python
n = int(input())
data = []
while len(data) != n:
data.append(list(map(int, input().split(' '))))
res = -1
minx = data[0][0]
maxx = 0
for i in data:
minx = min(minx, i[0])
maxx = max(maxx, i[1])
for i in range(0, len(data)):
if data[i][0] <= minx and data[i][1] >= maxx:
res = i + 1
print(res)
``` | 3 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,673,240,018 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | ips = [int(i) for i in input().split()]
a, b = ips[0], ips[1]
diffSocks = min(a, b)
sameSocks = (max(a, b) - min(a, b)) // 2
print(diffSocks, sameSocks) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
ips = [int(i) for i in input().split()]
a, b = ips[0], ips[1]
diffSocks = min(a, b)
sameSocks = (max(a, b) - min(a, b)) // 2
print(diffSocks, sameSocks)
``` | 3 |
|
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect? | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0. | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "300000"
},
{
"input": "1\n-1 1",
"output": "1"
},
{
"input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463",
"output": "1036452"
},
{
"input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532",
"output": "632240"
},
{
"input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044",
"output": "891593"
},
{
"input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422",
"output": "1109655"
},
{
"input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834",
"output": "847241"
},
{
"input": "3\n-94146 4473\n28707 99079\n-4153 8857",
"output": "112409"
},
{
"input": "3\n-3 3\n-2 2\n-1 1",
"output": "1"
},
{
"input": "2\n100000 3\n-100000 9",
"output": "12"
},
{
"input": "2\n-100000 100000\n100000 99999",
"output": "199999"
}
] | 1,612,639,085 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 62 | 307,200 |
n=int(input())
trees=[]
left=0
for _ in range(n):
trees.append([int(x) for x in input().split()])
left+=trees[-1][0]<0
right=n-left
trees.sort()
ans=0
if right>=left:
for _ in range(min(left,right)*2+(left!=right)):
ans+=trees[_][1]
else:
for _ in range(len(trees)-1,len(trees)-min(left,right)*2-2,-1):
ans+=trees[_][1]
print(ans)
| Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input Specification:
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output Specification:
Output the maximum number of apples Amr can collect.
Demo Input:
['2\n-1 5\n1 5\n', '3\n-2 2\n1 4\n-1 3\n', '3\n1 9\n3 5\n7 10\n']
Demo Output:
['10', '9', '9']
Note:
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | ```python
n=int(input())
trees=[]
left=0
for _ in range(n):
trees.append([int(x) for x in input().split()])
left+=trees[-1][0]<0
right=n-left
trees.sort()
ans=0
if right>=left:
for _ in range(min(left,right)*2+(left!=right)):
ans+=trees[_][1]
else:
for _ in range(len(trees)-1,len(trees)-min(left,right)*2-2,-1):
ans+=trees[_][1]
print(ans)
``` | 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,692,466,679 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
bool solve(string s,string z){
if(s.size() == 1) {
return s==z;
}
if(s == z){
return true;
} else{
string s1 = s.substr(0, s.size()/2);
string s2 = s.substr(s.size()/2,s.size()/2);
string z1 = z.substr(0,s.size()/2);
string z2 = z.substr(s.size()/2, s.size()/2);
return (solve(z1,s2) & solve(z2,s1)) || (solve(z1,s1) & solve(z2,s2)) ;
}
}
int main(){
string a, b; cin >> a >> b;
cout << (solve(a,b)? "YES\n":"NO\n");
} | 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
#include <bits/stdc++.h>
using namespace std;
bool solve(string s,string z){
if(s.size() == 1) {
return s==z;
}
if(s == z){
return true;
} else{
string s1 = s.substr(0, s.size()/2);
string s2 = s.substr(s.size()/2,s.size()/2);
string z1 = z.substr(0,s.size()/2);
string z2 = z.substr(s.size()/2, s.size()/2);
return (solve(z1,s2) & solve(z2,s1)) || (solve(z1,s1) & solve(z2,s2)) ;
}
}
int main(){
string a, b; cin >> a >> b;
cout << (solve(a,b)? "YES\n":"NO\n");
}
``` | -1 |
|
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
"input": "2 6 4 5 6 5 1 3",
"output": "0"
},
{
"input": "1 7 3 5 3 6 2 1",
"output": "6"
},
{
"input": "2 4 5 4 5 7 3 2",
"output": "1"
},
{
"input": "2 3 6 5 7 8 2 1",
"output": "4"
},
{
"input": "1 4 5 5 3 10 3 1",
"output": "6"
},
{
"input": "1 4 6 7 3 5 1 3",
"output": "1"
},
{
"input": "1 6 5 5 5 8 3 1",
"output": "8"
},
{
"input": "1 7 5 3 3 9 2 1",
"output": "9"
},
{
"input": "3 5 3 7 6 10 3 1",
"output": "1"
},
{
"input": "3 6 3 5 3 6 3 1",
"output": "2"
},
{
"input": "1 7 5 5 5 5 2 2",
"output": "2"
},
{
"input": "2 5 3 5 6 9 2 1",
"output": "3"
},
{
"input": "3 4 3 5 3 6 2 1",
"output": "2"
},
{
"input": "1 5 5 4 7 6 3 1",
"output": "6"
},
{
"input": "2 3 7 6 5 9 3 1",
"output": "3"
},
{
"input": "2 6 5 3 3 8 1 1",
"output": "4"
},
{
"input": "2 4 7 3 4 10 2 1",
"output": "5"
},
{
"input": "1 1000 1000 1000 1000 1000 1 1",
"output": "1000"
},
{
"input": "17 1000 1000 1000 1000 1000 3 7",
"output": "8"
},
{
"input": "115 1000 1000 1000 1000 1000 17 15",
"output": "0"
},
{
"input": "1 587 981 1 2 1 1 1",
"output": "1"
},
{
"input": "1 1 2 1 2 2 1 1",
"output": "2"
}
] | 1,699,268,262 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n, k, l, c, d, p, nl, nd = map(int, input().split())
toasts_with_drink = (k * l) // (n * nl)
toasts_with_lime = (c * d) // n
toasts_with_salt = p // (n * nd)
max_toasts = min(toasts_with_drink, toasts_with_lime, toasts_with_salt)
print(max_toasts) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
Input Specification:
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Output Specification:
Print a single integer — the number of toasts each friend can make.
Demo Input:
['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | ```python
n, k, l, c, d, p, nl, nd = map(int, input().split())
toasts_with_drink = (k * l) // (n * nl)
toasts_with_lime = (c * d) // n
toasts_with_salt = p // (n * nd)
max_toasts = min(toasts_with_drink, toasts_with_lime, toasts_with_salt)
print(max_toasts)
``` | 3 |
|
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51",
"output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52"
},
{
"input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1",
"output": "0\n0"
},
{
"input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5",
"output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21"
},
{
"input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0",
"output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95"
},
{
"input": "1\n100\n1\n1 100",
"output": "0"
},
{
"input": "1\n100\n1\n1 1",
"output": "0"
},
{
"input": "1\n50\n1\n1 25",
"output": "0"
},
{
"input": "2\n50 0\n1\n1 1",
"output": "0\n49"
},
{
"input": "1\n10\n0",
"output": "10"
}
] | 1,696,599,881 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 26 | 92 | 0 | n = int(input())
arr = [int(i) for i in input().split()]
q = int(input())
for i in range(q):
a, b = input().split()
a = int(a)
b = int(b)
a -= 1
if a == 0:
arr[a+1] += arr[a] - b
arr[a] = 0
elif a == n - 1:
arr[a-1] += b - 1
arr[a] = 0
else:
arr[a + 1] += arr[a] - b
arr[a - 1] += b - 1
arr[a] = 0
for i in range(n):
print(arr[i])
| Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
Input Specification:
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
Output Specification:
On the *i*-th line of the output print the number of birds on the *i*-th wire.
Demo Input:
['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n']
Demo Output:
['0\n12\n5\n0\n16\n', '3\n0\n3\n']
Note:
none | ```python
n = int(input())
arr = [int(i) for i in input().split()]
q = int(input())
for i in range(q):
a, b = input().split()
a = int(a)
b = int(b)
a -= 1
if a == 0:
arr[a+1] += arr[a] - b
arr[a] = 0
elif a == n - 1:
arr[a-1] += b - 1
arr[a] = 0
else:
arr[a + 1] += arr[a] - b
arr[a - 1] += b - 1
arr[a] = 0
for i in range(n):
print(arr[i])
``` | -1 |
|
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,696,045,573 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sat Sep 30 11:31:03 2023
@author: 20311
"""
order=list(map(str,input().split('+')))
order.sort()
print('+'.join(order)) | 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
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 30 11:31:03 2023
@author: 20311
"""
order=list(map(str,input().split('+')))
order.sort()
print('+'.join(order))
``` | 3 |
|
1,004 | B | Sonya and Exhibition | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily.
She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$.
The total beauty is equal to $2+2+4=8$.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
- in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$.
The total beauty is equal to $1+4+2=7$. | 1,000 | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "6 2\n1 6\n1 4",
"output": "010101"
},
{
"input": "2 1\n1 2",
"output": "01"
}
] | 1,530,809,534 | 1,034 | Python 3 | OK | TESTS | 27 | 124 | 0 | n, d = map(int, input().split())
print(''.join(str(i % 2) for i in range(n)))
| Title: Sonya and Exhibition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily.
She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input Specification:
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
Output Specification:
Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Demo Input:
['5 3\n1 3\n2 4\n2 5\n', '6 3\n5 6\n1 4\n4 6\n']
Demo Output:
['01100', '110010']
Note:
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$.
The total beauty is equal to $2+2+4=8$.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
- in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$.
The total beauty is equal to $1+4+2=7$. | ```python
n, d = map(int, input().split())
print(''.join(str(i % 2) for i in range(n)))
``` | 3 |
|
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR",
"output": "67"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU",
"output": "99"
},
{
"input": "3\nRUR",
"output": "2"
},
{
"input": "1\nR",
"output": "1"
},
{
"input": "5\nRURUU",
"output": "3"
},
{
"input": "1\nU",
"output": "1"
},
{
"input": "2\nUR",
"output": "1"
},
{
"input": "23\nUUUUUUUUUUUUUUUUUUUUUUU",
"output": "23"
}
] | 1,637,685,530 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n=int(input())
a=input()
k=0
while (i<n-1):
if a[i]!=a[i+1]:
k=k+1
i=i+2
else :
i=i+1
print (n-k) | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Output Specification:
Print the minimum possible length of the sequence of moves after all replacements are done.
Demo Input:
['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n']
Demo Output:
['3\n', '13\n']
Note:
In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | ```python
n=int(input())
a=input()
k=0
while (i<n-1):
if a[i]!=a[i+1]:
k=k+1
i=i+2
else :
i=i+1
print (n-k)
``` | -1 |
|
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
"input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746",
"output": "245"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "3\n607\n684",
"output": "5"
},
{
"input": "4\n0809\n0636",
"output": "8"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762280548\n9519431339078678836940020",
"output": "72"
},
{
"input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024",
"output": "305"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762285484\n9519431339078678836940202",
"output": "74"
},
{
"input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831",
"output": "357"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8378525987476228048406972\n9194339078883694020217816",
"output": "55"
},
{
"input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599",
"output": "274"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "1\n7\n7",
"output": "0"
},
{
"input": "1\n0\n5",
"output": "5"
},
{
"input": "1\n2\n7",
"output": "5"
},
{
"input": "1\n7\n9",
"output": "2"
},
{
"input": "1\n9\n7",
"output": "2"
},
{
"input": "1\n2\n9",
"output": "3"
},
{
"input": "1\n9\n2",
"output": "3"
},
{
"input": "25\n3164978461316464614169874\n9413979197249127496597357",
"output": "66"
},
{
"input": "4\n9999\n9999",
"output": "0"
},
{
"input": "2\n11\n11",
"output": "0"
}
] | 1,650,081,732 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | def get_least_moves(num1, num2):
if num1 > num2:
num1, num2 = num2, num1
if abs(num1 - num2) < 6:
return abs(num1 - num2)
else:
return (10 - num2) + num1
def main():
disks = int(input())
original = input()
combination = input()
min_moves = 0
for i in range(disks):
min_moves += get_least_moves(int(original[i]), int(combination[i]))
print(min_moves)
if __name__ == "__main__":
main()
| Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
def get_least_moves(num1, num2):
if num1 > num2:
num1, num2 = num2, num1
if abs(num1 - num2) < 6:
return abs(num1 - num2)
else:
return (10 - num2) + num1
def main():
disks = int(input())
original = input()
combination = input()
min_moves = 0
for i in range(disks):
min_moves += get_least_moves(int(original[i]), int(combination[i]))
print(min_moves)
if __name__ == "__main__":
main()
``` | 3 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,653,863,626 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 92 | 0 | num=int(input())+1
total=sum(list(map(int,input().split())))
count=0
for i in range(total+1,total+6):
if i%num==1:
count+=1
print(5-count) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
num=int(input())+1
total=sum(list(map(int,input().split())))
count=0
for i in range(total+1,total+6):
if i%num==1:
count+=1
print(5-count)
``` | 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,668,899,698 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 13,721,600 | from copy import copy
def solve():
n = int(input())
sizes = [int(input()) for i in range(n)]
sizes.sort()
right = n - 1
left = n // 2 - 1
merges = 0
while True:
if left < 0 or right < n // 2 - 1:
break
if sizes[left] * 2 <= sizes[right]:
merges += 1
left -= 1
right -= 1
else:
left -= 1
print(n - merges)
solve() | 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
from copy import copy
def solve():
n = int(input())
sizes = [int(input()) for i in range(n)]
sizes.sort()
right = n - 1
left = n // 2 - 1
merges = 0
while True:
if left < 0 or right < n // 2 - 1:
break
if sizes[left] * 2 <= sizes[right]:
merges += 1
left -= 1
right -= 1
else:
left -= 1
print(n - merges)
solve()
``` | 0 |
|
712 | B | Memory and Trident | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. | The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | [
"RRU\n",
"UDUR\n",
"RUUR\n"
] | [
"-1\n",
"1\n",
"2\n"
] | In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin. | 1,000 | [
{
"input": "RRU",
"output": "-1"
},
{
"input": "UDUR",
"output": "1"
},
{
"input": "RUUR",
"output": "2"
},
{
"input": "DDDD",
"output": "2"
},
{
"input": "RRRR",
"output": "2"
},
{
"input": "RRRUUD",
"output": "2"
},
{
"input": "UDURLRDURLRD",
"output": "1"
},
{
"input": "RLRU",
"output": "1"
},
{
"input": "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDULRURRDDDLLUDRLUDDLDDDRRDDDULLLLDLDRLRRLRRDDRLULURRUDRDUUUULDURUDRDLDDUDUDRRURDULRRUDRLRRDLUURURDLDRLRDUDDDLDDDURURLUULRDUUULRURUDUDRRUDULLLUUUDRLLDRRDDLRUDRDRDLLRURURRRULURURRRLUUULRRRUURUUDURUDDLLDLDRLRDLDRLLDLDRDRRLRRRURUUUDRDLRLRUDRLULUUULUDDLULDLRLLRDUULLRLRURLRURULLLUDUDDLRULRDUURURLDLUURRRDURRLLDRUUDRDLLDUUDLURUDDUUUULRLLURLUDDRLRRDRURLRUDRLDDRLLL",
"output": "-1"
},
{
"input": "LDLDLDLDLDRULD",
"output": "5"
},
{
"input": "LULULURULLLU",
"output": "5"
},
{
"input": "DRDRDDRR",
"output": "4"
},
{
"input": "LR",
"output": "0"
},
{
"input": "UL",
"output": "1"
},
{
"input": "UD",
"output": "0"
},
{
"input": "R",
"output": "-1"
},
{
"input": "LU",
"output": "1"
},
{
"input": "RR",
"output": "1"
},
{
"input": "UDLR",
"output": "0"
},
{
"input": "RRRRRLLUUUUDD",
"output": "-1"
},
{
"input": "UUUUDLLLLR",
"output": "3"
},
{
"input": "LLRUD",
"output": "-1"
},
{
"input": "LLRDDU",
"output": "1"
}
] | 1,473,527,350 | 1,450 | Python 3 | OK | TESTS | 75 | 77 | 307,200 | s = input()
countr = 0
countu = 0
for i in s:
if i == 'U':
countu += 1
elif i == 'D':
countu -= 1
elif i == 'R':
countr += 1
else:
countr -= 1
if (countr + countu) % 2 == 1:
print(-1)
else:
print((abs(countr) + abs(countu)) // 2) | Title: Memory and Trident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
Input Specification:
The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given.
Output Specification:
If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
Demo Input:
['RRU\n', 'UDUR\n', 'RUUR\n']
Demo Output:
['-1\n', '1\n', '2\n']
Note:
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin. | ```python
s = input()
countr = 0
countu = 0
for i in s:
if i == 'U':
countu += 1
elif i == 'D':
countu -= 1
elif i == 'R':
countr += 1
else:
countr -= 1
if (countr + countu) % 2 == 1:
print(-1)
else:
print((abs(countr) + abs(countu)) // 2)
``` | 3 |
|
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,487,498,287 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 4,608,000 | import math
if __name__ == '__main__':
n, m, z = str(input()).split()
n = int(n)
m = int(m)
z = int(z)
print((z * math.gcd(n, m)) // (n * m))
| Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
import math
if __name__ == '__main__':
n, m, z = str(input()).split()
n = int(n)
m = int(m)
z = int(z)
print((z * math.gcd(n, m)) // (n * m))
``` | 3 |
|
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,634,476,088 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m=input().split()
m=list(map(int,m))
p=m[0]*m[1]
d=p//2
print(d)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m=input().split()
m=list(map(int,m))
p=m[0]*m[1]
d=p//2
print(d)
``` | 3.969 |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total. | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
"output": "16032999235141416"
},
{
"input": "777888456\n1\n98\n43",
"output": "76233068590"
},
{
"input": "1162261467\n3\n1\n2000000000",
"output": "1162261466"
},
{
"input": "1000000000\n1999999999\n789987\n184569875",
"output": "789986999210013"
},
{
"input": "2000000000\n2\n1\n2000000000",
"output": "1999999999"
},
{
"input": "1999888325\n3\n2\n2000000000",
"output": "3333258884"
},
{
"input": "1897546487\n687\n89798979\n879876541",
"output": "110398404423"
},
{
"input": "20\n1\n20\n1",
"output": "380"
},
{
"input": "16\n5\n17\n3",
"output": "54"
},
{
"input": "19\n19\n19\n1",
"output": "1"
},
{
"input": "18\n2\n3\n16",
"output": "40"
},
{
"input": "1\n11\n8\n9",
"output": "0"
},
{
"input": "9\n10\n1\n20",
"output": "8"
},
{
"input": "19\n10\n19\n2",
"output": "173"
},
{
"input": "16\n9\n14\n2",
"output": "100"
},
{
"input": "15\n2\n5\n2",
"output": "21"
},
{
"input": "14\n7\n13\n1",
"output": "14"
},
{
"input": "43\n3\n45\n3",
"output": "189"
},
{
"input": "99\n1\n98\n1",
"output": "9604"
},
{
"input": "77\n93\n100\n77",
"output": "7600"
},
{
"input": "81\n3\n91\n95",
"output": "380"
},
{
"input": "78\n53\n87\n34",
"output": "2209"
},
{
"input": "80\n3\n15\n1",
"output": "108"
},
{
"input": "97\n24\n4\n24",
"output": "40"
},
{
"input": "100\n100\n1\n100",
"output": "99"
},
{
"input": "87\n4\n17\n7",
"output": "106"
},
{
"input": "65\n2\n3\n6",
"output": "36"
},
{
"input": "1000000\n1435\n3\n999999",
"output": "1005804"
},
{
"input": "783464\n483464\n2\n966928",
"output": "1566926"
},
{
"input": "248035\n11\n3\n20",
"output": "202"
},
{
"input": "524287\n2\n945658\n999756",
"output": "34963354"
},
{
"input": "947352\n78946\n85\n789654",
"output": "790589"
},
{
"input": "1000000\n1\n999899\n60",
"output": "999898000101"
},
{
"input": "753687\n977456\n6547\n456",
"output": "4934382242"
},
{
"input": "1000000\n500000\n1\n999997",
"output": "999998"
},
{
"input": "997458\n843596\n1\n843596",
"output": "997457"
},
{
"input": "821109\n92\n6547\n98787",
"output": "394566"
},
{
"input": "1073741823\n2\n9543\n8923453",
"output": "188412866"
},
{
"input": "1000999777\n1934999345\n2356346\n34534565",
"output": "2358701818178496"
},
{
"input": "2000000000\n1\n2000000000\n98",
"output": "3999999998000000000"
},
{
"input": "1999324353\n978435356\n1\n978435356",
"output": "1020888998"
},
{
"input": "2000000000\n2\n2000000000\n2000000000",
"output": "84000000000"
},
{
"input": "241375690\n17\n2\n1998789654",
"output": "482751378"
},
{
"input": "171507000\n350\n789\n6548687",
"output": "14216965"
},
{
"input": "1100220011\n10001\n2\n1999778654",
"output": "1999998674"
},
{
"input": "1867622656\n43216\n789644\n12315468",
"output": "24630936"
},
{
"input": "1867622656\n43216\n1\n1879865413",
"output": "1867622655"
},
{
"input": "1999999999\n1000000000\n789987\n184569875",
"output": "789987183779888"
},
{
"input": "1987987897\n103546\n7\n98754563",
"output": "98946650"
},
{
"input": "10\n2\n2\n5",
"output": "13"
},
{
"input": "7\n2\n1\n100000",
"output": "6"
},
{
"input": "7\n2\n3\n1",
"output": "8"
},
{
"input": "2000000000\n666666667\n1\n1",
"output": "666666668"
},
{
"input": "1999999997\n666666666\n2\n2",
"output": "1333333334"
}
] | 1,519,478,659 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,632,000 | n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
while n > 1:
if n % k == 0:
if B <= (n - n / k) * A:
cost += B
n //= k
else:
cost += (n - n / k) * A
n //= k
else:
if n > k:
cost += (n % k) * A
n -= n % k
else:
cost += (n - 1) * A
n = 1
print(cost)
| Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output Specification:
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
Demo Input:
['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n']
Demo Output:
['6\n', '8\n', '12\n']
Note:
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total. | ```python
n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
while n > 1:
if n % k == 0:
if B <= (n - n / k) * A:
cost += B
n //= k
else:
cost += (n - n / k) * A
n //= k
else:
if n > k:
cost += (n % k) * A
n -= n % k
else:
cost += (n - 1) * A
n = 1
print(cost)
``` | 0 |
|
734 | B | Anton and Digits | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than *k*2 digits 2, *k*3 digits 3 and so on. Of course, unused digits are not counted in the sum. | The only line of the input contains four integers *k*2, *k*3, *k*5 and *k*6 — the number of digits 2, 3, 5 and 6 respectively (0<=≤<=*k*2,<=*k*3,<=*k*5,<=*k*6<=≤<=5·106). | Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box. | [
"5 1 3 4\n",
"1 1 1 1\n"
] | [
"800\n",
"256\n"
] | In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | 750 | [
{
"input": "5 1 3 4",
"output": "800"
},
{
"input": "1 1 1 1",
"output": "256"
},
{
"input": "10 2 1 5",
"output": "320"
},
{
"input": "4 2 7 2",
"output": "576"
},
{
"input": "489 292 127 263",
"output": "41856"
},
{
"input": "9557 5242 1190 7734",
"output": "472384"
},
{
"input": "1480320 1969946 1158387 3940412",
"output": "306848928"
},
{
"input": "0 0 0 0",
"output": "0"
},
{
"input": "5000000 5000000 5000000 5000000",
"output": "1280000000"
},
{
"input": "1048576 256 1048576 1048576",
"output": "268435456"
},
{
"input": "2073144 2073145 0 0",
"output": "66340608"
},
{
"input": "1000000 0 0 1",
"output": "0"
},
{
"input": "2 1 1 1",
"output": "288"
},
{
"input": "0 5000000 5000000 5000000",
"output": "0"
},
{
"input": "4494839 1140434 3336818 4921605",
"output": "890719296"
},
{
"input": "2363223 3835613 926184 3190201",
"output": "283088352"
},
{
"input": "198044 2268164 2811743 1458798",
"output": "50699264"
},
{
"input": "5 5 1 0",
"output": "160"
},
{
"input": "1 1 1 4",
"output": "256"
},
{
"input": "3 3 4 4",
"output": "768"
},
{
"input": "1 2 0 5",
"output": "32"
},
{
"input": "1207814 1649617 2347252 3136345",
"output": "309200384"
},
{
"input": "78025 2308643 78025 4943733",
"output": "19974400"
},
{
"input": "3046068 2548438 2676145 4789979",
"output": "696930656"
},
{
"input": "4755258 2724358 2030900 4801065",
"output": "607089856"
},
{
"input": "1359689 3792971 4451626 4497236",
"output": "348080384"
},
{
"input": "3484483 3995744 87159 4941393",
"output": "131027072"
},
{
"input": "1273630 1273630 980163 1711706",
"output": "260312672"
},
{
"input": "2010798 1111442 4014004 4430228",
"output": "514764288"
},
{
"input": "1714940 133067 3346537 3346537",
"output": "439024640"
},
{
"input": "3731658 4548347 3731658 3731658",
"output": "955304448"
},
{
"input": "601597 2632066 450558 450558",
"output": "120176096"
},
{
"input": "726573 158002 568571 568571",
"output": "150610240"
},
{
"input": "407729 4510137 3425929 3425929",
"output": "104378624"
},
{
"input": "1781608 3826276 4384744 4384744",
"output": "456091648"
},
{
"input": "4486284 4486284 3249460 3249460",
"output": "871440128"
},
{
"input": "4759823 3520376 4743363 4743363",
"output": "1214827648"
},
{
"input": "386719 4643763 2749163 1701105",
"output": "99000064"
},
{
"input": "3173901 1042250 4102237 3173901",
"output": "812518656"
},
{
"input": "2681845 4558270 4388852 13014",
"output": "88734176"
},
{
"input": "1152975 910150 2776412 242825",
"output": "91288000"
},
{
"input": "2005366 3807065 4174270 2471686",
"output": "513373696"
},
{
"input": "2092196 2406694 3664886 85601",
"output": "86124896"
},
{
"input": "4542228 4542228 3992410 1039690",
"output": "378241856"
},
{
"input": "3093105 2256347 675644 570209",
"output": "218176608"
},
{
"input": "0 1 1 1",
"output": "0"
},
{
"input": "10 20 10 20",
"output": "2560"
},
{
"input": "0 0 5 1",
"output": "0"
},
{
"input": "10 0 10 11",
"output": "2560"
},
{
"input": "2 1 32768 65536",
"output": "512"
},
{
"input": "2 3 5 6",
"output": "512"
},
{
"input": "5 3 2 2",
"output": "608"
},
{
"input": "1 0 2 3",
"output": "256"
},
{
"input": "1 0 1 1",
"output": "256"
},
{
"input": "2 0 3 3",
"output": "512"
},
{
"input": "2 2 2 0",
"output": "64"
},
{
"input": "0 0 1 1",
"output": "0"
},
{
"input": "1 0 2 2",
"output": "256"
},
{
"input": "4 3 4 4",
"output": "1024"
},
{
"input": "5 1 5 6100",
"output": "1280"
}
] | 1,700,102,665 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 46 | 0 | a,b,c,d = map(int,input().split())
dic = {2:a,3:b,5:c,6:d}
k = min([a,c,d])
res = 0
res += k*256
dic[2] -= k
dic[5] -= k
dic[6] -= k
if dic[2] > 0 and dic[3] > 0:
k = min([dic[2],dic[3]])
res += 32 *k
print(res) | Title: Anton and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than *k*2 digits 2, *k*3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input Specification:
The only line of the input contains four integers *k*2, *k*3, *k*5 and *k*6 — the number of digits 2, 3, 5 and 6 respectively (0<=≤<=*k*2,<=*k*3,<=*k*5,<=*k*6<=≤<=5·106).
Output Specification:
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Demo Input:
['5 1 3 4\n', '1 1 1 1\n']
Demo Output:
['800\n', '256\n']
Note:
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | ```python
a,b,c,d = map(int,input().split())
dic = {2:a,3:b,5:c,6:d}
k = min([a,c,d])
res = 0
res += k*256
dic[2] -= k
dic[5] -= k
dic[6] -= k
if dic[2] > 0 and dic[3] > 0:
k = min([dic[2],dic[3]])
res += 32 *k
print(res)
``` | 3 |
|
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=><=*a**i*. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"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": "95"
},
{
"input": "1\n995",
"output": "0"
},
{
"input": "10\n103 101 103 103 101 102 100 100 101 104",
"output": "7"
},
{
"input": "20\n102 100 102 104 102 101 104 103 100 103 105 105 100 105 100 100 101 105 105 102",
"output": "15"
},
{
"input": "20\n990 994 996 999 997 994 990 992 990 993 992 990 999 999 992 994 997 990 993 998",
"output": "15"
},
{
"input": "100\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9",
"output": "84"
}
] | 1,677,272,361 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n = int(input())
l = list(map(int,input().split()))
c = 0
if n == len(set(l)):
print(n-1)
else :
l.sort()
if n % 2 != 0 :
l1 = l[:n//2]
l2 = l[n//2+1:]
else :
l1 = l[:n//2]
l2 = l[n//2:]
if n % 2 != 0 :
e = l[n//2]
if e > l1[0] and e < l2[n]:
c+=1
for i in range(len(l1)):
if l1[i]<l2[i]:
c+=1
print(c)
# else :
# minn = n - len(set(lista))
# print(n-minn-1) | Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=><=*a**i*.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting.
Output Specification:
Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement.
Demo Input:
['5\n20 30 10 50 40\n', '4\n200 100 100 200\n']
Demo Output:
['4\n', '2\n']
Note:
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | ```python
n = int(input())
l = list(map(int,input().split()))
c = 0
if n == len(set(l)):
print(n-1)
else :
l.sort()
if n % 2 != 0 :
l1 = l[:n//2]
l2 = l[n//2+1:]
else :
l1 = l[:n//2]
l2 = l[n//2:]
if n % 2 != 0 :
e = l[n//2]
if e > l1[0] and e < l2[n]:
c+=1
for i in range(len(l1)):
if l1[i]<l2[i]:
c+=1
print(c)
# else :
# minn = n - len(set(lista))
# print(n-minn-1)
``` | 0 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,693,201,023 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | str = input()
res = 0
arr = str[1:-1].split(', ')
let = [0 for i in range(26)]
for c in arr:
if(c!= ''):
let[ord(c)-ord('a')] = 1
for el in let:
if(el==1): res += 1
print(res) | 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
str = input()
res = 0
arr = str[1:-1].split(', ')
let = [0 for i in range(26)]
for c in arr:
if(c!= ''):
let[ord(c)-ord('a')] = 1
for el in let:
if(el==1): res += 1
print(res)
``` | 3 |
|
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc",
"output": "abaabaabaacaabaacacacaaaabbacbaacbbbbcabcabbcccaabcc"
},
{
"input": "13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymt\nbvwzpuut\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymth\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdl\nrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypud\nqlvkfkshkxyrfefigtngifxsuhpjgkb\nlhxtkfjrrwcvzuamizotupjqckaq\nenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjz\nxkazwk",
"output": "bvwzpuutclgknjjojyuvdtvclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymthclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdlclgknjjojyuvdtvzxzclgknjjojyuvdtvzxzxradqhmenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjzgvzpnckalbaubfviyhijosiixvxaydxagvymqlhxtkfjrrwcvzuamizotupjqckaqqlvkfkshkxyrfefigtngifxsuhpjgkbrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypudxkazwk"
}
] | 1,637,643,202 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n = int(input().strip())
inp = []
for i in range(n):
s = input().strip()
inp.append((len(s), s+'z'*(50-len(s))))
inp.sort(key=lambda x: x[1])
print(''.join([e[:l] for l, e in inp]))
| Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation.
Input Specification:
The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.
Output Specification:
Print the only string *a* — the lexicographically smallest string concatenation.
Demo Input:
['4\nabba\nabacaba\nbcd\ner\n', '5\nx\nxx\nxxa\nxxaa\nxxaaa\n', '3\nc\ncb\ncba\n']
Demo Output:
['abacabaabbabcder\n', 'xxaaaxxaaxxaxxx\n', 'cbacbc\n']
Note:
none | ```python
n = int(input().strip())
inp = []
for i in range(n):
s = input().strip()
inp.append((len(s), s+'z'*(50-len(s))))
inp.sort(key=lambda x: x[1])
print(''.join([e[:l] for l, e in inp]))
``` | 0 |
|
784 | E | Twisted Circuit | PROGRAMMING | 2,000 | [
"*special",
"brute force",
"implementation"
] | null | null | The input consists of four lines, each line containing a single digit 0 or 1. | Output a single digit, 0 or 1. | [
"0\n1\n1\n0\n"
] | [
"0\n"
] | none | 0 | [
{
"input": "0\n1\n1\n0",
"output": "0"
},
{
"input": "0\n0\n0\n0",
"output": "0"
},
{
"input": "1\n0\n0\n0",
"output": "1"
},
{
"input": "0\n1\n0\n0",
"output": "0"
},
{
"input": "1\n1\n0\n0",
"output": "1"
},
{
"input": "0\n0\n1\n0",
"output": "0"
},
{
"input": "1\n0\n1\n0",
"output": "0"
},
{
"input": "1\n1\n1\n0",
"output": "1"
},
{
"input": "0\n0\n0\n1",
"output": "1"
},
{
"input": "1\n0\n0\n1",
"output": "1"
},
{
"input": "0\n1\n0\n1",
"output": "0"
},
{
"input": "1\n1\n0\n1",
"output": "0"
},
{
"input": "0\n0\n1\n1",
"output": "1"
},
{
"input": "1\n0\n1\n1",
"output": "1"
},
{
"input": "0\n1\n1\n1",
"output": "0"
},
{
"input": "1\n1\n1\n1",
"output": "1"
}
] | 1,492,422,893 | 1,493 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | a = bool(input())
b = bool(input())
c = bool(input())
d = bool(input())
a, b, c, d = a or b, not(c or d), b and c, a or d
a, b = a and b, not(c or d)
a = a or b
print(1 if a else 0)
| Title: Twisted Circuit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input consists of four lines, each line containing a single digit 0 or 1.
Output Specification:
Output a single digit, 0 or 1.
Demo Input:
['0\n1\n1\n0\n']
Demo Output:
['0\n']
Note:
none | ```python
a = bool(input())
b = bool(input())
c = bool(input())
d = bool(input())
a, b, c, d = a or b, not(c or d), b and c, a or d
a, b = a and b, not(c or d)
a = a or b
print(1 if a else 0)
``` | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.