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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
802 | J | Send the Fool Further! (easy) | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on.
Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank?
Heidi's *n* friends are labeled 0 through *n*<=-<=1, and their network of connections forms a tree. In other words, every two of her friends *a*, *b* know each other, possibly indirectly (there is a sequence of friends starting from *a* and ending on *b* and such that each two consecutive friends in the sequence know each other directly), and there are exactly *n*<=-<=1 pairs of friends who know each other directly.
Jenny is given the number 0. | The first line of the input contains the number of friends *n* (3<=≤<=*n*<=≤<=100). The next *n*<=-<=1 lines each contain three space-separated integers *u*, *v* and *c* (0<=≤<=*u*,<=*v*<=≤<=*n*<=-<=1, 1<=≤<=*c*<=≤<=104), meaning that *u* and *v* are friends (know each other directly) and the cost for travelling between *u* and *v* is *c*.
It is guaranteed that the social network of the input forms a tree. | Output a single integer – the maximum sum of costs. | [
"4\n0 1 4\n0 2 2\n2 3 3\n",
"6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n",
"11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n"
] | [
"5\n",
"105\n",
"5551\n"
] | In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). | 0 | [
{
"input": "4\n0 1 4\n0 2 2\n2 3 3",
"output": "5"
},
{
"input": "3\n1 0 5987\n2 0 8891",
"output": "8891"
},
{
"input": "10\n1 0 518\n2 0 4071\n3 1 121\n4 2 3967\n5 3 9138\n6 2 9513\n7 3 3499\n8 2 2337\n9 4 7647",
"output": "15685"
},
{
"input": "11\n1 0 6646\n2 0 8816\n3 2 9375\n4 2 5950\n5 1 8702\n6 2 2657\n7 2 885\n8 7 2660\n9 2 5369\n10 6 3798",
"output": "18191"
},
{
"input": "10\n0 1 7171\n0 2 2280\n1 3 9126\n2 4 2598\n5 4 8320\n6 2 1855\n3 7 9204\n7 8 2145\n4 9 10",
"output": "27646"
},
{
"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10",
"output": "105"
},
{
"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378",
"output": "5551"
}
] | 1,621,613,395 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | import sys
n=int(input())
graph = [[] for _ in range(n)]
for i in range(n - 1):
inf = list(map(int, input().split()))
v1 = inf[0]
v2 = inf[1]
c=inf[2]
graph[v1].append([v2,c])
graph[v2].append([v1,c])
curr = [0,0]
stk = []
nvis = [True] * n
ans = 0
lea=[False]*n
k=0
lc=[0]*n
for i in range(n):
if(len(graph[i])==1):
lea[i]=True
k+=1
lc[i]=graph[i][0][1]
while(True):
nxt = -1
temp=len(graph[curr[0]])
for i in range(temp-1,-1,-1):
if (nvis[graph[curr[0]][i][0]]):
nxt = graph[curr[0]][i][0]
break
else:
graph[curr[0]].pop()
if(nxt != -1):
if(stk==[]):cost=0
else: cost=stk[-1][1]+curr[1]
stk.append([curr[0],cost])
nvis[curr[0]] = False
curr = [nxt,graph[curr[0]][i][1]]
else:
if(curr[0]==0):
print(max(lc))
sys.exit()
break
cost=stk[-1][1]
if(lea[curr[0]]):
lc[curr[0]]+=cost
nvis[curr[0]] = False
curr = stk[-1]
stk.pop() | Title: Send the Fool Further! (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on.
Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank?
Heidi's *n* friends are labeled 0 through *n*<=-<=1, and their network of connections forms a tree. In other words, every two of her friends *a*, *b* know each other, possibly indirectly (there is a sequence of friends starting from *a* and ending on *b* and such that each two consecutive friends in the sequence know each other directly), and there are exactly *n*<=-<=1 pairs of friends who know each other directly.
Jenny is given the number 0.
Input Specification:
The first line of the input contains the number of friends *n* (3<=≤<=*n*<=≤<=100). The next *n*<=-<=1 lines each contain three space-separated integers *u*, *v* and *c* (0<=≤<=*u*,<=*v*<=≤<=*n*<=-<=1, 1<=≤<=*c*<=≤<=104), meaning that *u* and *v* are friends (know each other directly) and the cost for travelling between *u* and *v* is *c*.
It is guaranteed that the social network of the input forms a tree.
Output Specification:
Output a single integer – the maximum sum of costs.
Demo Input:
['4\n0 1 4\n0 2 2\n2 3 3\n', '6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n', '11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n']
Demo Output:
['5\n', '105\n', '5551\n']
Note:
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). | ```python
import sys
n=int(input())
graph = [[] for _ in range(n)]
for i in range(n - 1):
inf = list(map(int, input().split()))
v1 = inf[0]
v2 = inf[1]
c=inf[2]
graph[v1].append([v2,c])
graph[v2].append([v1,c])
curr = [0,0]
stk = []
nvis = [True] * n
ans = 0
lea=[False]*n
k=0
lc=[0]*n
for i in range(n):
if(len(graph[i])==1):
lea[i]=True
k+=1
lc[i]=graph[i][0][1]
while(True):
nxt = -1
temp=len(graph[curr[0]])
for i in range(temp-1,-1,-1):
if (nvis[graph[curr[0]][i][0]]):
nxt = graph[curr[0]][i][0]
break
else:
graph[curr[0]].pop()
if(nxt != -1):
if(stk==[]):cost=0
else: cost=stk[-1][1]+curr[1]
stk.append([curr[0],cost])
nvis[curr[0]] = False
curr = [nxt,graph[curr[0]][i][1]]
else:
if(curr[0]==0):
print(max(lc))
sys.exit()
break
cost=stk[-1][1]
if(lea[curr[0]]):
lc[curr[0]]+=cost
nvis[curr[0]] = False
curr = stk[-1]
stk.pop()
``` | 0 |
|
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch. | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integer — the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d",
"output": "3999999999999999994"
},
{
"input": "999999999999999997a",
"output": "3999999999999999988"
},
{
"input": "1c",
"output": "6"
},
{
"input": "1d",
"output": "3"
},
{
"input": "1e",
"output": "2"
},
{
"input": "1a",
"output": "4"
},
{
"input": "2a",
"output": "11"
},
{
"input": "2b",
"output": "12"
},
{
"input": "2e",
"output": "9"
},
{
"input": "2f",
"output": "8"
},
{
"input": "3a",
"output": "4"
},
{
"input": "3b",
"output": "5"
},
{
"input": "3c",
"output": "6"
},
{
"input": "3d",
"output": "3"
},
{
"input": "3e",
"output": "2"
},
{
"input": "3f",
"output": "1"
},
{
"input": "4b",
"output": "12"
},
{
"input": "4c",
"output": "13"
},
{
"input": "4d",
"output": "10"
},
{
"input": "4e",
"output": "9"
},
{
"input": "4f",
"output": "8"
},
{
"input": "999999997a",
"output": "3999999988"
},
{
"input": "999999997b",
"output": "3999999989"
},
{
"input": "999999997c",
"output": "3999999990"
},
{
"input": "999999997d",
"output": "3999999987"
},
{
"input": "999999997e",
"output": "3999999986"
},
{
"input": "999999997f",
"output": "3999999985"
},
{
"input": "999999998a",
"output": "3999999995"
},
{
"input": "999999998b",
"output": "3999999996"
},
{
"input": "999999998c",
"output": "3999999997"
},
{
"input": "999999998d",
"output": "3999999994"
},
{
"input": "999999998e",
"output": "3999999993"
},
{
"input": "999999998f",
"output": "3999999992"
},
{
"input": "999999999a",
"output": "3999999988"
},
{
"input": "999999999b",
"output": "3999999989"
},
{
"input": "999999999c",
"output": "3999999990"
},
{
"input": "999999999d",
"output": "3999999987"
},
{
"input": "999999999e",
"output": "3999999986"
},
{
"input": "999999999f",
"output": "3999999985"
},
{
"input": "1000000000a",
"output": "3999999995"
},
{
"input": "1000000000b",
"output": "3999999996"
},
{
"input": "1000000000c",
"output": "3999999997"
},
{
"input": "1000000000d",
"output": "3999999994"
},
{
"input": "1000000000e",
"output": "3999999993"
},
{
"input": "1000000000f",
"output": "3999999992"
},
{
"input": "100000b",
"output": "399996"
},
{
"input": "100000f",
"output": "399992"
},
{
"input": "100001d",
"output": "400003"
},
{
"input": "100001e",
"output": "400002"
},
{
"input": "100001f",
"output": "400001"
},
{
"input": "100002a",
"output": "400011"
},
{
"input": "100002b",
"output": "400012"
},
{
"input": "100002d",
"output": "400010"
},
{
"input": "1231273a",
"output": "4925092"
},
{
"input": "82784f",
"output": "331128"
},
{
"input": "88312c",
"output": "353245"
},
{
"input": "891237e",
"output": "3564946"
},
{
"input": "999999999999999997b",
"output": "3999999999999999989"
},
{
"input": "999999999999999997c",
"output": "3999999999999999990"
},
{
"input": "999999999999999997d",
"output": "3999999999999999987"
},
{
"input": "999999999999999997e",
"output": "3999999999999999986"
},
{
"input": "999999999999999997f",
"output": "3999999999999999985"
},
{
"input": "999999999999999998a",
"output": "3999999999999999995"
},
{
"input": "999999999999999998b",
"output": "3999999999999999996"
},
{
"input": "999999999999999998c",
"output": "3999999999999999997"
},
{
"input": "999999999999999998d",
"output": "3999999999999999994"
},
{
"input": "999999999999999998e",
"output": "3999999999999999993"
},
{
"input": "999999999999999998f",
"output": "3999999999999999992"
},
{
"input": "999999999999999999a",
"output": "3999999999999999988"
},
{
"input": "999999999999999999b",
"output": "3999999999999999989"
},
{
"input": "999999999999999999c",
"output": "3999999999999999990"
},
{
"input": "999999999999999999d",
"output": "3999999999999999987"
},
{
"input": "1000000000000000000a",
"output": "3999999999999999995"
},
{
"input": "1000000000000000000e",
"output": "3999999999999999993"
},
{
"input": "1000000000000000000f",
"output": "3999999999999999992"
},
{
"input": "1000000000000000000c",
"output": "3999999999999999997"
},
{
"input": "97a",
"output": "388"
},
{
"input": "6f",
"output": "24"
},
{
"input": "7f",
"output": "17"
},
{
"input": "7e",
"output": "18"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "7a",
"output": "20"
},
{
"input": "8f",
"output": "24"
},
{
"input": "999999999999999992a",
"output": "3999999999999999963"
},
{
"input": "999999999999999992b",
"output": "3999999999999999964"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "999999999999999992d",
"output": "3999999999999999962"
},
{
"input": "999999999999999992e",
"output": "3999999999999999961"
},
{
"input": "999999999999999992f",
"output": "3999999999999999960"
},
{
"input": "999999999999999993a",
"output": "3999999999999999972"
},
{
"input": "999999999999999993b",
"output": "3999999999999999973"
},
{
"input": "999999999999999993c",
"output": "3999999999999999974"
},
{
"input": "999999999999999993d",
"output": "3999999999999999971"
},
{
"input": "999999999999999993e",
"output": "3999999999999999970"
},
{
"input": "999999999999999993f",
"output": "3999999999999999969"
},
{
"input": "999999999999999994a",
"output": "3999999999999999979"
},
{
"input": "999999999999999994b",
"output": "3999999999999999980"
},
{
"input": "999999999999999994c",
"output": "3999999999999999981"
},
{
"input": "999999999999999994d",
"output": "3999999999999999978"
},
{
"input": "999999999999999994e",
"output": "3999999999999999977"
},
{
"input": "999999999999999994f",
"output": "3999999999999999976"
},
{
"input": "999999999999999995a",
"output": "3999999999999999972"
},
{
"input": "999999999999999995b",
"output": "3999999999999999973"
},
{
"input": "999999999999999995c",
"output": "3999999999999999974"
},
{
"input": "999999999999999995d",
"output": "3999999999999999971"
},
{
"input": "999999999999999995e",
"output": "3999999999999999970"
},
{
"input": "999999999999999995f",
"output": "3999999999999999969"
},
{
"input": "10a",
"output": "43"
},
{
"input": "11f",
"output": "33"
},
{
"input": "681572647b",
"output": "2726290581"
},
{
"input": "23f",
"output": "81"
},
{
"input": "123a",
"output": "484"
},
{
"input": "999999888888777777a",
"output": "3999999555555111108"
}
] | 1,477,150,902 | 2,202 | Python 3 | OK | TESTS | 119 | 62 | 0 | ns = input()
trantab = str.maketrans('abcdef', '456321')
n = int(ns[:-1])
s = ns[-1]
m = int(s.translate(trantab))
ans = 0
if n % 4 == 1 or n % 4 == 3:
ans += (n // 4) * 16 + m
elif n % 2 == 2:
ans += (n // 4) * 16 + 7 + m
else:
ans += ((n - 1) // 4) * 16 + 7 + m
print(ans)
| Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch.
Input Specification:
The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
Output Specification:
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
Demo Input:
['1f\n', '2d\n', '4a\n', '5e\n']
Demo Output:
['1\n', '10\n', '11\n', '18\n']
Note:
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | ```python
ns = input()
trantab = str.maketrans('abcdef', '456321')
n = int(ns[:-1])
s = ns[-1]
m = int(s.translate(trantab))
ans = 0
if n % 4 == 1 or n % 4 == 3:
ans += (n // 4) * 16 + m
elif n % 2 == 2:
ans += (n // 4) * 16 + 7 + m
else:
ans += ((n - 1) // 4) * 16 + 7 + m
print(ans)
``` | 3 |
|
706 | A | Beru-taxi | PROGRAMMING | 900 | [
"brute force",
"geometry",
"implementation"
] | null | null | Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at point (*x**i*,<=*y**i*) and moves with a speed *v**i*.
Consider that each of *n* drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. | The first line of the input contains two integers *a* and *b* (<=-<=100<=≤<=*a*,<=*b*<=≤<=100) — coordinates of Vasiliy's home.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of available Beru-taxi cars nearby.
The *i*-th of the following *n* lines contains three integers *x**i*, *y**i* and *v**i* (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100, 1<=≤<=*v**i*<=≤<=100) — the coordinates of the *i*-th car and its speed.
It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. | Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"0 0\n2\n2 0 1\n0 2 2\n",
"1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n"
] | [
"1.00000000000000000000",
"0.50000000000000000000"
] | In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.
In the second sample, cars 2 and 3 will arrive simultaneously. | 500 | [
{
"input": "0 0\n2\n2 0 1\n0 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10",
"output": "0.50000000000000000000"
},
{
"input": "2 2\n10\n8 10 1\n14 18 5\n2 2 1\n4 2 2\n5 2 1\n0 2 1\n2 10 4\n10 2 4\n14 18 20\n14 18 10",
"output": "0.00000000000000000000"
},
{
"input": "-100 100\n3\n100 100 1\n-100 0 5\n-100 -100 20",
"output": "10.00000000000000000000"
},
{
"input": "5 5\n4\n20 5 1\n20 5 3\n20 5 5\n20 5 15",
"output": "1.00000000000000000000"
},
{
"input": "0 0\n6\n12 0 1\n0 12 12\n12 0 6\n12 0 3\n0 12 4\n12 0 2",
"output": "1.00000000000000000000"
},
{
"input": "0 0\n1\n3 4 5",
"output": "1.00000000000000000000"
},
{
"input": "1 0\n3\n1 1 1\n2 0 1\n3 0 2",
"output": "1.00000000000000000000"
},
{
"input": "95 69\n2\n100 -47 34\n43 80 72",
"output": "0.73820457032879509778"
},
{
"input": "-21 -48\n5\n69 4 95\n86 -44 90\n-51 -23 85\n64 -8 21\n-47 41 82",
"output": "0.45942645152392084672"
},
{
"input": "2 2\n2\n1 3 99\n3 3 100",
"output": "0.01414213562373095049"
},
{
"input": "0 0\n2\n0 1 100\n0 0 1",
"output": "0.00000000000000000000"
},
{
"input": "-24 -35\n19\n7 25 34\n-7 12 17\n-40 2 54\n-60 54 38\n68 -49 8\n-43 -25 25\n-84 -44 21\n4 71 43\n96 -60 66\n-77 62 92\n23 -6 79\n44 67 10\n-21 -26 55\n-82 24 10\n92 55 23\n-82 -40 33\n78 -91 3\n-48 -17 26\n-74 87 18",
"output": "0.17248787237282069083"
},
{
"input": "-56 45\n23\n-79 -82 42\n43 -54 73\n-91 65 54\n-79 -25 36\n40 -22 95\n57 67 31\n-12 -32 37\n-25 95 95\n39 6 24\n96 73 1\n45 -20 35\n-59 50 36\n-49 -18 72\n-74 0 12\n-22 -1 50\n-79 68 13\n-7 -63 27\n-35 3 29\n-95 -54 12\n71 92 76\n25 -90 19\n-95 -66 23\n99 -96 76",
"output": "0.16197088596792501308"
},
{
"input": "-88 -12\n29\n60 -57 48\n52 100 14\n-86 -78 95\n59 -67 2\n-62 59 14\n-71 74 68\n5 -63 21\n-72 14 78\n84 30 35\n-41 -78 15\n-38 34 82\n38 40 57\n99 24 97\n-87 -43 7\n74 -84 14\n-92 4 61\n39 27 22\n86 -88 79\n-39 -83 37\n-93 56 25\n-35 -38 34\n-4 9 90\n-82 -69 54\n-85 31 28\n18 54 71\n89 -3 34\n-78 -81 20\n91 34 43\n34 -30 18",
"output": "0.27036758200771544589"
},
{
"input": "-85 71\n31\n-64 -97 57\n7 41 20\n29 41 85\n27 -81 9\n-63 100 59\n-54 72 66\n-13 -33 36\n89 66 64\n77 -46 54\n86 -58 75\n71 -32 56\n78 -91 74\n-37 69 39\n67 -3 76\n-39 -62 56\n49 16 50\n6 -25 23\n-8 96 34\n14 -81 58\n34 -61 53\n0 77 37\n-27 -27 61\n-37 63 54\n86 12 10\n94 -41 53\n-81 24 49\n-32 81 62\n42 -4 77\n24 70 69\n-51 -19 20\n18 -17 61",
"output": "0.46994128543244917054"
},
{
"input": "-16 -86\n37\n-25 28 67\n-9 -81 61\n9 99 25\n65 77 71\n-91 -19 73\n19 54 8\n-96 36 19\n-58 -15 48\n48 -21 77\n24 -8 1\n88 22 7\n50 100 95\n-65 -90 64\n29 -46 75\n-69 -20 16\n36 28 98\n76 65 13\n-12 81 76\n-6 90 87\n47 5 6\n-35 -72 56\n39 -54 41\n82 -10 28\n-72 47 32\n-48 -60 5\n13 0 66\n-61 -49 61\n21 -90 16\n-65 -85 84\n76 31 45\n-75 84 12\n8 -66 27\n10 -17 16\n45 -26 78\n-78 -24 37\n18 26 22\n99 24 66",
"output": "0.14102172568922338971"
},
{
"input": "-27 -63\n39\n-88 87 70\n86 -89 2\n-57 19 40\n77 -62 67\n9 -34 11\n1 48 16\n-7 17 16\n53 -17 2\n96 96 15\n-31 -16 37\n1 73 89\n-94 -13 3\n17 74 44\n8 -10 4\n30 79 94\n-2 -52 78\n-76 70 40\n-5 -84 25\n-4 -54 69\n-41 -6 27\n38 -13 31\n35 55 59\n-28 24 25\n-74 -67 12\n-79 1 55\n-23 -67 36\n-53 34 67\n22 99 67\n-2 65 32\n10 13 82\n37 -24 27\n-96 -69 11\n14 82 96\n-52 70 26\n1 93 77\n-20 80 44\n-80 8 29\n77 -100 95\n83 -15 89",
"output": "0.15713484026367722764"
},
{
"input": "-24 -5\n41\n-11 46 71\n42 -47 16\n-17 -39 26\n45 -1 74\n-92 -93 57\n18 -55 14\n-24 23 32\n13 -91 88\n90 45 27\n21 -98 1\n9 7 59\n-54 83 29\n83 -82 85\n62 31 72\n19 0 47\n64 60 79\n68 -83 41\n25 25 80\n-52 -51 86\n-14 -24 54\n-29 1 30\n-88 44 37\n-83 55 29\n72 -61 94\n-3 81 33\n-93 -16 51\n-8 -5 9\n49 61 5\n88 40 82\n7 -63 1\n-6 -99 82\n20 81 99\n57 90 46\n27 30 77\n-78 -13 79\n-32 -85 4\n82 55 93\n11 -3 45\n39 -66 43\n-37 44 63\n75 -94 2",
"output": "0.26034165586355514647"
},
{
"input": "66 -82\n43\n27 -21 70\n-64 46 58\n-7 -20 41\n-42 60 57\n-93 -7 95\n26 -61 26\n-10 -72 25\n-78 -18 55\n-62 -64 69\n-33 95 50\n24 59 45\n4 72 37\n66 57 61\n16 -60 5\n17 -78 36\n-75 56 59\n-60 98 77\n-94 37 28\n76 6 63\n99 -35 75\n69 -40 1\n9 -48 56\n-94 -11 19\n69 1 63\n43 42 80\n-28 -83 21\n100 -23 6\n50 49 49\n-26 -12 22\n-34 45 46\n-96 -82 100\n-60 78 88\n35 88 26\n31 25 25\n-98 -97 12\n-70 -31 30\n-71 65 56\n32 26 58\n-80 82 30\n64 34 74\n5 15 2\n-72 -9 46\n68 43 84",
"output": "0.76570954748593223420"
},
{
"input": "0 0\n2\n100 100 1\n100 99 1",
"output": "140.71602609511114245766"
},
{
"input": "1 2\n1\n4 6 3",
"output": "1.66666666666666666663"
},
{
"input": "100 100\n1\n-100 -100 1",
"output": "282.84271247461900974929"
},
{
"input": "4 7\n1\n11 34 17",
"output": "1.64074419776251211988"
},
{
"input": "91 91\n3\n3 3 2\n-2 3 6\n-2 7 10",
"output": "12.53195914452325367139"
},
{
"input": "100 100\n3\n3 3 2\n-2 3 6\n-2 7 10",
"output": "13.80326048439280884911"
},
{
"input": "0 0\n1\n1 5 5",
"output": "1.01980390271855696595"
},
{
"input": "3 6\n2\n18 92 45\n32 94 86",
"output": "1.07738691952544205876"
},
{
"input": "-100 -100\n1\n100 100 1",
"output": "282.84271247461900974929"
},
{
"input": "0 0\n1\n0 31 13",
"output": "2.38461538461538461548"
},
{
"input": "0 0\n1\n1 2 2",
"output": "1.11803398874989484821"
},
{
"input": "0 0\n1\n10 0 6",
"output": "1.66666666666666666663"
},
{
"input": "100 100\n1\n-100 -100 100",
"output": "2.82842712474619009753"
},
{
"input": "-100 -100\n1\n100 100 2",
"output": "141.42135623730950487464"
}
] | 1,688,836,924 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 46 | 0 | import math
a,b=input().split()
a=int(a)
b=int(b)
number_of_cars=int(input())
mylist=[]
for i in range(number_of_cars):
e,f,g=input().split()
e=int(e)
f=int(f)
g=int(g)
distance_formula=math.sqrt((e-a)**2+(f-b)**2)
mylist.append(distance_formula/g)
print(min(mylist)) | Title: Beru-taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at point (*x**i*,<=*y**i*) and moves with a speed *v**i*.
Consider that each of *n* drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.
Input Specification:
The first line of the input contains two integers *a* and *b* (<=-<=100<=≤<=*a*,<=*b*<=≤<=100) — coordinates of Vasiliy's home.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of available Beru-taxi cars nearby.
The *i*-th of the following *n* lines contains three integers *x**i*, *y**i* and *v**i* (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100, 1<=≤<=*v**i*<=≤<=100) — the coordinates of the *i*-th car and its speed.
It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives.
Output Specification:
Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['0 0\n2\n2 0 1\n0 2 2\n', '1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n']
Demo Output:
['1.00000000000000000000', '0.50000000000000000000']
Note:
In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.
In the second sample, cars 2 and 3 will arrive simultaneously. | ```python
import math
a,b=input().split()
a=int(a)
b=int(b)
number_of_cars=int(input())
mylist=[]
for i in range(number_of_cars):
e,f,g=input().split()
e=int(e)
f=int(f)
g=int(g)
distance_formula=math.sqrt((e-a)**2+(f-b)**2)
mylist.append(distance_formula/g)
print(min(mylist))
``` | 3 |
|
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output": "423654797"
},
{
"input": "-623563697",
"output": "-62356367"
},
{
"input": "645894116",
"output": "645894116"
},
{
"input": "-384381709",
"output": "-38438170"
},
{
"input": "437587210",
"output": "437587210"
},
{
"input": "-297534606",
"output": "-29753460"
},
{
"input": "891773002",
"output": "891773002"
},
{
"input": "-56712976",
"output": "-5671296"
},
{
"input": "963662765",
"output": "963662765"
},
{
"input": "-272656295",
"output": "-27265625"
},
{
"input": "383441522",
"output": "383441522"
},
{
"input": "-477665112",
"output": "-47766511"
},
{
"input": "791725034",
"output": "791725034"
},
{
"input": "-812168727",
"output": "-81216872"
},
{
"input": "528894922",
"output": "528894922"
},
{
"input": "-479977172",
"output": "-47997712"
},
{
"input": "568044564",
"output": "568044564"
},
{
"input": "-392784794",
"output": "-39278474"
},
{
"input": "925596634",
"output": "925596634"
},
{
"input": "-836078769",
"output": "-83607876"
},
{
"input": "71036059",
"output": "71036059"
},
{
"input": "-337396162",
"output": "-33739612"
},
{
"input": "87129297",
"output": "87129297"
},
{
"input": "-648171877",
"output": "-64817187"
},
{
"input": "20218400",
"output": "20218400"
},
{
"input": "10",
"output": "10"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "-1000000000",
"output": "-100000000"
},
{
"input": "-102",
"output": "-10"
},
{
"input": "-120",
"output": "-10"
},
{
"input": "-20",
"output": "0"
},
{
"input": "-15",
"output": "-1"
},
{
"input": "-5575533",
"output": "-557553"
},
{
"input": "-50",
"output": "0"
},
{
"input": "-31",
"output": "-1"
},
{
"input": "-55",
"output": "-5"
},
{
"input": "-81",
"output": "-1"
},
{
"input": "-99",
"output": "-9"
},
{
"input": "-23",
"output": "-2"
},
{
"input": "-41",
"output": "-1"
},
{
"input": "-24",
"output": "-2"
},
{
"input": "46",
"output": "46"
}
] | 1,693,641,418 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 0 | n = int(input())
b = 0
l = 0
if n >= 0:
print(n)
else:
if n >= -10:
print(0)
else:
b = n // 10
l_str = str(l)
l1_str = l_str[:-2]
result = int(l1_str) - n % 10
if b > result:
print(b)
else:
print(result) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
Input Specification:
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
Output Specification:
In a single line print an integer — the maximum state of the bank account that Ilya can get.
Demo Input:
['2230\n', '-10\n', '-100003\n']
Demo Output:
['2230\n', '0\n', '-10000\n']
Note:
In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | ```python
n = int(input())
b = 0
l = 0
if n >= 0:
print(n)
else:
if n >= -10:
print(0)
else:
b = n // 10
l_str = str(l)
l1_str = l_str[:-2]
result = int(l1_str) - n % 10
if b > result:
print(b)
else:
print(result)
``` | -1 |
|
993 | B | Open Communication | PROGRAMMING | 1,900 | [
"bitmasks",
"brute force"
] | null | null | Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.
Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.
Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 12$) — the number of pairs the first participant communicated to the second and vice versa.
The second line contains $n$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from first participant to the second.
The third line contains $m$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from the second participant to the first.
All pairs within each set are distinct (in particular, if there is a pair $(1,2)$, there will be no pair $(2,1)$ within the same set), and no pair contains the same number twice.
It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. | If you can deduce the shared number with certainty, print that number.
If you can with certainty deduce that both participants know the shared number, but you do not know it, print $0$.
Otherwise print $-1$. | [
"2 2\n1 2 3 4\n1 5 3 4\n",
"2 2\n1 2 3 4\n1 5 6 4\n",
"2 3\n1 2 4 5\n1 2 1 3 2 3\n"
] | [
"1\n",
"0\n",
"-1\n"
] | In the first example the first participant communicated pairs $(1,2)$ and $(3,4)$, and the second communicated $(1,5)$, $(3,4)$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $(3,4)$. Thus, the first participant has $(1,2)$ and the second has $(1,5)$, and at this point you already know the shared number is $1$.
In the second example either the first participant has $(1,2)$ and the second has $(1,5)$, or the first has $(3,4)$ and the second has $(6,4)$. In the first case both of them know the shared number is $1$, in the second case both of them know the shared number is $4$. You don't have enough information to tell $1$ and $4$ apart.
In the third case if the first participant was given $(1,2)$, they don't know what the shared number is, since from their perspective the second participant might have been given either $(1,3)$, in which case the shared number is $1$, or $(2,3)$, in which case the shared number is $2$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $-1$. | 1,000 | [
{
"input": "2 2\n1 2 3 4\n1 5 3 4",
"output": "1"
},
{
"input": "2 2\n1 2 3 4\n1 5 6 4",
"output": "0"
},
{
"input": "2 3\n1 2 4 5\n1 2 1 3 2 3",
"output": "-1"
},
{
"input": "2 1\n1 2 1 3\n1 2",
"output": "1"
},
{
"input": "4 4\n1 2 3 4 5 6 7 8\n2 3 4 5 6 7 8 1",
"output": "-1"
},
{
"input": "3 3\n1 2 5 6 7 8\n2 3 4 5 8 9",
"output": "0"
},
{
"input": "4 3\n1 2 4 5 6 7 8 9\n1 2 8 9 3 1",
"output": "1"
},
{
"input": "3 4\n2 1 8 9 3 1\n1 2 4 5 6 7 8 9",
"output": "1"
},
{
"input": "3 8\n8 9 8 5 9 2\n8 4 8 3 2 6 4 2 4 3 3 7 3 6 1 6",
"output": "0"
},
{
"input": "9 1\n3 4 3 2 3 7 3 5 9 4 1 9 6 4 5 2 7 6\n8 3",
"output": "3"
},
{
"input": "5 6\n4 7 7 3 4 3 9 4 3 9\n7 5 7 8 1 7 7 2 6 2 1 2",
"output": "7"
},
{
"input": "7 3\n2 6 6 7 6 4 6 1 9 6 7 4 1 9\n6 5 3 6 6 8",
"output": "6"
},
{
"input": "9 2\n9 6 1 6 2 5 7 3 8 1 7 2 9 1 2 8 3 8\n6 4 4 5",
"output": "0"
},
{
"input": "5 6\n1 7 5 6 6 9 3 6 1 9\n2 7 2 5 8 5 4 8 4 2 8 2",
"output": "0"
},
{
"input": "3 9\n9 7 9 2 7 2\n9 8 1 9 3 9 6 3 8 6 4 6 1 3 5 4 5 3",
"output": "9"
},
{
"input": "9 4\n2 8 8 9 8 1 9 2 5 9 3 5 3 2 5 2 9 1\n8 4 8 7 6 8 4 7",
"output": "8"
},
{
"input": "1 12\n6 8\n8 4 8 2 5 8 9 8 8 3 8 7 8 1 1 3 1 9 4 3 7 3 5 7",
"output": "8"
},
{
"input": "12 12\n7 6 3 8 8 4 4 7 1 9 9 5 7 5 4 9 8 6 2 7 7 3 3 6\n9 1 2 4 9 8 5 3 6 7 3 8 2 7 5 9 6 4 3 1 2 6 1 4",
"output": "-1"
},
{
"input": "12 12\n1 6 2 6 8 3 6 4 4 8 7 2 7 5 9 4 2 4 9 5 8 5 3 6\n2 8 6 9 2 6 7 4 6 5 6 3 5 8 7 8 7 1 1 9 9 7 7 3",
"output": "-1"
},
{
"input": "12 12\n6 7 5 4 7 8 2 9 8 5 3 5 1 6 7 3 7 9 5 7 1 8 6 8\n6 4 2 1 7 8 1 6 8 5 9 8 1 5 7 2 5 9 6 3 9 2 9 4",
"output": "-1"
},
{
"input": "1 10\n3 9\n3 2 3 4 5 3 5 7 8 6 2 5 7 8 2 4 1 7 5 1",
"output": "3"
},
{
"input": "3 10\n6 1 4 1 4 6\n7 1 8 1 8 5 3 2 9 7 9 3 5 9 5 3 5 7 7 2",
"output": "1"
},
{
"input": "2 7\n2 7 2 5\n7 1 9 7 8 9 4 9 8 1 3 9 3 8",
"output": "7"
},
{
"input": "12 1\n6 2 6 4 8 6 6 9 5 6 6 1 9 1 1 3 3 9 2 4 5 2 8 1\n6 7",
"output": "6"
},
{
"input": "2 11\n6 1 3 6\n1 7 1 2 1 5 1 4 5 3 3 2 9 8 4 2 7 5 4 9 2 9",
"output": "0"
},
{
"input": "6 9\n8 1 8 4 2 8 2 1 4 1 4 2\n8 3 8 6 7 8 5 8 6 7 5 7 9 6 5 6 5 3",
"output": "8"
},
{
"input": "6 4\n2 7 3 2 8 3 1 5 7 4 3 5\n2 6 9 8 8 6 6 9",
"output": "0"
},
{
"input": "3 10\n1 5 7 1 2 1\n9 5 5 6 3 5 4 7 8 3 9 6 8 4 9 8 4 6 3 4",
"output": "0"
},
{
"input": "1 7\n8 4\n9 8 8 2 6 8 8 1 7 8 2 1 9 5",
"output": "8"
},
{
"input": "3 6\n3 5 7 4 7 5\n3 9 3 2 8 6 6 2 8 2 6 9",
"output": "3"
},
{
"input": "8 5\n7 9 6 7 4 7 2 1 4 9 2 9 4 2 9 6\n8 7 1 8 8 5 3 5 3 8",
"output": "0"
},
{
"input": "8 1\n1 6 7 6 7 3 9 2 1 2 8 6 2 3 4 1\n8 3",
"output": "-1"
},
{
"input": "12 5\n9 2 6 7 7 8 3 4 8 4 7 1 2 1 7 3 7 2 5 6 3 8 1 5\n3 7 7 5 7 4 5 8 4 6",
"output": "-1"
},
{
"input": "11 1\n2 6 1 4 7 9 7 6 8 1 4 8 4 7 7 2 1 7 9 6 6 5\n3 1",
"output": "1"
},
{
"input": "10 2\n4 9 2 1 5 1 6 2 6 7 2 7 5 8 1 7 5 3 9 1\n9 7 1 4",
"output": "-1"
},
{
"input": "9 1\n1 8 7 6 7 2 7 9 4 1 4 3 3 8 4 6 9 6\n9 4",
"output": "-1"
},
{
"input": "4 7\n9 2 4 1 2 3 2 7\n6 1 5 4 7 5 6 3 1 5 8 1 1 4",
"output": "-1"
},
{
"input": "3 7\n8 2 7 9 8 1\n3 1 8 1 2 7 4 7 4 2 1 4 4 6",
"output": "-1"
},
{
"input": "12 2\n3 1 8 2 6 9 2 6 5 4 4 3 4 1 4 2 6 3 9 7 9 4 3 2\n7 1 4 1",
"output": "-1"
},
{
"input": "7 6\n6 2 9 2 6 5 2 4 1 2 4 5 6 7\n3 9 5 1 9 8 9 5 3 4 2 3",
"output": "-1"
},
{
"input": "4 12\n2 8 3 1 2 1 9 4\n9 5 5 3 1 6 3 7 7 1 8 5 6 5 4 6 1 9 1 4 2 5 9 8",
"output": "-1"
},
{
"input": "2 2\n1 2 2 3\n2 3 3 4",
"output": "0"
},
{
"input": "2 2\n1 2 1 3\n1 2 1 3",
"output": "1"
},
{
"input": "3 3\n1 2 1 3 2 3\n1 2 1 3 2 3",
"output": "-1"
},
{
"input": "2 3\n1 2 1 3\n1 2 1 3 2 3",
"output": "-1"
},
{
"input": "2 2\n1 2 2 4\n1 2 1 3",
"output": "0"
},
{
"input": "2 1\n4 5 6 7\n4 7",
"output": "-1"
},
{
"input": "3 2\n1 2 1 3 2 3\n1 2 4 5",
"output": "-1"
},
{
"input": "4 4\n1 2 1 3 6 7 6 8\n1 4 1 5 6 1 6 9",
"output": "-1"
},
{
"input": "4 4\n1 2 2 3 1 3 4 5\n1 3 3 2 1 2 4 6",
"output": "-1"
},
{
"input": "3 2\n1 2 4 5 6 7\n4 7 1 3",
"output": "-1"
},
{
"input": "2 3\n1 2 7 8\n1 3 2 4 7 9",
"output": "-1"
}
] | 1,626,630,747 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 42 | 93 | 20,172,800 | def process(A, B):
n = len(A)
m = len(B)
first = {}
second = {}
for i in range(0, n, 2):
a, b = A[i], A[i+1]
if a not in first:
first[a] = set([])
first[a].add(b)
if b not in first:
first[b] = set([])
first[b].add(a)
for i in range(0, m, 2):
a, b = B[i], B[i+1]
if a not in second:
second[a] = set([])
second[a].add(b)
if b not in second:
second[b] = set([])
second[b].add(a)
g = {}
h = {}
possible = set([])
for i in range(10):
if i in first and i in second:
for j in range(10):
if (j in first[i] and j not in second[i]) or (j not in first[i] and j in second[i]):
possible.add(i)
if j in first[i] and j not in second[i]:
pair1 = (min(i, j), max(i, j))
for j2 in second[i]:
pair2 = (min(i, j2), max(i, j2))
if pair1 not in g:
g[pair1] = set([])
g[pair1].add(i)
if pair2 not in h:
h[pair2] = set([])
h[pair2].add(i)
elif j not in first[i] and j in second[i]:
pair1 = (min(i, j), max(i, j))
for j2 in first[i]:
pair2 = (min(i, j2), max(i, j2))
if pair2 not in g:
g[pair2] = set([])
g[pair2].add(i)
if pair1 not in h:
h[pair1] = set([])
h[pair1].add(i)
if len(possible)==1:
return list(possible)[0]
one_knows = True
for x in g:
if len(g[x]) > 1:
one_knows = False
two_knows = True
for x in h:
if len(h[x]) > 1:
two_knows = False
if one_knows and two_knows:
return 0
else:
return -1
n, m = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print(process(A, B))
| Title: Open Communication
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.
Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.
Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 12$) — the number of pairs the first participant communicated to the second and vice versa.
The second line contains $n$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from first participant to the second.
The third line contains $m$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from the second participant to the first.
All pairs within each set are distinct (in particular, if there is a pair $(1,2)$, there will be no pair $(2,1)$ within the same set), and no pair contains the same number twice.
It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.
Output Specification:
If you can deduce the shared number with certainty, print that number.
If you can with certainty deduce that both participants know the shared number, but you do not know it, print $0$.
Otherwise print $-1$.
Demo Input:
['2 2\n1 2 3 4\n1 5 3 4\n', '2 2\n1 2 3 4\n1 5 6 4\n', '2 3\n1 2 4 5\n1 2 1 3 2 3\n']
Demo Output:
['1\n', '0\n', '-1\n']
Note:
In the first example the first participant communicated pairs $(1,2)$ and $(3,4)$, and the second communicated $(1,5)$, $(3,4)$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $(3,4)$. Thus, the first participant has $(1,2)$ and the second has $(1,5)$, and at this point you already know the shared number is $1$.
In the second example either the first participant has $(1,2)$ and the second has $(1,5)$, or the first has $(3,4)$ and the second has $(6,4)$. In the first case both of them know the shared number is $1$, in the second case both of them know the shared number is $4$. You don't have enough information to tell $1$ and $4$ apart.
In the third case if the first participant was given $(1,2)$, they don't know what the shared number is, since from their perspective the second participant might have been given either $(1,3)$, in which case the shared number is $1$, or $(2,3)$, in which case the shared number is $2$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $-1$. | ```python
def process(A, B):
n = len(A)
m = len(B)
first = {}
second = {}
for i in range(0, n, 2):
a, b = A[i], A[i+1]
if a not in first:
first[a] = set([])
first[a].add(b)
if b not in first:
first[b] = set([])
first[b].add(a)
for i in range(0, m, 2):
a, b = B[i], B[i+1]
if a not in second:
second[a] = set([])
second[a].add(b)
if b not in second:
second[b] = set([])
second[b].add(a)
g = {}
h = {}
possible = set([])
for i in range(10):
if i in first and i in second:
for j in range(10):
if (j in first[i] and j not in second[i]) or (j not in first[i] and j in second[i]):
possible.add(i)
if j in first[i] and j not in second[i]:
pair1 = (min(i, j), max(i, j))
for j2 in second[i]:
pair2 = (min(i, j2), max(i, j2))
if pair1 not in g:
g[pair1] = set([])
g[pair1].add(i)
if pair2 not in h:
h[pair2] = set([])
h[pair2].add(i)
elif j not in first[i] and j in second[i]:
pair1 = (min(i, j), max(i, j))
for j2 in first[i]:
pair2 = (min(i, j2), max(i, j2))
if pair2 not in g:
g[pair2] = set([])
g[pair2].add(i)
if pair1 not in h:
h[pair1] = set([])
h[pair1].add(i)
if len(possible)==1:
return list(possible)[0]
one_knows = True
for x in g:
if len(g[x]) > 1:
one_knows = False
two_knows = True
for x in h:
if len(h[x]) > 1:
two_knows = False
if one_knows and two_knows:
return 0
else:
return -1
n, m = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print(process(A, B))
``` | 0 |
|
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices. | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,663,219,850 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 8,908,800 | [n,m]=[int(i) for i in input().split()]
mark={0:['1',0]}
unmark=list(range(1,n))
class vertice:
def __init__(self):
# Initialize the edge matrix. Column and row indices of the matrix
# correspond to the vertices' indices, whose order doesn't matter.
# The values of the elements denote the length of the edges, and if
# no edge exsists between two vertices, the value would be infinity
# as a initial setting.
# vertice.d=[[float('inf') for _ in range(n)] for _ in range(n)]
# Hint: here if use the command [[0]*n]*n, although we can also
# obtain the correct square matrix with zero elements, however,
# since list is alterable, when doing the second
# multiplication, all the rows share the same memory. So, when
# changing elements in one of the rows, all the corresponding
# elements in other rows will change simutaneously.
# too much memory used! try dictionary
self.d={}
def dinput(self,lst):
# Import the length of the edges.
# lst is one edge in form ai, bi and wi
# (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 10^6), where ai, bi are edge endpoints and wi is
# the length of the edge.
self.d[(lst[0]-1,lst[1]-1)]=self.d[(lst[1]-1,lst[0]-1)]=min(lst[2],self.d.get((lst[0]-1,lst[1]-1),float('inf')))
def fmin(self):
self.vwin=0
self.vvalue=float('inf')
for i in list(mark.keys()):
for j in unmark:
if mark[i][1]+self.d.get((i,j),float('inf'))<self.vvalue:
self.vvalue=mark[i][1]+self.d.get((i,j),float('inf'))
self.vwin=j
self.vo=i
def nxt(self):
mark[self.vwin]=[mark[self.vo][0]+' '+str(self.vwin+1),self.vvalue]
unmark.remove(self.vwin)
v=vertice()
#input edges' length
for j in range(m):
v.dinput([int(i) for i in input().split()])
# print(v.d)
while True:
v.fmin()
if (not n-1 in unmark) or v.vwin==0:
break
v.nxt()
print(mark.get(n-1,['-1',0])[0]) | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none | ```python
[n,m]=[int(i) for i in input().split()]
mark={0:['1',0]}
unmark=list(range(1,n))
class vertice:
def __init__(self):
# Initialize the edge matrix. Column and row indices of the matrix
# correspond to the vertices' indices, whose order doesn't matter.
# The values of the elements denote the length of the edges, and if
# no edge exsists between two vertices, the value would be infinity
# as a initial setting.
# vertice.d=[[float('inf') for _ in range(n)] for _ in range(n)]
# Hint: here if use the command [[0]*n]*n, although we can also
# obtain the correct square matrix with zero elements, however,
# since list is alterable, when doing the second
# multiplication, all the rows share the same memory. So, when
# changing elements in one of the rows, all the corresponding
# elements in other rows will change simutaneously.
# too much memory used! try dictionary
self.d={}
def dinput(self,lst):
# Import the length of the edges.
# lst is one edge in form ai, bi and wi
# (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 10^6), where ai, bi are edge endpoints and wi is
# the length of the edge.
self.d[(lst[0]-1,lst[1]-1)]=self.d[(lst[1]-1,lst[0]-1)]=min(lst[2],self.d.get((lst[0]-1,lst[1]-1),float('inf')))
def fmin(self):
self.vwin=0
self.vvalue=float('inf')
for i in list(mark.keys()):
for j in unmark:
if mark[i][1]+self.d.get((i,j),float('inf'))<self.vvalue:
self.vvalue=mark[i][1]+self.d.get((i,j),float('inf'))
self.vwin=j
self.vo=i
def nxt(self):
mark[self.vwin]=[mark[self.vo][0]+' '+str(self.vwin+1),self.vvalue]
unmark.remove(self.vwin)
v=vertice()
#input edges' length
for j in range(m):
v.dinput([int(i) for i in input().split()])
# print(v.d)
while True:
v.fmin()
if (not n-1 in unmark) or v.vwin==0:
break
v.nxt()
print(mark.get(n-1,['-1',0])[0])
``` | 0 |
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{
"input": "16 112 50 114 68\n1 4 8 4 9\n19 11",
"output": "5178"
},
{
"input": "55 66 75 44 47\n6 0 6 6 10\n19 0",
"output": "6414"
},
{
"input": "47 11 88 5 110\n6 10 4 2 3\n10 6",
"output": "5188"
},
{
"input": "5 44 61 103 92\n9 0 10 4 8\n15 7",
"output": "4914"
},
{
"input": "115 53 96 62 110\n7 8 1 7 9\n7 16",
"output": "3416"
},
{
"input": "102 83 26 6 11\n3 4 1 8 3\n17 14",
"output": "6704"
},
{
"input": "36 102 73 101 19\n5 9 2 2 6\n4 13",
"output": "4292"
},
{
"input": "40 115 93 107 113\n5 7 2 6 8\n6 17",
"output": "2876"
},
{
"input": "53 34 53 107 81\n4 3 1 10 8\n7 7",
"output": "4324"
},
{
"input": "113 37 4 84 66\n2 0 10 3 0\n20 19",
"output": "6070"
},
{
"input": "10 53 101 62 1\n8 0 9 7 9\n0 11",
"output": "4032"
},
{
"input": "45 45 75 36 76\n6 2 2 0 0\n8 17",
"output": "5222"
},
{
"input": "47 16 44 78 111\n7 9 8 0 2\n1 19",
"output": "3288"
},
{
"input": "7 54 39 102 31\n6 0 2 10 1\n18 3",
"output": "6610"
},
{
"input": "0 46 86 72 40\n1 5 5 5 9\n6 5",
"output": "4924"
},
{
"input": "114 4 45 78 113\n0 4 8 10 2\n10 12",
"output": "4432"
},
{
"input": "56 56 96 105 107\n4 9 10 4 8\n2 1",
"output": "3104"
},
{
"input": "113 107 59 50 56\n3 7 10 6 3\n10 12",
"output": "4586"
},
{
"input": "96 104 9 94 84\n6 10 7 8 3\n14 11",
"output": "4754"
},
{
"input": "98 15 116 43 55\n4 3 0 9 3\n10 7",
"output": "5400"
},
{
"input": "0 26 99 108 35\n0 4 3 0 10\n9 5",
"output": "5388"
},
{
"input": "89 24 51 49 84\n5 6 2 2 9\n2 14",
"output": "4066"
},
{
"input": "57 51 76 45 96\n1 0 4 3 6\n12 15",
"output": "5156"
},
{
"input": "79 112 37 36 116\n2 8 4 7 5\n4 12",
"output": "3872"
},
{
"input": "71 42 60 20 7\n7 1 1 10 6\n1 7",
"output": "5242"
},
{
"input": "86 10 66 80 55\n0 2 5 10 5\n15 6",
"output": "5802"
},
{
"input": "66 109 22 22 62\n3 1 5 4 5\n10 5",
"output": "5854"
},
{
"input": "97 17 43 84 58\n2 8 3 8 6\n10 7",
"output": "5028"
},
{
"input": "109 83 5 114 104\n6 0 3 9 5\n5 2",
"output": "4386"
},
{
"input": "94 18 24 91 105\n2 0 7 10 3\n1 4",
"output": "4118"
},
{
"input": "64 17 86 59 45\n8 0 10 2 2\n4 4",
"output": "5144"
},
{
"input": "70 84 31 57 2\n7 0 0 2 7\n12 5",
"output": "6652"
},
{
"input": "98 118 117 86 4\n2 10 9 7 5\n11 15",
"output": "4476"
},
{
"input": "103 110 101 97 70\n4 2 1 0 5\n7 5",
"output": "4678"
},
{
"input": "78 96 6 97 62\n7 7 9 2 9\n10 3",
"output": "4868"
},
{
"input": "95 28 3 31 115\n1 9 0 7 3\n10 13",
"output": "5132"
},
{
"input": "45 17 116 58 3\n8 8 7 6 4\n3 19",
"output": "3992"
},
{
"input": "19 12 0 113 77\n3 0 10 9 2\n8 6",
"output": "5040"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0",
"output": "7500"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n20 0",
"output": "9500"
},
{
"input": "119 119 119 119 119\n10 10 10 10 10\n0 20",
"output": "1310"
},
{
"input": "0 0 0 0 0\n10 10 10 10 10\n0 20",
"output": "4150"
},
{
"input": "119 0 0 0 0\n10 0 0 0 0\n5 5",
"output": "7400"
},
{
"input": "0 119 0 0 0\n0 10 0 0 0\n5 5",
"output": "7050"
},
{
"input": "0 0 119 0 0\n0 0 10 0 0\n0 0",
"output": "6450"
},
{
"input": "0 0 0 119 0\n0 0 0 10 0\n5 5",
"output": "6350"
},
{
"input": "0 0 0 0 119\n0 0 0 0 10\n5 5",
"output": "6060"
},
{
"input": "119 0 0 0 0\n2 0 0 0 0\n5 5",
"output": "7412"
},
{
"input": "0 119 0 0 0\n0 2 0 0 0\n5 5",
"output": "7174"
},
{
"input": "0 0 119 0 0\n0 0 2 0 0\n5 5",
"output": "6936"
},
{
"input": "0 0 0 119 0\n0 0 0 2 0\n5 5",
"output": "6698"
},
{
"input": "0 0 0 0 119\n0 0 0 0 2\n5 5",
"output": "6460"
},
{
"input": "119 0 0 0 0\n0 0 0 0 0\n4 9",
"output": "7212"
}
] | 1,654,328,171 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import re
print'YES'if re.match(r'^\w{1,16}@\w{1,16}(\.\w{1,16})*(\/\w{1,16})?$',raw_input())else'NO' | Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
Input Specification:
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Output Specification:
Print a single integer, the value of Kevin's final score.
Demo Input:
['20 40 60 80 100\n0 1 2 3 4\n1 0\n', '119 119 119 119 119\n0 0 0 0 0\n10 0\n']
Demo Output:
['4900\n', '4930\n']
Note:
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | ```python
import re
print'YES'if re.match(r'^\w{1,16}@\w{1,16}(\.\w{1,16})*(\/\w{1,16})?$',raw_input())else'NO'
``` | -1 |
|
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get. | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{
"input": "3\n1\n5",
"output": "20"
},
{
"input": "6\n7\n1",
"output": "48"
},
{
"input": "1\n8\n3",
"output": "27"
},
{
"input": "9\n7\n2",
"output": "126"
},
{
"input": "1\n1\n10",
"output": "20"
},
{
"input": "9\n1\n1",
"output": "18"
},
{
"input": "10\n5\n6",
"output": "300"
},
{
"input": "8\n9\n7",
"output": "504"
},
{
"input": "4\n2\n10",
"output": "80"
},
{
"input": "2\n8\n3",
"output": "48"
},
{
"input": "3\n5\n7",
"output": "105"
},
{
"input": "1\n10\n1",
"output": "12"
},
{
"input": "2\n2\n2",
"output": "8"
},
{
"input": "5\n6\n1",
"output": "35"
},
{
"input": "10\n1\n1",
"output": "20"
},
{
"input": "1\n6\n1",
"output": "8"
},
{
"input": "1\n9\n1",
"output": "11"
},
{
"input": "2\n1\n2",
"output": "6"
},
{
"input": "2\n6\n1",
"output": "14"
},
{
"input": "9\n2\n1",
"output": "27"
},
{
"input": "1\n9\n2",
"output": "20"
},
{
"input": "1\n3\n1",
"output": "5"
},
{
"input": "2\n1\n1",
"output": "4"
}
] | 1,686,204,484 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | a = int(input())
b = int(input())
c = int(input())
num= [a, b, c]
print(max(a * b * c, a + b + c, a * b + c, a * (b + c), a + b * c, (a + b) * c))
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
Input Specification:
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Output Specification:
Print the maximum value of the expression that you can obtain.
Demo Input:
['1\n2\n3\n', '2\n10\n3\n']
Demo Output:
['9\n', '60\n']
Note:
none | ```python
a = int(input())
b = int(input())
c = int(input())
num= [a, b, c]
print(max(a * b * c, a + b + c, a * b + c, a * (b + c), a + b * c, (a + b) * c))
``` | 3 |
|
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 1,585,471,660 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 310 | 0 | x=int(input())
y=int(input())
c=0
while(y%x==0):
y=y//x
c=c+1
if(y>1):
print("NO")
else:
print("YES")
print(c-1) | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
Input Specification:
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
Output Specification:
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
Demo Input:
['5\n25\n', '3\n8\n']
Demo Output:
['YES\n1\n', 'NO\n']
Note:
none | ```python
x=int(input())
y=int(input())
c=0
while(y%x==0):
y=y//x
c=c+1
if(y>1):
print("NO")
else:
print("YES")
print(c-1)
``` | 3 |
|
855 | B | Marvolo Gaunt's Ring | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made.
Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | 1,000 | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876",
"output": "547306902373544674"
},
{
"input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162",
"output": "1876641179289775029"
},
{
"input": "1 0 0 0\n0",
"output": "0"
},
{
"input": "1 1000000000 1000000000 1000000000\n1000000000",
"output": "3000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 1000000000\n1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 -1000000000\n1000000000",
"output": "-3000000000000000000"
},
{
"input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 1 1 1\n-1",
"output": "-3"
},
{
"input": "1 -1 -1 -1\n1",
"output": "-3"
},
{
"input": "1 1000000000 1000000000 1000000000\n-1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 1 2 3\n-1",
"output": "-6"
},
{
"input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "3 1 1 1\n-1 -1 -1",
"output": "-3"
},
{
"input": "1 -1000000000 0 0\n1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -100 -100 -100\n100",
"output": "-30000"
},
{
"input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 999999999 999999999 999999999\n-999999999",
"output": "-2999999994000000003"
},
{
"input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000",
"output": "-1999999999000000000"
},
{
"input": "3 -2 3 -2\n1 2 1",
"output": "2"
},
{
"input": "2 1 -1 1\n1 -1",
"output": "1"
},
{
"input": "1 -1000000000 1 -1000000000\n1000000000",
"output": "-1999999999000000000"
},
{
"input": "1 1000000000 1000000000 -1000000000\n-1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 0\n1000000000",
"output": "-2000000000000000000"
}
] | 1,653,110,464 | 1,264 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | a=[1,2,3,4,5]
Q=int(input("Enter number of queries: "))
p,q,r=map(int,input("Enter 3 numbers").split())
prefix=[0 for i in range(0,len(a))]
prefix[0]=a[0]*p
for i in range(1,len(a)):
if prefix[i-1]>a[i]*p:
prefix[i]=prefix[i-1]
else:
prefix[i]=a[i]*p
suffix=[0 for i in range(0,len(a))]
#print(prefix)
suffix[len(a)-1]=a[len(a)-1]*r
for i in range(len(a)-2,-1,-1):
if suffix[i+1]>a[i]*r:
suffix[i]=suffix[i+1]
else:
suffix[i]=a[i]*r
for i in range(0,len(a)):
a[i]=a[i]*q
print("prefix: ",prefix)
print("a: ",a)
print("suffix: ",suffix)
ans=float('-inf')
for i in range(1,len(a)-2):
ans=max(ans,prefix[i-1]+a[i]+suffix[i+1])
for i in range(0,len(a)):
ans=max(ans,prefix[i]+a[i]+suffix[i])
print(ans) | Title: Marvolo Gaunt's Ring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made.
Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
Input Specification:
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
Demo Input:
['5 1 2 3\n1 2 3 4 5\n', '5 1 2 -3\n-1 -2 -3 -4 -5\n']
Demo Output:
['30\n', '12\n']
Note:
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | ```python
a=[1,2,3,4,5]
Q=int(input("Enter number of queries: "))
p,q,r=map(int,input("Enter 3 numbers").split())
prefix=[0 for i in range(0,len(a))]
prefix[0]=a[0]*p
for i in range(1,len(a)):
if prefix[i-1]>a[i]*p:
prefix[i]=prefix[i-1]
else:
prefix[i]=a[i]*p
suffix=[0 for i in range(0,len(a))]
#print(prefix)
suffix[len(a)-1]=a[len(a)-1]*r
for i in range(len(a)-2,-1,-1):
if suffix[i+1]>a[i]*r:
suffix[i]=suffix[i+1]
else:
suffix[i]=a[i]*r
for i in range(0,len(a)):
a[i]=a[i]*q
print("prefix: ",prefix)
print("a: ",a)
print("suffix: ",suffix)
ans=float('-inf')
for i in range(1,len(a)-2):
ans=max(ans,prefix[i-1]+a[i]+suffix[i+1])
for i in range(0,len(a)):
ans=max(ans,prefix[i]+a[i]+suffix[i])
print(ans)
``` | -1 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,677,468,424 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def gcd(A,B):
if A == 0:
return B
if B == 0:
return A
for i in range(min(A,B),0,-1):
if A % i == 0 and B % i == 0:
return i
return i
shu1,shu2=input().split()
shu1,shu2=int(shu1),int(shu2)
print(gcd(shu1,shu2)) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
def gcd(A,B):
if A == 0:
return B
if B == 0:
return A
for i in range(min(A,B),0,-1):
if A % i == 0 and B % i == 0:
return i
return i
shu1,shu2=input().split()
shu1,shu2=int(shu1),int(shu2)
print(gcd(shu1,shu2))
``` | 0 |
|
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output": "YES"
},
{
"input": "10 1\n5 78 3 87 4 9 5 8 9 1235",
"output": "NO"
},
{
"input": "3 12\n3 3 3",
"output": "NO"
},
{
"input": "3 9\n2 2 2",
"output": "NO"
},
{
"input": "2 5\n1 1",
"output": "NO"
},
{
"input": "1 2\n1",
"output": "NO"
},
{
"input": "3 13\n3 3 3",
"output": "NO"
},
{
"input": "3 6\n1 1 1",
"output": "NO"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "3 11\n3 3 2",
"output": "NO"
},
{
"input": "2 6\n1 3",
"output": "NO"
},
{
"input": "3 10\n2 2 2",
"output": "NO"
},
{
"input": "3 8\n2 1 1",
"output": "NO"
},
{
"input": "1 5\n2",
"output": "NO"
},
{
"input": "1 3\n1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "2 10\n4 4",
"output": "NO"
},
{
"input": "2 8\n2 3",
"output": "NO"
},
{
"input": "2 4\n1 1",
"output": "NO"
},
{
"input": "3 10\n1 2 4",
"output": "NO"
},
{
"input": "3 10\n2 1 3",
"output": "NO"
},
{
"input": "2 6\n1 2",
"output": "NO"
},
{
"input": "3 4\n1 1 1",
"output": "NO"
},
{
"input": "3 11\n1 2 4",
"output": "NO"
},
{
"input": "3 12\n3 3 2",
"output": "NO"
},
{
"input": "4 9\n1 1 1 1",
"output": "NO"
},
{
"input": "1 10\n9",
"output": "NO"
},
{
"input": "1 7\n5",
"output": "NO"
},
{
"input": "2 5\n1 2",
"output": "NO"
},
{
"input": "3 8\n1 1 2",
"output": "NO"
},
{
"input": "3 7\n1 1 1",
"output": "NO"
},
{
"input": "1 10\n1",
"output": "NO"
},
{
"input": "3 10\n2 3 4",
"output": "NO"
},
{
"input": "3 9\n1 2 3",
"output": "NO"
},
{
"input": "3 9\n3 3 2",
"output": "NO"
},
{
"input": "3 6\n3 3 2",
"output": "NO"
},
{
"input": "1 1\n3",
"output": "NO"
},
{
"input": "1 3\n2",
"output": "NO"
},
{
"input": "3 10\n3 3 3",
"output": "NO"
},
{
"input": "3 5\n1 1 1",
"output": "YES"
},
{
"input": "2 1\n100 100",
"output": "NO"
},
{
"input": "3 3\n3 3 3",
"output": "NO"
},
{
"input": "4 17\n3 3 9 1",
"output": "NO"
},
{
"input": "4 1660\n1505 13 37 100",
"output": "NO"
},
{
"input": "3 5\n3 3 2",
"output": "NO"
},
{
"input": "4 10\n3 3 2 5",
"output": "NO"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n2",
"output": "NO"
},
{
"input": "5 10\n1 2 2 4 5",
"output": "NO"
},
{
"input": "2 1\n1 1",
"output": "NO"
}
] | 1,620,197,144 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
t = sum(a)
if t >= x:
print('NO')
else:
if x - n == t:
print('YES')
else:
print('NO') | Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
Input Specification:
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Output Specification:
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
Demo Input:
['2 4\n1 3\n', '3 10\n3 3 2\n', '2 10\n1 3\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
t = sum(a)
if t >= x:
print('NO')
else:
if x - n == t:
print('YES')
else:
print('NO')
``` | 0 |
|
949 | A | Zebras | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.
Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. | In the only line of input data there is a non-empty string *s* consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |*s*|) does not exceed 200<=000 characters. | If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer *k* (1<=≤<=*k*<=≤<=|*s*|), the resulting number of subsequences. In the *i*-th of following *k* lines first print the integer *l**i* (1<=≤<=*l**i*<=≤<=|*s*|), which is the length of the *i*-th subsequence, and then *l**i* indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to *n* must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.
Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of *k*. | [
"0010100\n",
"111\n"
] | [
"3\n3 1 3 4\n3 2 5 6\n1 7\n",
"-1\n"
] | none | 500 | [
{
"input": "0010100",
"output": "3\n1 1\n5 2 3 4 5 6\n1 7"
},
{
"input": "111",
"output": "-1"
},
{
"input": "0",
"output": "1\n1 1"
},
{
"input": "1",
"output": "-1"
},
{
"input": "0101010101",
"output": "-1"
},
{
"input": "010100001",
"output": "-1"
},
{
"input": "000111000",
"output": "3\n3 1 6 7\n3 2 5 8\n3 3 4 9"
},
{
"input": "0101001000",
"output": "4\n5 1 2 3 4 5\n3 6 7 8\n1 9\n1 10"
},
{
"input": "0000001000",
"output": "8\n1 1\n1 2\n1 3\n1 4\n1 5\n3 6 7 8\n1 9\n1 10"
},
{
"input": "0101",
"output": "-1"
},
{
"input": "000101110",
"output": "-1"
},
{
"input": "010101010",
"output": "1\n9 1 2 3 4 5 6 7 8 9"
},
{
"input": "0101001010",
"output": "2\n5 1 2 3 4 5\n5 6 7 8 9 10"
},
{
"input": "0100101100",
"output": "2\n5 1 2 3 8 9\n5 4 5 6 7 10"
},
{
"input": "0110100000",
"output": "-1"
},
{
"input": "0000000000",
"output": "10\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10"
},
{
"input": "1111111111",
"output": "-1"
},
{
"input": "0010101100",
"output": "2\n3 1 8 9\n7 2 3 4 5 6 7 10"
},
{
"input": "1010000",
"output": "-1"
},
{
"input": "0001110",
"output": "-1"
},
{
"input": "0000000000011001100011110101000101000010010111000100110110000011010011110110001100100001001001010010",
"output": "22\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n7 9 24 25 26 27 28 29\n7 10 13 14 17 18 23 30\n11 11 12 15 16 19 22 31 32 33 34 35\n3 20 21 36\n3 37 46 47\n9 38 39 40 45 48 57 58 75 76\n17 41 42 43 44 49 50 51 54 55 56 59 72 73 74 77 80 81\n9 52 53 60 71 78 79 82 83 84\n7 61 64 65 66 67 70 85\n5 62 63 68 69 86\n3 87 88 89\n3 90 91 92\n5 93 94 95 96 97\n3 98 99 100"
},
{
"input": "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "1\n245 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "0010011100000000",
"output": "8\n3 1 8 9\n5 2 3 4 7 10\n3 5 6 11\n1 12\n1 13\n1 14\n1 15\n1 16"
}
] | 1,552,151,038 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 10,547,200 | s = input()
zebra = list()
f = 0
c = 0
if s[0] == '1' or s[-1] == '1':
f = 1
else:
index_1 = list()
index_0 = list()
for i in range(len(s)):
if s[i] == '0' and c == 0:
zebra.append([i])
index_0.append(len(zebra) - 1)
elif c > 0 and s[i] == '0':
r = index_1[0]
zebra[r].append(i)
c -= 1
index_1.remove(r)
index_0.append(r)
elif len(index_1) == len(zebra):
f = 1
break
else:
r = index_0[0]
zebra[r].append(i)
index_0.remove(r)
c += 1
index_1.append(r)
if f == 1 or c != 0:
print(-1)
else:
print(len(zebra))
for elem in zebra:
print(len(elem), end=' ')
for x in elem:
print(x + 1, end=' ')
print()
| Title: Zebras
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.
Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.
Input Specification:
In the only line of input data there is a non-empty string *s* consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |*s*|) does not exceed 200<=000 characters.
Output Specification:
If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer *k* (1<=≤<=*k*<=≤<=|*s*|), the resulting number of subsequences. In the *i*-th of following *k* lines first print the integer *l**i* (1<=≤<=*l**i*<=≤<=|*s*|), which is the length of the *i*-th subsequence, and then *l**i* indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to *n* must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.
Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of *k*.
Demo Input:
['0010100\n', '111\n']
Demo Output:
['3\n3 1 3 4\n3 2 5 6\n1 7\n', '-1\n']
Note:
none | ```python
s = input()
zebra = list()
f = 0
c = 0
if s[0] == '1' or s[-1] == '1':
f = 1
else:
index_1 = list()
index_0 = list()
for i in range(len(s)):
if s[i] == '0' and c == 0:
zebra.append([i])
index_0.append(len(zebra) - 1)
elif c > 0 and s[i] == '0':
r = index_1[0]
zebra[r].append(i)
c -= 1
index_1.remove(r)
index_0.append(r)
elif len(index_1) == len(zebra):
f = 1
break
else:
r = index_0[0]
zebra[r].append(i)
index_0.remove(r)
c += 1
index_1.append(r)
if f == 1 or c != 0:
print(-1)
else:
print(len(zebra))
for elem in zebra:
print(len(elem), end=' ')
for x in elem:
print(x + 1, end=' ')
print()
``` | 0 |
|
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978 -217138 -408658 493342 -733576 -350871 711210 884148 -426172 519986 -356885 527171 661680 977247 141654 906254 -961045 -759474 -48634 891473 -606365 -513781 -966166 27696",
"output": "yes"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "no"
},
{
"input": "11\n1 11 10 2 3 9 8 4 5 7 6",
"output": "no"
},
{
"input": "10\n3 2 4 5 1 6 9 7 8 10",
"output": "yes"
},
{
"input": "11\n3 4 2 5 1 6 11 7 10 8 9",
"output": "no"
},
{
"input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8",
"output": "no"
},
{
"input": "16\n6 7 8 9 5 10 11 12 13 14 15 4 16 2 1 3",
"output": "yes"
},
{
"input": "1\n0",
"output": "no"
},
{
"input": "4\n3 1 4 2",
"output": "yes"
},
{
"input": "5\n0 2 4 -2 5",
"output": "no"
},
{
"input": "5\n1 9 8 7 0",
"output": "yes"
},
{
"input": "3\n5 10 0",
"output": "no"
},
{
"input": "6\n1 3 -1 5 2 4",
"output": "yes"
},
{
"input": "4\n3 2 4 1",
"output": "no"
},
{
"input": "4\n10 5 15 0",
"output": "no"
},
{
"input": "2\n-5 -10",
"output": "no"
},
{
"input": "3\n1 0 3",
"output": "no"
},
{
"input": "4\n-2 -4 1 -3",
"output": "yes"
},
{
"input": "4\n3 6 0 2",
"output": "no"
},
{
"input": "4\n-9 10 -10 0",
"output": "yes"
},
{
"input": "4\n5 10 1 15",
"output": "no"
},
{
"input": "3\n1 0 2",
"output": "no"
},
{
"input": "4\n2 3 4 1",
"output": "no"
},
{
"input": "4\n7 5 9 12",
"output": "no"
}
] | 1,664,780,481 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
arr = list(map(int,input().split()))
if n<3:
print("no")
else:
ans = "no"
l,r = min(arr[0],arr[1]),max(arr[0],arr[1])
for i in range(2,n):
num = arr[i]
if num>l and num<r:
l = num
elif num>l and num>r:
l = r
r = num
else:
ans = "yes"
break
print(ans)
| Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate.
Output Specification:
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Demo Input:
['4\n0 10 5 15\n', '4\n0 15 5 10\n']
Demo Output:
['yes\n', 'no\n']
Note:
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | ```python
n = int(input())
arr = list(map(int,input().split()))
if n<3:
print("no")
else:
ans = "no"
l,r = min(arr[0],arr[1]),max(arr[0],arr[1])
for i in range(2,n):
num = arr[i]
if num>l and num<r:
l = num
elif num>l and num>r:
l = r
r = num
else:
ans = "yes"
break
print(ans)
``` | 0 |
|
797 | A | k-Factorization | PROGRAMMING | 1,100 | [
"implementation",
"math",
"number theory"
] | null | null | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). | If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. | [
"100000 2\n",
"100000 20\n",
"1024 5\n"
] | [
"2 50000 \n",
"-1\n",
"2 64 2 2 2 \n"
] | none | 0 | [
{
"input": "100000 2",
"output": "2 50000 "
},
{
"input": "100000 20",
"output": "-1"
},
{
"input": "1024 5",
"output": "2 64 2 2 2 "
},
{
"input": "100000 10",
"output": "2 2 2 2 2 5 5 5 5 5 "
},
{
"input": "99999 3",
"output": "3 813 41 "
},
{
"input": "99999 4",
"output": "3 3 41 271 "
},
{
"input": "99999 5",
"output": "-1"
},
{
"input": "1024 10",
"output": "2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "1024 11",
"output": "-1"
},
{
"input": "2048 11",
"output": "2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-1"
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "3 1",
"output": "3 "
},
{
"input": "3 2",
"output": "-1"
},
{
"input": "349 2",
"output": "-1"
},
{
"input": "8 1",
"output": "8 "
},
{
"input": "66049 2",
"output": "257 257 "
},
{
"input": "6557 2",
"output": "83 79 "
},
{
"input": "9 2",
"output": "3 3 "
},
{
"input": "4 2",
"output": "2 2 "
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "12 1",
"output": "12 "
},
{
"input": "17 1",
"output": "17 "
},
{
"input": "8 2",
"output": "2 4 "
},
{
"input": "14 2",
"output": "7 2 "
},
{
"input": "99991 1",
"output": "99991 "
},
{
"input": "30 2",
"output": "3 10 "
},
{
"input": "97 1",
"output": "97 "
},
{
"input": "92 2",
"output": "2 46 "
},
{
"input": "4 1",
"output": "4 "
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "30 4",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "3 1",
"output": "3 "
},
{
"input": "3 2",
"output": "-1"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "3 6",
"output": "-1"
},
{
"input": "4 1",
"output": "4 "
},
{
"input": "4 2",
"output": "2 2 "
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "4 5",
"output": "-1"
},
{
"input": "4 6",
"output": "-1"
},
{
"input": "5 1",
"output": "5 "
},
{
"input": "5 2",
"output": "-1"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "5 4",
"output": "-1"
},
{
"input": "5 5",
"output": "-1"
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "6 1",
"output": "6 "
},
{
"input": "6 2",
"output": "3 2 "
},
{
"input": "6 3",
"output": "-1"
},
{
"input": "6 4",
"output": "-1"
},
{
"input": "6 5",
"output": "-1"
},
{
"input": "6 6",
"output": "-1"
},
{
"input": "7 1",
"output": "7 "
},
{
"input": "7 2",
"output": "-1"
},
{
"input": "7 3",
"output": "-1"
},
{
"input": "7 4",
"output": "-1"
},
{
"input": "7 5",
"output": "-1"
},
{
"input": "7 6",
"output": "-1"
},
{
"input": "8 1",
"output": "8 "
},
{
"input": "8 2",
"output": "2 4 "
},
{
"input": "8 3",
"output": "2 2 2 "
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "8 5",
"output": "-1"
},
{
"input": "8 6",
"output": "-1"
},
{
"input": "9 1",
"output": "9 "
},
{
"input": "9 2",
"output": "3 3 "
},
{
"input": "9 3",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "9 5",
"output": "-1"
},
{
"input": "9 6",
"output": "-1"
},
{
"input": "10 1",
"output": "10 "
},
{
"input": "10 2",
"output": "5 2 "
},
{
"input": "10 3",
"output": "-1"
},
{
"input": "10 4",
"output": "-1"
},
{
"input": "10 5",
"output": "-1"
},
{
"input": "10 6",
"output": "-1"
},
{
"input": "11 1",
"output": "11 "
},
{
"input": "11 2",
"output": "-1"
},
{
"input": "11 3",
"output": "-1"
},
{
"input": "11 4",
"output": "-1"
},
{
"input": "11 5",
"output": "-1"
},
{
"input": "11 6",
"output": "-1"
},
{
"input": "12 1",
"output": "12 "
},
{
"input": "12 2",
"output": "2 6 "
},
{
"input": "12 3",
"output": "2 2 3 "
},
{
"input": "12 4",
"output": "-1"
},
{
"input": "12 5",
"output": "-1"
},
{
"input": "12 6",
"output": "-1"
},
{
"input": "13 1",
"output": "13 "
},
{
"input": "13 2",
"output": "-1"
},
{
"input": "13 3",
"output": "-1"
},
{
"input": "13 4",
"output": "-1"
},
{
"input": "13 5",
"output": "-1"
},
{
"input": "13 6",
"output": "-1"
},
{
"input": "14 1",
"output": "14 "
},
{
"input": "14 2",
"output": "7 2 "
},
{
"input": "14 3",
"output": "-1"
},
{
"input": "14 4",
"output": "-1"
},
{
"input": "14 5",
"output": "-1"
},
{
"input": "14 6",
"output": "-1"
},
{
"input": "15 1",
"output": "15 "
},
{
"input": "15 2",
"output": "5 3 "
},
{
"input": "15 3",
"output": "-1"
},
{
"input": "15 4",
"output": "-1"
},
{
"input": "15 5",
"output": "-1"
},
{
"input": "15 6",
"output": "-1"
},
{
"input": "16 1",
"output": "16 "
},
{
"input": "16 2",
"output": "2 8 "
},
{
"input": "16 3",
"output": "2 4 2 "
},
{
"input": "16 4",
"output": "2 2 2 2 "
},
{
"input": "16 5",
"output": "-1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "17 1",
"output": "17 "
},
{
"input": "17 2",
"output": "-1"
},
{
"input": "17 3",
"output": "-1"
},
{
"input": "17 4",
"output": "-1"
},
{
"input": "17 5",
"output": "-1"
},
{
"input": "17 6",
"output": "-1"
},
{
"input": "18 1",
"output": "18 "
},
{
"input": "18 2",
"output": "3 6 "
},
{
"input": "18 3",
"output": "3 2 3 "
},
{
"input": "18 4",
"output": "-1"
},
{
"input": "18 5",
"output": "-1"
},
{
"input": "18 6",
"output": "-1"
},
{
"input": "19 1",
"output": "19 "
},
{
"input": "19 2",
"output": "-1"
},
{
"input": "19 3",
"output": "-1"
},
{
"input": "19 4",
"output": "-1"
},
{
"input": "19 5",
"output": "-1"
},
{
"input": "19 6",
"output": "-1"
},
{
"input": "20 1",
"output": "20 "
},
{
"input": "20 2",
"output": "2 10 "
},
{
"input": "20 3",
"output": "2 2 5 "
},
{
"input": "20 4",
"output": "-1"
},
{
"input": "20 5",
"output": "-1"
},
{
"input": "20 6",
"output": "-1"
},
{
"input": "94249 1",
"output": "94249 "
},
{
"input": "94249 2",
"output": "307 307 "
},
{
"input": "94249 3",
"output": "-1"
},
{
"input": "94249 4",
"output": "-1"
},
{
"input": "94249 5",
"output": "-1"
},
{
"input": "95477 1",
"output": "95477 "
},
{
"input": "95477 2",
"output": "311 307 "
},
{
"input": "95477 3",
"output": "-1"
},
{
"input": "95477 4",
"output": "-1"
},
{
"input": "95477 5",
"output": "-1"
},
{
"input": "35557 1",
"output": "35557 "
},
{
"input": "35557 2",
"output": "31 1147 "
},
{
"input": "35557 3",
"output": "31 31 37 "
},
{
"input": "35557 4",
"output": "-1"
},
{
"input": "35557 5",
"output": "-1"
},
{
"input": "42439 1",
"output": "42439 "
},
{
"input": "42439 2",
"output": "37 1147 "
},
{
"input": "42439 3",
"output": "37 31 37 "
},
{
"input": "42439 4",
"output": "-1"
},
{
"input": "42439 5",
"output": "-1"
}
] | 1,626,231,486 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 77 | 6,963,200 | l = 0
n, c = map(int,input().split())
li = []
for _ in range(c-1):
i = 0
for x in range(2, int(n)//2):
if n%x == 0:
n/=x
i = 1
li.append(x)
break
if i == 0:
print(-1); exit()
li.append(int(n))
print(' '.join([str(elem) for elem in li])) | Title: k-Factorization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
Output Specification:
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
Demo Input:
['100000 2\n', '100000 20\n', '1024 5\n']
Demo Output:
['2 50000 \n', '-1\n', '2 64 2 2 2 \n']
Note:
none | ```python
l = 0
n, c = map(int,input().split())
li = []
for _ in range(c-1):
i = 0
for x in range(2, int(n)//2):
if n%x == 0:
n/=x
i = 1
li.append(x)
break
if i == 0:
print(-1); exit()
li.append(int(n))
print(' '.join([str(elem) for elem in li]))
``` | 0 |
|
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number. | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell. | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs. | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSDDSDSDS\nSSDDDDDDDS"
},
{
"input": "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....\nS..S...S.S\n...WWW..S.\n..S..S.S.S\nSS.......S",
"output": "No"
},
{
"input": "1 50\nW...S..............W.....S..S...............S...W.",
"output": "Yes\nWDDDSDDDDDDDDDDDDDDWDDDDDSDDSDDDDDDDDDDDDDDDSDDDWD"
},
{
"input": "2 4\n...S\n...W",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nSW",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nWS",
"output": "No"
},
{
"input": "2 4\n...W\n...S",
"output": "No"
},
{
"input": "50 1\nS\n.\n.\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\n.\nS\n.\nW\n.\nS\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\nW\n.\n.\n.\nW\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "Yes\nS\nD\nD\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nD\nS\nD\nW\nD\nS\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nW\nD\nD\nD\nW\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD"
},
{
"input": "4 4\nW..S\nW..S\nW..S\nW..S",
"output": "Yes\nWDDS\nWDDS\nWDDS\nWDDS"
},
{
"input": "4 4\nSSSS\n....\n....\nWWWW",
"output": "Yes\nSSSS\nDDDD\nDDDD\nWWWW"
},
{
"input": "4 4\nWWWW\n....\n....\nSSSS",
"output": "Yes\nWWWW\nDDDD\nDDDD\nSSSS"
},
{
"input": "4 4\nS..W\nS..W\nS..W\nS..W",
"output": "Yes\nSDDW\nSDDW\nSDDW\nSDDW"
},
{
"input": "1 1\n.",
"output": "Yes\nD"
},
{
"input": "1 1\nW",
"output": "Yes\nW"
},
{
"input": "1 1\nS",
"output": "Yes\nS"
},
{
"input": "4 2\n..\n..\n.W\n.S",
"output": "No"
},
{
"input": "4 2\n..\n..\n.S\n.W",
"output": "No"
},
{
"input": "4 2\n..\n..\nW.\nS.",
"output": "No"
},
{
"input": "4 2\n..\n..\nS.\nW.",
"output": "No"
},
{
"input": "2 4\n....\n..SW",
"output": "No"
},
{
"input": "2 4\n....\n..WS",
"output": "No"
},
{
"input": "1 2\nS.",
"output": "Yes\nSD"
}
] | 1,541,148,439 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | n, m = map(int, input().split())
mas = []
z = 0
def toD(inp):
if inp=='.':
return 'D'
return inp
for i in range(n):
mas.append([toD(x) for x in input()])
if z == 1:
print('No')
elif z == 0:
print('Yes')
print(mas)
| 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
n, m = map(int, input().split())
mas = []
z = 0
def toD(inp):
if inp=='.':
return 'D'
return inp
for i in range(n):
mas.append([toD(x) for x in input()])
if z == 1:
print('No')
elif z == 0:
print('Yes')
print(mas)
``` | 0 |
|
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 1,697,703,513 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 15 | 0 | num_bacterias = int(input())
x = 0
while 2**x < num_bacterias:
x += 1
if 2**(x-1) == num_bacterias:
print(1)
else:
print(num_bacterias % 2**(x-1) + 1) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
num_bacterias = int(input())
x = 0
while 2**x < num_bacterias:
x += 1
if 2**(x-1) == num_bacterias:
print(1)
else:
print(num_bacterias % 2**(x-1) + 1)
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,652,024,282 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | count = int(input())
listElements = []
while (count > 0):
x,y,z = input().split()
listElements.append(x)
listElements.append(y)
listElements.append(z)
count -= 1
xsum = (int(listElements[0]) + int(listElements[3]) + int(listElements[6]))
ysum = (int(listElements[1]) + int(listElements[4]) + int(listElements[7]))
zsum = (int(listElements[2]) + int(listElements[5]) + int(listElements[8]))
if (xsum == ysum == zsum == 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
count = int(input())
listElements = []
while (count > 0):
x,y,z = input().split()
listElements.append(x)
listElements.append(y)
listElements.append(z)
count -= 1
xsum = (int(listElements[0]) + int(listElements[3]) + int(listElements[6]))
ysum = (int(listElements[1]) + int(listElements[4]) + int(listElements[7]))
zsum = (int(listElements[2]) + int(listElements[5]) + int(listElements[8]))
if (xsum == ysum == zsum == 0):
print('YES')
else:
print('NO')
``` | 0 |
840 | A | Leha and Function | PROGRAMMING | 1,300 | [
"combinatorics",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — mathematical expectation of the minimal element among all *k*-element subsets.
But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays *A* and *B*, each consists of *m* integers. For all *i*,<=*j* such that 1<=≤<=*i*,<=*j*<=≤<=*m* the condition *A**i*<=≥<=*B**j* holds. Help Leha rearrange the numbers in the array *A* so that the sum is maximally possible, where *A*' is already rearranged array. | First line of input data contains single integer *m* (1<=≤<=*m*<=≤<=2·105) — length of arrays *A* and *B*.
Next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — array *A*.
Next line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=109) — array *B*. | Output *m* integers *a*'1,<=*a*'2,<=...,<=*a*'*m* — array *A*' which is permutation of the array *A*. | [
"5\n7 3 5 3 4\n2 1 3 2 3\n",
"7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n"
] | [
"4 7 3 5 3\n",
"2 6 4 5 8 8 6\n"
] | none | 500 | [
{
"input": "5\n7 3 5 3 4\n2 1 3 2 3",
"output": "4 7 3 5 3"
},
{
"input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2",
"output": "2 6 4 5 8 8 6"
}
] | 1,603,745,461 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 904 | 34,918,400 | m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_streak = a.copy()
b_streak = b.copy()
a_streak.sort(reverse=True)
b_streak.sort()
mapping = {}
for ind, b_i in enumerate(b_streak):
if b_i not in mapping:
mapping[b_i] = [a_streak[ind]]
else:
mapping[b_i].append(a_streak[ind])
# print(mapping)
ans = []
for b_i in b:
ans.append(mapping[b_i].pop())
print(*ans)
| Title: Leha and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — mathematical expectation of the minimal element among all *k*-element subsets.
But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays *A* and *B*, each consists of *m* integers. For all *i*,<=*j* such that 1<=≤<=*i*,<=*j*<=≤<=*m* the condition *A**i*<=≥<=*B**j* holds. Help Leha rearrange the numbers in the array *A* so that the sum is maximally possible, where *A*' is already rearranged array.
Input Specification:
First line of input data contains single integer *m* (1<=≤<=*m*<=≤<=2·105) — length of arrays *A* and *B*.
Next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — array *A*.
Next line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=109) — array *B*.
Output Specification:
Output *m* integers *a*'1,<=*a*'2,<=...,<=*a*'*m* — array *A*' which is permutation of the array *A*.
Demo Input:
['5\n7 3 5 3 4\n2 1 3 2 3\n', '7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n']
Demo Output:
['4 7 3 5 3\n', '2 6 4 5 8 8 6\n']
Note:
none | ```python
m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_streak = a.copy()
b_streak = b.copy()
a_streak.sort(reverse=True)
b_streak.sort()
mapping = {}
for ind, b_i in enumerate(b_streak):
if b_i not in mapping:
mapping[b_i] = [a_streak[ind]]
else:
mapping[b_i].append(a_streak[ind])
# print(mapping)
ans = []
for b_i in b:
ans.append(mapping[b_i].pop())
print(*ans)
``` | 3 |
|
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
"output": "90"
},
{
"input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88",
"output": "90"
},
{
"input": "90\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n1",
"output": "16"
},
{
"input": "5\n15 30 45 60 75",
"output": "90"
},
{
"input": "6\n14 29 43 59 70 74",
"output": "58"
},
{
"input": "1\n15",
"output": "30"
},
{
"input": "1\n16",
"output": "15"
},
{
"input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89",
"output": "90"
},
{
"input": "76\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n90",
"output": "15"
},
{
"input": "6\n13 17 32 47 60 66",
"output": "81"
},
{
"input": "84\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84",
"output": "90"
},
{
"input": "9\n6 20 27 28 40 53 59 70 85",
"output": "90"
},
{
"input": "12\n14 22 27 31 35 44 62 69 74 79 88 89",
"output": "59"
},
{
"input": "5\n15 30 45 60 74",
"output": "89"
},
{
"input": "72\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89",
"output": "54"
},
{
"input": "8\n1 16 30 31 32 33 34 50",
"output": "49"
},
{
"input": "12\n1 3 6 10 15 21 28 36 45 55 66 78",
"output": "90"
},
{
"input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90",
"output": "80"
},
{
"input": "8\n5 17 20 35 42 53 67 76",
"output": "90"
},
{
"input": "9\n15 28 39 48 55 60 63 64 74",
"output": "89"
},
{
"input": "10\n15 28 39 48 55 60 63 64 74 82",
"output": "90"
},
{
"input": "2\n1 18",
"output": "16"
},
{
"input": "9\n10 20 30 40 50 60 70 80 84",
"output": "90"
},
{
"input": "2\n16 50",
"output": "15"
},
{
"input": "6\n15 30 45 60 75 84",
"output": "90"
},
{
"input": "8\n15 20 30 40 50 60 73 83",
"output": "90"
},
{
"input": "8\n10 20 30 40 50 60 70 80",
"output": "90"
},
{
"input": "3\n1 20 90",
"output": "16"
},
{
"input": "6\n15 30 45 60 74 89",
"output": "90"
}
] | 1,495,772,704 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | import sys
number_of_minutes = int(input())
time_range = input()
minutes = time_range.split()
tmp = 0
for i in range(number_of_minutes):
if int(tmp)+15 < int(minutes[i]):
print(str(int(tmp)+15))
sys.exit()
tmp = minutes[i]
#print("tmp la : " + str(tmp))
if int(tmp)+15>90:
print("90")
else:
print(str(int(tmp)+15)) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order.
Output Specification:
Print the number of minutes Limak will watch the game.
Demo Input:
['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n']
Demo Output:
['35\n', '15\n', '90\n']
Note:
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | ```python
import sys
number_of_minutes = int(input())
time_range = input()
minutes = time_range.split()
tmp = 0
for i in range(number_of_minutes):
if int(tmp)+15 < int(minutes[i]):
print(str(int(tmp)+15))
sys.exit()
tmp = minutes[i]
#print("tmp la : " + str(tmp))
if int(tmp)+15>90:
print("90")
else:
print(str(int(tmp)+15))
``` | 3 |
|
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU",
"output": "80"
},
{
"input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR",
"output": "84"
},
{
"input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD",
"output": "76"
},
{
"input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR",
"output": "86"
},
{
"input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR",
"output": "84"
},
{
"input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL",
"output": "86"
},
{
"input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU",
"output": "86"
},
{
"input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL",
"output": "84"
},
{
"input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR",
"output": "82"
},
{
"input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD",
"output": "92"
},
{
"input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD",
"output": "86"
},
{
"input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL",
"output": "88"
},
{
"input": "1\nU",
"output": "0"
},
{
"input": "5\nUUULD",
"output": "2"
},
{
"input": "1\nD",
"output": "0"
},
{
"input": "5\nURLUL",
"output": "2"
},
{
"input": "5\nDDDRU",
"output": "2"
},
{
"input": "2\nLR",
"output": "2"
},
{
"input": "8\nDDRDLDUR",
"output": "4"
},
{
"input": "6\nLLLLUD",
"output": "2"
},
{
"input": "13\nRRRLLLLLLLLLL",
"output": "6"
}
] | 1,639,464,640 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 77 | 0 | n, s, l, r, u, d = int(input()), input(), 0, 0, 0, 0
for x in s:
if x == 'L': l += 1
elif x == 'R': r += 1
elif x == 'U': u += 1
else: d += 1
print(n - abs(l - r) - abs(u - d)) | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
Input Specification:
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Output Specification:
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
Demo Input:
['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n']
Demo Output:
['4\n', '0\n', '4\n']
Note:
none | ```python
n, s, l, r, u, d = int(input()), input(), 0, 0, 0, 0
for x in s:
if x == 'L': l += 1
elif x == 'R': r += 1
elif x == 'U': u += 1
else: d += 1
print(n - abs(l - r) - abs(u - d))
``` | 3 |
|
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"input": "129a",
"output": "4"
},
{
"input": "233444",
"output": "14"
},
{
"input": "abacaba",
"output": "21"
},
{
"input": "abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321",
"output": "324"
},
{
"input": "zazaeeeeeeeq34443333444tttttt",
"output": "155"
},
{
"input": "00000000000000000000000",
"output": "529"
},
{
"input": "999000888775646453342311",
"output": "62"
}
] | 1,616,586,587 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | ls=list(input())
n=1
print(ls)
for i in ls:
a=eval(ls[i])
for j in ls:
b=eval(ls[j])
if a==b:
n+=1
print(n) | Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th.
Input Specification:
The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105.
Output Specification:
Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count.
Demo Input:
['great10\n', 'aaaaaaaaaa\n']
Demo Output:
['7\n', '100\n']
Note:
none | ```python
ls=list(input())
n=1
print(ls)
for i in ls:
a=eval(ls[i])
for j in ls:
b=eval(ls[j])
if a==b:
n+=1
print(n)
``` | -1 |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying. | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"input": "4 0\n100 100 100 100",
"output": "0"
},
{
"input": "100 7567\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "75\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"
},
{
"input": "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50",
"output": "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68"
},
{
"input": "100 10000\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100\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"
},
{
"input": "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93",
"output": "25\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"
},
{
"input": "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76",
"output": "98\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"
},
{
"input": "5 249\n96 13 7 2 81",
"output": "5\n1 2 3 4 5"
},
{
"input": "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44",
"output": "61\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"
},
{
"input": "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80",
"output": "99\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"
},
{
"input": "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97",
"output": "89\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"
},
{
"input": "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8",
"output": "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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"
},
{
"input": "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12",
"output": "27\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"
},
{
"input": "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93",
"output": "55\n1 2 3 4 5 6 7 8 9 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"
},
{
"input": "6 41\n6 8 9 8 9 8",
"output": "5\n1 2 3 4 6"
},
{
"input": "9 95\n9 11 12 11 12 11 8 11 10",
"output": "9\n1 2 3 4 5 6 7 8 9"
},
{
"input": "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52",
"output": "89\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"
},
{
"input": "5 29\n6 3 7 2 1",
"output": "5\n1 2 3 4 5"
},
{
"input": "5 49\n16 13 7 2 1",
"output": "5\n1 2 3 4 5"
},
{
"input": "6 84\n16 21 25 6 17 16",
"output": "5\n1 2 4 5 6"
},
{
"input": "4 9\n7 4 2 1",
"output": "3\n2 3 4"
},
{
"input": "50 2500\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50\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"
},
{
"input": "100 10000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100\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"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100\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"
},
{
"input": "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6",
"output": "96\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"
},
{
"input": "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3",
"output": "47\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"
},
{
"input": "100 200\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": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
},
{
"input": "2 10000\n1 1",
"output": "2\n1 2"
},
{
"input": "1 2\n1",
"output": "1\n1"
},
{
"input": "1 3\n2",
"output": "1\n1"
},
{
"input": "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71",
"output": "34\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"
},
{
"input": "2 2\n1 10",
"output": "1\n1"
},
{
"input": "2 5\n1 1",
"output": "2\n1 2"
},
{
"input": "1 4\n3",
"output": "1\n1"
},
{
"input": "4 384\n1 2 3 4",
"output": "4\n1 2 3 4"
}
] | 1,679,981,276 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 62 | 1,638,400 | [n, k] = list(map(int, input().split(" ")))
days = list(map(int, input().split(" ")))
order = []
i = 0
while (k > 0):
if (k - min(days) < 0):
break
minimum = min(days)
k -= minimum
i += 1
order.append(days.index(minimum) + 1)
days[days.index(minimum)] = 10001
print(i)
if(i > 0):
print(' '.join(list(map(str, order))).strip())
| Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input Specification:
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
Output Specification:
In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Demo Input:
['4 10\n4 3 1 2\n', '5 6\n4 3 1 1 2\n', '1 3\n4\n']
Demo Output:
['4\n1 2 3 4', '3\n1 3 4', '0\n']
Note:
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | ```python
[n, k] = list(map(int, input().split(" ")))
days = list(map(int, input().split(" ")))
order = []
i = 0
while (k > 0):
if (k - min(days) < 0):
break
minimum = min(days)
k -= minimum
i += 1
order.append(days.index(minimum) + 1)
days[days.index(minimum)] = 10001
print(i)
if(i > 0):
print(' '.join(list(map(str, order))).strip())
``` | 3 |
|
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
},
{
"input": "2\n500000000 1000000000",
"output": "500000000"
},
{
"input": "2\n4 6",
"output": "-1"
},
{
"input": "5\n10 8 6 4 2",
"output": "2"
},
{
"input": "2\n6 10",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "1000000000"
},
{
"input": "2\n6 8",
"output": "-1"
},
{
"input": "5\n2 2 2 2 1000000000",
"output": "2"
},
{
"input": "2\n6 4",
"output": "-1"
}
] | 1,595,241,574 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 10,547,200 | n=int(input())
n1=list(map(int,input().split()))
v=0
if(1 in n1):
print(1)
else:
for i in n1:
k=0
for j in n1:
if(j%i==0):
k=k+1
if(k==n):
v=v+1
break
if(v==1):
print(i)
else:
print(-1)
| Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Output Specification:
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them.
Demo Input:
['3\n2 2 4\n', '5\n2 1 3 1 6\n', '3\n2 3 5\n']
Demo Output:
['2\n', '1\n', '-1\n']
Note:
none | ```python
n=int(input())
n1=list(map(int,input().split()))
v=0
if(1 in n1):
print(1)
else:
for i in n1:
k=0
for j in n1:
if(j%i==0):
k=k+1
if(k==n):
v=v+1
break
if(v==1):
print(i)
else:
print(-1)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones? | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones. | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | 0 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
{
"input": "1 314253869 261764879\n0",
"output": "261764879"
},
{
"input": "1 491511050 399084767\n1",
"output": "0"
},
{
"input": "2 163093925 214567542\n00",
"output": "214567542"
},
{
"input": "2 340351106 646854722\n10",
"output": "646854722"
},
{
"input": "2 222640995 489207317\n01",
"output": "489207317"
},
{
"input": "2 399898176 552898277\n11",
"output": "0"
},
{
"input": "2 690218164 577155357\n00",
"output": "577155357"
},
{
"input": "2 827538051 754412538\n10",
"output": "754412538"
},
{
"input": "2 636702427 259825230\n01",
"output": "259825230"
},
{
"input": "2 108926899 102177825\n11",
"output": "0"
},
{
"input": "3 368381052 440077270\n000",
"output": "440077270"
},
{
"input": "3 505700940 617334451\n100",
"output": "617334451"
},
{
"input": "3 499624340 643020827\n010",
"output": "1142645167"
},
{
"input": "3 75308005 971848814\n110",
"output": "971848814"
},
{
"input": "3 212627893 854138703\n001",
"output": "854138703"
},
{
"input": "3 31395883 981351561\n101",
"output": "981351561"
},
{
"input": "3 118671447 913685773\n011",
"output": "913685773"
},
{
"input": "3 255991335 385910245\n111",
"output": "0"
},
{
"input": "3 688278514 268200134\n000",
"output": "268200134"
},
{
"input": "3 825598402 445457315\n100",
"output": "445457315"
},
{
"input": "3 300751942 45676507\n010",
"output": "91353014"
},
{
"input": "3 517900980 438071829\n110",
"output": "438071829"
},
{
"input": "3 400190869 280424424\n001",
"output": "280424424"
},
{
"input": "3 577448050 344115384\n101",
"output": "344115384"
},
{
"input": "3 481435271 459737939\n011",
"output": "459737939"
},
{
"input": "3 931962412 913722450\n111",
"output": "0"
},
{
"input": "4 522194562 717060616\n0000",
"output": "717060616"
},
{
"input": "4 659514449 894317797\n1000",
"output": "894317797"
},
{
"input": "4 71574977 796834337\n0100",
"output": "868409314"
},
{
"input": "4 248832158 934154224\n1100",
"output": "934154224"
},
{
"input": "4 71474110 131122047\n0010",
"output": "202596157"
},
{
"input": "4 308379228 503761290\n1010",
"output": "812140518"
},
{
"input": "4 272484957 485636409\n0110",
"output": "758121366"
},
{
"input": "4 662893590 704772137\n1110",
"output": "704772137"
},
{
"input": "4 545183479 547124732\n0001",
"output": "547124732"
},
{
"input": "4 684444619 722440661\n1001",
"output": "722440661"
},
{
"input": "4 477963686 636258459\n0101",
"output": "1114222145"
},
{
"input": "4 360253575 773578347\n1101",
"output": "773578347"
},
{
"input": "4 832478048 910898234\n0011",
"output": "910898234"
},
{
"input": "4 343185412 714767937\n1011",
"output": "714767937"
},
{
"input": "4 480505300 892025118\n0111",
"output": "892025118"
},
{
"input": "4 322857895 774315007\n1111",
"output": "0"
},
{
"input": "4 386548854 246539479\n0000",
"output": "246539479"
},
{
"input": "4 523868742 128829368\n1000",
"output": "128829368"
},
{
"input": "4 956155921 11119257\n0100",
"output": "22238514"
},
{
"input": "4 188376438 93475808\n1100",
"output": "93475808"
},
{
"input": "4 754947032 158668188\n0010",
"output": "317336376"
},
{
"input": "4 927391856 637236921\n1010",
"output": "1274473842"
},
{
"input": "4 359679035 109461393\n0110",
"output": "218922786"
},
{
"input": "4 991751283 202031630\n1110",
"output": "202031630"
},
{
"input": "4 339351517 169008463\n0001",
"output": "169008463"
},
{
"input": "4 771638697 346265644\n1001",
"output": "346265644"
},
{
"input": "4 908958584 523522825\n0101",
"output": "1047045650"
},
{
"input": "4 677682252 405812714\n1101",
"output": "405812714"
},
{
"input": "4 815002139 288102603\n0011",
"output": "288102603"
},
{
"input": "4 952322026 760327076\n1011",
"output": "760327076"
},
{
"input": "4 663334158 312481698\n0111",
"output": "312481698"
},
{
"input": "4 840591339 154834293\n1111",
"output": "0"
},
{
"input": "14 3 11\n10110100011001",
"output": "20"
},
{
"input": "19 1 1\n1010101010101010101",
"output": "9"
},
{
"input": "1 10 1\n1",
"output": "0"
},
{
"input": "1 100 1\n1",
"output": "0"
},
{
"input": "5 1000 1\n11111",
"output": "0"
},
{
"input": "5 10 1\n11111",
"output": "0"
},
{
"input": "7 3 2\n1111111",
"output": "0"
},
{
"input": "5 1 10\n10101",
"output": "11"
},
{
"input": "1 3 2\n1",
"output": "0"
},
{
"input": "2 10 1\n11",
"output": "0"
},
{
"input": "4 148823922 302792601\n1010",
"output": "451616523"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "5 2 3\n00011",
"output": "3"
},
{
"input": "1 5 0\n1",
"output": "0"
},
{
"input": "7 2 3\n1001001",
"output": "5"
},
{
"input": "10 1 1000000000\n1111010111",
"output": "1000000001"
},
{
"input": "25 999999998 999999999\n1011001110101010100111001",
"output": "7999999985"
},
{
"input": "2 0 1\n00",
"output": "1"
},
{
"input": "2 1 100\n10",
"output": "100"
},
{
"input": "7 20 3\n1111111",
"output": "0"
},
{
"input": "1 1 0\n1",
"output": "0"
},
{
"input": "3 1 10\n010",
"output": "11"
},
{
"input": "2 1 0\n11",
"output": "0"
},
{
"input": "7 100 3\n1111111",
"output": "0"
},
{
"input": "5 1 1000\n10101",
"output": "1001"
},
{
"input": "5 2 1\n11111",
"output": "0"
},
{
"input": "1 1000 1\n1",
"output": "0"
},
{
"input": "1 799543940 488239239\n1",
"output": "0"
},
{
"input": "6 1 1000\n010101",
"output": "1002"
},
{
"input": "5 11 1\n11111",
"output": "0"
},
{
"input": "5 2 3\n10101",
"output": "5"
},
{
"input": "3 10 1\n111",
"output": "0"
},
{
"input": "7 9 10\n1001011",
"output": "19"
},
{
"input": "5 5 6\n10101",
"output": "11"
},
{
"input": "1 1000000000 0\n1",
"output": "0"
},
{
"input": "4 0 1\n0101",
"output": "1"
},
{
"input": "8 2 3\n10101010",
"output": "9"
},
{
"input": "6 3 100\n010101",
"output": "106"
},
{
"input": "3 3 2\n111",
"output": "0"
},
{
"input": "1 20 1\n1",
"output": "0"
},
{
"input": "2 1 2\n01",
"output": "2"
}
] | 1,530,460,369 | 6,469 | PyPy 3 | OK | TESTS | 115 | 171 | 3,788,800 | # -*- coding: utf-8 -*-
def problem():
in1 = input()
in2 = input()
# in1 = '5 5 10'
# in2 = '101010'
inp1 = list(map(int, in1.split()))
n = inp1[0]
exc_cost = inp1[1]
flip_cost = inp1[2]
s = in2;
zeros = 0
sign = s[0]
for num in s[1:]:
# print(num)
if (num != sign):
if (sign == '0'):
zeros += 1
sign = num
if (sign == '0'):
zeros += 1
if zeros == 0:
return 0
if zeros == 1:
return flip_cost
cost1 = (zeros - 1) * exc_cost + flip_cost
cost2 = zeros * flip_cost
if (cost1 <= cost2):
return cost1
else:
return cost2
result = problem()
print(result)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input Specification:
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones.
Output Specification:
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
Demo Input:
['5 1 10\n01000\n', '5 10 1\n01000\n', '7 2 3\n1111111\n']
Demo Output:
['11\n', '2\n', '0\n']
Note:
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | ```python
# -*- coding: utf-8 -*-
def problem():
in1 = input()
in2 = input()
# in1 = '5 5 10'
# in2 = '101010'
inp1 = list(map(int, in1.split()))
n = inp1[0]
exc_cost = inp1[1]
flip_cost = inp1[2]
s = in2;
zeros = 0
sign = s[0]
for num in s[1:]:
# print(num)
if (num != sign):
if (sign == '0'):
zeros += 1
sign = num
if (sign == '0'):
zeros += 1
if zeros == 0:
return 0
if zeros == 1:
return flip_cost
cost1 = (zeros - 1) * exc_cost + flip_cost
cost2 = zeros * flip_cost
if (cost1 <= cost2):
return cost1
else:
return cost2
result = problem()
print(result)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,682,316,258 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | for i in range(int(inout())):
s=input()
if(s.len()>10):
print(s[0],s(len)-2,s[-1],sep="")
else:
print(s) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
for i in range(int(inout())):
s=input()
if(s.len()>10):
print(s[0],s(len)-2,s[-1],sep="")
else:
print(s)
``` | -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,681,866,850 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n=int(input())
l=list(map(int,input().split()))
m=0
for i in range(n-1):
if l[i+1] - l[i] > m:
m=i+2
print(m) | 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())
l=list(map(int,input().split()))
m=0
for i in range(n-1):
if l[i+1] - l[i] > m:
m=i+2
print(m)
``` | 0 |
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,673,738,346 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n = int(input())
test_cases = input().split()
for i in range(n):
if i == 0:
print(int(test_cases[1])-int(test_cases[0]), int(test_cases[-1])-int(test_cases[0]))
elif i == n-1:
print(int(test_cases[i])-int(test_cases[i-1]), int(test_cases[i])-int(test_cases[0]))
else:
shortest = max(int(test_cases[i])-int(test_cases[i-1]), int(test_cases[i])-int(test_cases[i+1]))
biggest = max(int(test_cases[n-1])-int(test_cases[i]), int(test_cases[i])-int(test_cases[0]))
print(shortest, biggest)
| 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())
test_cases = input().split()
for i in range(n):
if i == 0:
print(int(test_cases[1])-int(test_cases[0]), int(test_cases[-1])-int(test_cases[0]))
elif i == n-1:
print(int(test_cases[i])-int(test_cases[i-1]), int(test_cases[i])-int(test_cases[0]))
else:
shortest = max(int(test_cases[i])-int(test_cases[i-1]), int(test_cases[i])-int(test_cases[i+1]))
biggest = max(int(test_cases[n-1])-int(test_cases[i]), int(test_cases[i])-int(test_cases[0]))
print(shortest, biggest)
``` | 0 |
|
708 | A | Letters Cyclic Shift | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once? | The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. | Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. | [
"codeforces\n",
"abacaba\n"
] | [
"bncdenqbdr\n",
"aaacaba\n"
] | String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | 500 | [
{
"input": "codeforces",
"output": "bncdenqbdr"
},
{
"input": "abacaba",
"output": "aaacaba"
},
{
"input": "babbbabaababbaa",
"output": "aabbbabaababbaa"
},
{
"input": "bcbacaabcababaccccaaaabacbbcbbaa",
"output": "abaacaabcababaccccaaaabacbbcbbaa"
},
{
"input": "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda",
"output": "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda"
},
{
"input": "a",
"output": "z"
},
{
"input": "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec",
"output": "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec"
},
{
"input": "fddfbabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe",
"output": "ecceaabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaz"
},
{
"input": "abbabaaaaa",
"output": "aaaabaaaaa"
},
{
"input": "bbbbbbbbbbbb",
"output": "aaaaaaaaaaaa"
},
{
"input": "aabaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaz"
},
{
"input": "abaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa",
"output": "aaaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa"
},
{
"input": "abbbbbbbabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb",
"output": "aaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb"
},
{
"input": "aaaaa",
"output": "aaaaz"
},
{
"input": "aaa",
"output": "aaz"
},
{
"input": "aa",
"output": "az"
}
] | 1,518,976,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,632,000 | t = input()
for i,c in enumerate(t):
if c!='a':
print (t[:i] + ''.join(chr(ord(x)-1) for x in t[i:]))
break
else:
print (t[:-1] + 'b') | Title: Letters Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once?
Input Specification:
The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters.
Output Specification:
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
Demo Input:
['codeforces\n', 'abacaba\n']
Demo Output:
['bncdenqbdr\n', 'aaacaba\n']
Note:
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | ```python
t = input()
for i,c in enumerate(t):
if c!='a':
print (t[:i] + ''.join(chr(ord(x)-1) for x in t[i:]))
break
else:
print (t[:-1] + 'b')
``` | 0 |
|
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*.
Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad. | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second. | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company. | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n1001011011",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "10 5 8\n1000001110",
"output": "1"
},
{
"input": "10 1 10\n0000011111",
"output": "1"
},
{
"input": "4 1 4\n0011",
"output": "1"
},
{
"input": "10 3 7\n0000011111",
"output": "1"
},
{
"input": "5 1 5\n11010",
"output": "1"
},
{
"input": "6 1 6\n111000",
"output": "1"
},
{
"input": "2 1 2\n01",
"output": "1"
},
{
"input": "10 10 1\n0000011111",
"output": "1"
},
{
"input": "6 1 6\n000111",
"output": "1"
},
{
"input": "10 2 10\n0000011111",
"output": "1"
},
{
"input": "8 1 8\n11110000",
"output": "1"
},
{
"input": "6 1 5\n100000",
"output": "1"
},
{
"input": "16 4 12\n0000000011111111",
"output": "1"
},
{
"input": "6 1 5\n111000",
"output": "1"
},
{
"input": "8 2 7\n11110000",
"output": "1"
},
{
"input": "6 2 5\n111000",
"output": "1"
},
{
"input": "9 9 1\n111000000",
"output": "1"
},
{
"input": "2 2 1\n01",
"output": "1"
},
{
"input": "5 2 5\n00001",
"output": "1"
},
{
"input": "5 1 5\n10000",
"output": "1"
},
{
"input": "6 1 6\n011111",
"output": "1"
},
{
"input": "5 5 1\n11110",
"output": "1"
},
{
"input": "2 1 2\n10",
"output": "1"
},
{
"input": "4 2 4\n0001",
"output": "1"
},
{
"input": "10 1 10\n1111100000",
"output": "1"
},
{
"input": "8 4 5\n00001111",
"output": "1"
},
{
"input": "4 4 1\n0111",
"output": "1"
},
{
"input": "8 1 8\n00101001",
"output": "1"
}
] | 1,485,721,590 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,a,b=[int(i) for i in input().split()}
x=input()
if x[a-1]==x[b-1]:
print(0)
else:
print(1)
| Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*.
Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input Specification:
The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second.
Output Specification:
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
Demo Input:
['4 1 4\n1010\n', '5 5 2\n10110\n']
Demo Output:
['1', '0']
Note:
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company. | ```python
n,a,b=[int(i) for i in input().split()}
x=input()
if x[a-1]==x[b-1]:
print(0)
else:
print(1)
``` | -1 |
|
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
},
{
"input": "5\n7 36 53 81 100",
"output": "4"
},
{
"input": "5\n100 81 53 36 7",
"output": "4"
},
{
"input": "10\n8 6 3 4 9 10 7 7 1 3",
"output": "5"
},
{
"input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862",
"output": "6"
},
{
"input": "10\n1 3 3 4 6 7 7 8 9 10",
"output": "7"
},
{
"input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137",
"output": "9"
},
{
"input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198",
"output": "5"
},
{
"input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101",
"output": "5"
},
{
"input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498",
"output": "7"
},
{
"input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679",
"output": "9"
},
{
"input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992",
"output": "57"
},
{
"input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83",
"output": "4"
},
{
"input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901",
"output": "57"
},
{
"input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100",
"output": "99"
},
{
"input": "2\n0 10000",
"output": "1"
},
{
"input": "2\n5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n10 10",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,694,659,945 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 122 | 0 | # n, k = [int(a) for a in input().split()]
# scores = list(map(int, input().split()))
#
# x = 0
#
# for i in range(n):
# if scores[i] >= scores[k-1] and scores[i] > 0:
# x += 1
#
# print(x)
#
############# Task 2
#
# print("+".join(list(map(str, sorted(input().split('+'))))))
amt = int(input())
scores = list(map(int, input().split()))
output = 0
max_num = scores[0]
min_num = scores[0]
if amt != 1:
for i in range(1, amt):
if scores[i] > max_num:
output += 1
max_num = scores[i]
elif scores[i] < min_num:
output += 1
min_num = scores[i]
print(output)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Output Specification:
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
Demo Input:
['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | ```python
# n, k = [int(a) for a in input().split()]
# scores = list(map(int, input().split()))
#
# x = 0
#
# for i in range(n):
# if scores[i] >= scores[k-1] and scores[i] > 0:
# x += 1
#
# print(x)
#
############# Task 2
#
# print("+".join(list(map(str, sorted(input().split('+'))))))
amt = int(input())
scores = list(map(int, input().split()))
output = 0
max_num = scores[0]
min_num = scores[0]
if amt != 1:
for i in range(1, amt):
if scores[i] > max_num:
output += 1
max_num = scores[i]
elif scores[i] < min_num:
output += 1
min_num = scores[i]
print(output)
``` | 3 |
|
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,685,872,462 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | s=input()
d=s.split("WUB")
b=''
for i in d:
if (i==''):
continue
b+= (i+' ')
print(b) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
s=input()
d=s.split("WUB")
b=''
for i in d:
if (i==''):
continue
b+= (i+' ')
print(b)
``` | 3 |
|
329 | B | Biridian Forest | PROGRAMMING | 1,500 | [
"dfs and similar",
"shortest paths"
] | null | null | You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.
The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example):
Moves
Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions:
- Do nothing. - Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees. - If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement.
After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).
Mikemon battle
If you and *t* (*t*<=><=0) mikemon breeders are located on the same cell, exactly *t* mikemon battles will ensue that time (since you will be battling each of those *t* breeders once). After the battle, all of those *t* breeders will leave the forest to heal their respective mikemons.
Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).
Your goal
You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.
Goal of other breeders
Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.
Your task
Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make. | The first line consists of two integers: *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=1000), denoting the number of rows and the number of columns in Biridian Forest. The next *r* rows will each depict a row of the map, where each character represents the content of a single cell:
- 'T': A cell occupied by a tree. - 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map. - 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map. - A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder).
It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves. | A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. | [
"5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000\n",
"1 4\nSE23\n"
] | [
"3\n",
"2\n"
] | The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:
The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.
For the second example, you should post this sequence in your Blog:
Here's what happens. First, you move one cell to the right.
Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing.
You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest.
Finally, you make another move by leaving the forest. | 1,000 | [
{
"input": "5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000",
"output": "3"
},
{
"input": "1 4\nSE23",
"output": "2"
},
{
"input": "3 3\n000\nS0E\n000",
"output": "0"
},
{
"input": "5 5\nS9999\nTTTT9\n99999\n9TTTT\n9999E",
"output": "135"
},
{
"input": "1 10\n9T9TSET9T9",
"output": "0"
},
{
"input": "10 1\nS\n9\n9\n9\n9\nE\n9\n9\n9\n9",
"output": "72"
},
{
"input": "4 3\nS01\n234\n567\n89E",
"output": "45"
},
{
"input": "2 2\nE9\nS4",
"output": "9"
},
{
"input": "3 3\n920\n752\nE8S",
"output": "29"
},
{
"input": "5 1\n9\nT\nE\n6\nS",
"output": "6"
},
{
"input": "1 5\n78S6E",
"output": "6"
},
{
"input": "9 8\n38030772\n697T83S2\n8T626740\n86T02062\n05402864\nT7504180\n3T368E08\n90637446\n12709560",
"output": "194"
},
{
"input": "3 5\n00000\nS0E01\n00000",
"output": "1"
}
] | 1,633,305,652 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 122 | 6,758,400 | print("ola")
| Title: Biridian Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.
The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example):
Moves
Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions:
- Do nothing. - Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees. - If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement.
After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).
Mikemon battle
If you and *t* (*t*<=><=0) mikemon breeders are located on the same cell, exactly *t* mikemon battles will ensue that time (since you will be battling each of those *t* breeders once). After the battle, all of those *t* breeders will leave the forest to heal their respective mikemons.
Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).
Your goal
You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.
Goal of other breeders
Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.
Your task
Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make.
Input Specification:
The first line consists of two integers: *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=1000), denoting the number of rows and the number of columns in Biridian Forest. The next *r* rows will each depict a row of the map, where each character represents the content of a single cell:
- 'T': A cell occupied by a tree. - 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map. - 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map. - A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder).
It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves.
Output Specification:
A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number.
Demo Input:
['5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000\n', '1 4\nSE23\n']
Demo Output:
['3\n', '2\n']
Note:
The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:
The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.
For the second example, you should post this sequence in your Blog:
Here's what happens. First, you move one cell to the right.
Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing.
You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest.
Finally, you make another move by leaving the forest. | ```python
print("ola")
``` | 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,696,773,179 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | r=list(input())
if int(n[0])%int(n[4])!=0:
d=int(n[0])//int(n[4])+1
else:
d=int(n[0])//int(n[4])
if int(n[2])%int(n[4])!=0:
e=int(n[2])//int(n[4])+1
else:
e=int(n[2])//int(n[4])
print(d*e) | 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
r=list(input())
if int(n[0])%int(n[4])!=0:
d=int(n[0])//int(n[4])+1
else:
d=int(n[0])//int(n[4])
if int(n[2])%int(n[4])!=0:
e=int(n[2])//int(n[4])+1
else:
e=int(n[2])//int(n[4])
print(d*e)
``` | -1 |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different. | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
"output": "20"
},
{
"input": "10 4\n11 6 76 49 28 20 57 152 5 32",
"output": "4"
},
{
"input": "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 310 382 770 337 18 189 570 177 29 54 855 171 205 291 299 935 620 180 114 358 88 292 118 400 218 537 369 60 683 192 13 537 59 824 264 191 3 300",
"output": "2404"
}
] | 1,662,236,502 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | # https://codeforces.com/problemset/problem/32/A
d, count = int(input().split(' ')[1]) , 0
input_arr = list(map(int, input().split(' ')))
for i in range(len(input_arr)):
modified_arr = [s for s in input_arr if s != input_arr[i]]
#print(modified_arr)
minimum, maximum = input_arr[i]-d , input_arr[i]+d
#print('min: '+str(minimum)+' ; max:'+str(maximum))
for j in modified_arr:
if (j >= minimum) and (j <= maximum):
#print(j)
count += 1
print(count)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different.
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output Specification:
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
Demo Input:
['5 10\n10 20 50 60 65\n', '5 1\n55 30 29 31 55\n']
Demo Output:
['6\n', '6\n']
Note:
none | ```python
# https://codeforces.com/problemset/problem/32/A
d, count = int(input().split(' ')[1]) , 0
input_arr = list(map(int, input().split(' ')))
for i in range(len(input_arr)):
modified_arr = [s for s in input_arr if s != input_arr[i]]
#print(modified_arr)
minimum, maximum = input_arr[i]-d , input_arr[i]+d
#print('min: '+str(minimum)+' ; max:'+str(maximum))
for j in modified_arr:
if (j >= minimum) and (j <= maximum):
#print(j)
count += 1
print(count)
``` | 0 |
580 | B | Kefa and Company | PROGRAMMING | 1,500 | [
"binary search",
"sortings",
"two pointers"
] | null | null | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least *d* units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company! | The first line of the input contains two space-separated integers, *n* and *d* (1<=≤<=*n*<=≤<=105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the description of the *i*-th friend of type *m**i*, *s**i* (0<=≤<=*m**i*,<=*s**i*<=≤<=109) — the amount of money and the friendship factor, respectively. | Print the maximum total friendship factir that can be reached. | [
"4 5\n75 5\n0 100\n150 20\n75 1\n",
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n"
] | [
"100\n",
"111\n"
] | In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends. | 1,250 | [
{
"input": "4 5\n75 5\n0 100\n150 20\n75 1",
"output": "100"
},
{
"input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54",
"output": "111"
},
{
"input": "1 1000000000\n15 12",
"output": "12"
},
{
"input": "5 1\n5 9\n2 10\n8 5\n18 12\n1 1",
"output": "12"
},
{
"input": "3 3\n4 15\n0 17\n9 11",
"output": "17"
},
{
"input": "5 10\n8 90\n1009 1000000\n9 121\n10 298\n0 109092",
"output": "1000000"
},
{
"input": "5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989",
"output": "3989899086"
},
{
"input": "4 2\n10909234 9\n10909236 8\n10909237 10\n10909235 98",
"output": "107"
},
{
"input": "3 1\n801 10101\n802 134509124\n801 1",
"output": "134509124"
},
{
"input": "4 1\n2 4\n2 2\n3 3\n3 3",
"output": "6"
},
{
"input": "8 5\n3 227589091\n12 131068951\n8 492784630\n20 918918112\n11 6972428\n20 585402296\n12 220234661\n1 225083234",
"output": "1504320408"
},
{
"input": "15 1234\n2738 322313356\n1160 970909702\n2594 902749351\n3126 324754476\n3151 177963947\n3424 396145897\n5578 737768323\n3423 687640543\n381 848813098\n1058 197211286\n936 650181776\n1025 776492538\n3598 142176544\n3595 680519527\n1191 32199940",
"output": "3634263641"
},
{
"input": "5 6\n5 11\n10 11\n11 11\n12 11\n100 1",
"output": "33"
},
{
"input": "7 6\n5 11\n9 11\n10 11\n11 11\n12 11\n13 11\n100 1",
"output": "55"
},
{
"input": "4 2\n1 1\n2 100\n3 100\n4 1",
"output": "200"
}
] | 1,693,938,700 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 452 | 17,203,200 | import sys
input=sys.stdin.readline
ppl,diff = map(int,input().split())
lst = []
for i in range(ppl):
lst.append(list(map(int,input().split())))
lst.sort()
l,r,sm,mx = 0,0,0,0
while r<ppl:
sm+=lst[r][-1]
while lst[r][0]-lst[l][0]>=diff:
sm-=lst[l][-1]
l+=1
mx = max(mx,sm)
r+=1
print(mx) | Title: Kefa and Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least *d* units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
Input Specification:
The first line of the input contains two space-separated integers, *n* and *d* (1<=≤<=*n*<=≤<=105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the description of the *i*-th friend of type *m**i*, *s**i* (0<=≤<=*m**i*,<=*s**i*<=≤<=109) — the amount of money and the friendship factor, respectively.
Output Specification:
Print the maximum total friendship factir that can be reached.
Demo Input:
['4 5\n75 5\n0 100\n150 20\n75 1\n', '5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n']
Demo Output:
['100\n', '111\n']
Note:
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends. | ```python
import sys
input=sys.stdin.readline
ppl,diff = map(int,input().split())
lst = []
for i in range(ppl):
lst.append(list(map(int,input().split())))
lst.sort()
l,r,sm,mx = 0,0,0,0
while r<ppl:
sm+=lst[r][-1]
while lst[r][0]-lst[l][0]>=diff:
sm-=lst[l][-1]
l+=1
mx = max(mx,sm)
r+=1
print(mx)
``` | 3 |
|
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=<<=*n*), that *p**i*<=><=*p**i*<=+<=1.
You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*. | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input": "10 4",
"output": "10 9 8 7 1 2 3 4 5 6"
},
{
"input": "56893 5084",
"output": "56893 56892 56891 56890 56889 56888 56887 56886 56885 56884 56883 56882 56881 56880 56879 56878 56877 56876 56875 56874 56873 56872 56871 56870 56869 56868 56867 56866 56865 56864 56863 56862 56861 56860 56859 56858 56857 56856 56855 56854 56853 56852 56851 56850 56849 56848 56847 56846 56845 56844 56843 56842 56841 56840 56839 56838 56837 56836 56835 56834 56833 56832 56831 56830 56829 56828 56827 56826 56825 56824 56823 56822 56821 56820 56819 56818 56817 56816 56815 56814 56813 56812 56811 56810 56809 5..."
},
{
"input": "6 3",
"output": "6 5 4 1 2 3"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "310 186",
"output": "310 309 308 307 306 305 304 303 302 301 300 299 298 297 296 295 294 293 292 291 290 289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183..."
},
{
"input": "726 450",
"output": "726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599..."
},
{
"input": "438 418",
"output": "438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311..."
},
{
"input": "854 829",
"output": "854 853 852 851 850 849 848 847 846 845 844 843 842 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 786 785 784 783 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727..."
},
{
"input": "214 167",
"output": "214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 ..."
},
{
"input": "85705 56268",
"output": "85705 85704 85703 85702 85701 85700 85699 85698 85697 85696 85695 85694 85693 85692 85691 85690 85689 85688 85687 85686 85685 85684 85683 85682 85681 85680 85679 85678 85677 85676 85675 85674 85673 85672 85671 85670 85669 85668 85667 85666 85665 85664 85663 85662 85661 85660 85659 85658 85657 85656 85655 85654 85653 85652 85651 85650 85649 85648 85647 85646 85645 85644 85643 85642 85641 85640 85639 85638 85637 85636 85635 85634 85633 85632 85631 85630 85629 85628 85627 85626 85625 85624 85623 85622 85621 8..."
},
{
"input": "11417 4583",
"output": "11417 11416 11415 11414 11413 11412 11411 11410 11409 11408 11407 11406 11405 11404 11403 11402 11401 11400 11399 11398 11397 11396 11395 11394 11393 11392 11391 11390 11389 11388 11387 11386 11385 11384 11383 11382 11381 11380 11379 11378 11377 11376 11375 11374 11373 11372 11371 11370 11369 11368 11367 11366 11365 11364 11363 11362 11361 11360 11359 11358 11357 11356 11355 11354 11353 11352 11351 11350 11349 11348 11347 11346 11345 11344 11343 11342 11341 11340 11339 11338 11337 11336 11335 11334 11333 1..."
},
{
"input": "53481 20593",
"output": "53481 53480 53479 53478 53477 53476 53475 53474 53473 53472 53471 53470 53469 53468 53467 53466 53465 53464 53463 53462 53461 53460 53459 53458 53457 53456 53455 53454 53453 53452 53451 53450 53449 53448 53447 53446 53445 53444 53443 53442 53441 53440 53439 53438 53437 53436 53435 53434 53433 53432 53431 53430 53429 53428 53427 53426 53425 53424 53423 53422 53421 53420 53419 53418 53417 53416 53415 53414 53413 53412 53411 53410 53409 53408 53407 53406 53405 53404 53403 53402 53401 53400 53399 53398 53397 5..."
},
{
"input": "79193 77281",
"output": "79193 79192 79191 79190 79189 79188 79187 79186 79185 79184 79183 79182 79181 79180 79179 79178 79177 79176 79175 79174 79173 79172 79171 79170 79169 79168 79167 79166 79165 79164 79163 79162 79161 79160 79159 79158 79157 79156 79155 79154 79153 79152 79151 79150 79149 79148 79147 79146 79145 79144 79143 79142 79141 79140 79139 79138 79137 79136 79135 79134 79133 79132 79131 79130 79129 79128 79127 79126 79125 79124 79123 79122 79121 79120 79119 79118 79117 79116 79115 79114 79113 79112 79111 79110 79109 7..."
},
{
"input": "42607 42144",
"output": "42607 42606 42605 42604 42603 42602 42601 42600 42599 42598 42597 42596 42595 42594 42593 42592 42591 42590 42589 42588 42587 42586 42585 42584 42583 42582 42581 42580 42579 42578 42577 42576 42575 42574 42573 42572 42571 42570 42569 42568 42567 42566 42565 42564 42563 42562 42561 42560 42559 42558 42557 42556 42555 42554 42553 42552 42551 42550 42549 42548 42547 42546 42545 42544 42543 42542 42541 42540 42539 42538 42537 42536 42535 42534 42533 42532 42531 42530 42529 42528 42527 42526 42525 42524 42523 4..."
},
{
"input": "100000 0",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "100000 99999",
"output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..."
},
{
"input": "100000 53860",
"output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..."
},
{
"input": "4 0",
"output": "1 2 3 4"
},
{
"input": "4 1",
"output": "4 1 2 3"
},
{
"input": "4 2",
"output": "4 3 1 2"
},
{
"input": "4 3",
"output": "4 3 2 1"
},
{
"input": "3 1",
"output": "3 1 2"
}
] | 1,568,864,790 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | #!/usr/bin/env python3
def main():
n, k = map(int, input().split())
arr = [*list(range(k+1, 0, -1)), *list(range(n-k+1, n+1))]
print(*arr)
if __name__ == "__main__":
main()
| Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=<<=*n*), that *p**i*<=><=*p**i*<=+<=1.
You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*.
Input Specification:
The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient.
Output Specification:
In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.
Demo Input:
['5 2\n', '3 0\n', '3 2\n']
Demo Output:
['1 5 2 4 3\n', '1 2 3\n', '3 2 1\n']
Note:
none | ```python
#!/usr/bin/env python3
def main():
n, k = map(int, input().split())
arr = [*list(range(k+1, 0, -1)), *list(range(n-k+1, n+1))]
print(*arr)
if __name__ == "__main__":
main()
``` | 0 |
|
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every *x*,<=*y* such that 1<=≤<=*x*,<=*y*<=≤<=*n* and *a**x*,<=*y*<=≠<=1, there should exist two indices *s* and *t* so that *a**x*,<=*y*<==<=*a**x*,<=*s*<=+<=*a**t*,<=*y*, where *a**i*,<=*j* denotes the integer in *i*-th row and *j*-th column.
Help Okabe determine whether a given lab is good! | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No". | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2 6 3 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 12 1 2\n4 4 1 3\n5 10 6 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n5 11 6 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n7 11 6 1",
"output": "No"
},
{
"input": "4\n1 1 1 1\n1 14 1 6\n4 5 1 5\n3 8 2 1",
"output": "Yes"
},
{
"input": "10\n3 2 6 5 1 2 1 1 2 1\n1 2 2 3 1 4 1 1 1 1\n1 1 3 1 2 2 2 1 1 1\n1 3 1 2 1 2 1 1 1 1\n12 1 4 3 3 1 1 1 2 1\n8 1 1 1 1 3 6 5 1 3\n1 1 1 2 4 1 3 2 1 1\n1 1 1 1 1 1 1 2 1 1\n1 2 1 1 1 1 1 1 1 1\n2 1 1 1 1 1 1 1 1 2",
"output": "Yes"
},
{
"input": "4\n1 2 3 5\n1 1 1 1\n1 1 1 1\n1 1 1 1",
"output": "No"
},
{
"input": "1\n2",
"output": "No"
},
{
"input": "3\n1 1 4\n1 1 2\n1 1 2",
"output": "No"
},
{
"input": "1\n5",
"output": "No"
},
{
"input": "3\n1 2 1\n2 2 3\n1 3 1",
"output": "No"
},
{
"input": "3\n2 1 1\n2 1 1\n2 1 1",
"output": "No"
},
{
"input": "1\n60000",
"output": "No"
}
] | 1,498,401,936 | 636 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define ld long double
using namespace std;
const int MAXN = 51;
int a[MAXN][MAXN];
bool used[MAXN][MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
for (int x = 0; x < n; x++){
for (int y = 0; y < n; y++){
if ((i == x) or (y == j)){
continue;
}
if (a[i][y] + a[x][j] == a[i][j]){
used[i][j] = true;
}
}
}
//cout << i << ' ' << j << ' ' << used[i][j];
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if ((a[i][j] != 1) and (!used[i][j])){
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
| Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every *x*,<=*y* such that 1<=≤<=*x*,<=*y*<=≤<=*n* and *a**x*,<=*y*<=≠<=1, there should exist two indices *s* and *t* so that *a**x*,<=*y*<==<=*a**x*,<=*s*<=+<=*a**t*,<=*y*, where *a**i*,<=*j* denotes the integer in *i*-th row and *j*-th column.
Help Okabe determine whether a given lab is good!
Input Specification:
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105).
Output Specification:
Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case.
Demo Input:
['3\n1 1 2\n2 3 1\n6 4 1\n', '3\n1 5 2\n1 1 1\n1 2 3\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No". | ```python
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define ld long double
using namespace std;
const int MAXN = 51;
int a[MAXN][MAXN];
bool used[MAXN][MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
for (int x = 0; x < n; x++){
for (int y = 0; y < n; y++){
if ((i == x) or (y == j)){
continue;
}
if (a[i][y] + a[x][j] == a[i][j]){
used[i][j] = true;
}
}
}
//cout << i << ' ' << j << ' ' << used[i][j];
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if ((a[i][j] != 1) and (!used[i][j])){
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
``` | -1 |
|
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom. | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????",
"output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT"
},
{
"input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "==="
},
{
"input": "4\n??A?",
"output": "CGAT"
},
{
"input": "4\n?C??",
"output": "ACGT"
},
{
"input": "4\nT???",
"output": "TACG"
},
{
"input": "4\n???G",
"output": "ACTG"
},
{
"input": "4\n??AC",
"output": "GTAC"
},
{
"input": "8\n?C?AA???",
"output": "CCGAAGTT"
},
{
"input": "12\n???A?G???A?T",
"output": "ACCACGGGTATT"
},
{
"input": "16\n?????C??CAG??T??",
"output": "AAACCCGGCAGGTTTT"
},
{
"input": "20\n???A?G??C?GC???????G",
"output": "AAAAAGCCCCGCGGTTTTTG"
},
{
"input": "24\n?TG???AT?A?CTTG??T?GCT??",
"output": "ATGAAAATCACCTTGCCTGGCTGG"
},
{
"input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?",
"output": "AACTGAAGAGGTCCCGAGTTTTCCACGT"
},
{
"input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?",
"output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT"
},
{
"input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?",
"output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT"
},
{
"input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??",
"output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT"
},
{
"input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??",
"output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT"
},
{
"input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?",
"output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT"
},
{
"input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG",
"output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG"
},
{
"input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??",
"output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT"
},
{
"input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?",
"output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT"
},
{
"input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C",
"output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC"
},
{
"input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??",
"output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT"
},
{
"input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG",
"output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG"
},
{
"input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG",
"output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG"
},
{
"input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?",
"output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG"
},
{
"input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C",
"output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC"
},
{
"input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?",
"output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT"
},
{
"input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???",
"output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT"
},
{
"input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????",
"output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT"
},
{
"input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT",
"output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT"
},
{
"input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG",
"output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG"
},
{
"input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA",
"output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA"
},
{
"input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??",
"output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT"
},
{
"input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C",
"output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC"
},
{
"input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C",
"output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC"
},
{
"input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G",
"output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG"
},
{
"input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?",
"output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT"
},
{
"input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT",
"output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT"
},
{
"input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?",
"output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT"
},
{
"input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??",
"output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT"
},
{
"input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA",
"output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA"
},
{
"input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?",
"output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT"
},
{
"input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G",
"output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG"
},
{
"input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA",
"output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA"
},
{
"input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?",
"output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT"
},
{
"input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?",
"output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG"
},
{
"input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT",
"output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT"
},
{
"input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA",
"output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA"
},
{
"input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G",
"output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG"
},
{
"input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?",
"output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT"
},
{
"input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T",
"output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT"
},
{
"input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T",
"output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT"
},
{
"input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????",
"output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT"
},
{
"input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??",
"output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT"
},
{
"input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??",
"output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT"
},
{
"input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?",
"output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT"
},
{
"input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT",
"output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT"
},
{
"input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?",
"output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT"
},
{
"input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??",
"output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT"
},
{
"input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?",
"output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT"
},
{
"input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?",
"output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT"
},
{
"input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C",
"output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC"
},
{
"input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC",
"output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC"
},
{
"input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG",
"output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG"
},
{
"input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?",
"output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT"
},
{
"input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC",
"output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC"
},
{
"input": "8\n???AAA??",
"output": "==="
},
{
"input": "12\nC??CC??????C",
"output": "==="
},
{
"input": "4\nG??G",
"output": "==="
},
{
"input": "4\nTT??",
"output": "==="
},
{
"input": "4\nACAC",
"output": "==="
},
{
"input": "8\nACGT???T",
"output": "ACGTACGT"
},
{
"input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG"
},
{
"input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "4\nAA?T",
"output": "==="
},
{
"input": "4\nAAAA",
"output": "==="
},
{
"input": "8\nAAA?????",
"output": "==="
},
{
"input": "10\nACGT??????",
"output": "==="
},
{
"input": "6\nACGACG",
"output": "==="
},
{
"input": "5\nAAAAA",
"output": "==="
},
{
"input": "8\nGGGGAA??",
"output": "==="
},
{
"input": "5\nATGCA",
"output": "==="
},
{
"input": "4\nTTTT",
"output": "==="
},
{
"input": "4\nACCG",
"output": "==="
},
{
"input": "8\nACGTA?GT",
"output": "ACGTACGT"
}
] | 1,482,305,311 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | n = int(input())
tar = n//4
ls = ('A','G','T','C')
st = list(input())
count = [0,0,0,0]
j=0
for i in range (0,n):
if st[i]=='A': count[0]+=1
if st[i]=='G': count[1]+=1
if st[i]=='T': count[2]+=1
if st[i]=='C': count[3]+=1
#print (count[0],count[1],count[2],count[3])
if n%4: print("===")
elif count[0]>(n//4) or count[1]>(n//4) or count[2]>(n//4) or count[3]>(n//4): print("===")
else:
for i in range (0,n):
if st[i]=='?':
while(count[j]==n//4): j+=1
st[i]=ls[j]
count[j]+=1
ans = "".join(map(str,st))
print (ans)
| Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
Input Specification:
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
Output Specification:
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
Demo Input:
['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n']
Demo Output:
['AGACGTCT\n', 'AGCT\n', '===\n', '===\n']
Note:
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom. | ```python
n = int(input())
tar = n//4
ls = ('A','G','T','C')
st = list(input())
count = [0,0,0,0]
j=0
for i in range (0,n):
if st[i]=='A': count[0]+=1
if st[i]=='G': count[1]+=1
if st[i]=='T': count[2]+=1
if st[i]=='C': count[3]+=1
#print (count[0],count[1],count[2],count[3])
if n%4: print("===")
elif count[0]>(n//4) or count[1]>(n//4) or count[2]>(n//4) or count[3]>(n//4): print("===")
else:
for i in range (0,n):
if st[i]=='?':
while(count[j]==n//4): j+=1
st[i]=ls[j]
count[j]+=1
ans = "".join(map(str,st))
print (ans)
``` | 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,652,703,142 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 4,505,600 | s=input()
a=-1
b=-1
c=-1
d=-1
e=-1
for i in range(0,len(s)):
if s[i]=="h"and a==-1:
a=i
if s[i]=="e"and a<i:
b=i
if s[i]=="l"and c==-1:
c=i
if s[i]=="l" and c<i:
d=i
if s[i]=="o"and d<i:
e=i
if(a<b<c<d<e):
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s=input()
a=-1
b=-1
c=-1
d=-1
e=-1
for i in range(0,len(s)):
if s[i]=="h"and a==-1:
a=i
if s[i]=="e"and a<i:
b=i
if s[i]=="l"and c==-1:
c=i
if s[i]=="l" and c<i:
d=i
if s[i]=="o"and d<i:
e=i
if(a<b<c<d<e):
print("YES")
else:
print("NO")
``` | 0 |
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him. | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "1 10",
"output": "<"
},
{
"input": "9 1",
"output": ">"
},
{
"input": "1 1",
"output": "="
},
{
"input": "2 2",
"output": "="
},
{
"input": "3 3",
"output": "="
},
{
"input": "4 4",
"output": "="
},
{
"input": "5 5",
"output": "="
},
{
"input": "2 3",
"output": "<"
},
{
"input": "2 5",
"output": ">"
},
{
"input": "3 2",
"output": ">"
},
{
"input": "3 4",
"output": ">"
},
{
"input": "3 5",
"output": ">"
},
{
"input": "4 2",
"output": "="
},
{
"input": "4 3",
"output": "<"
},
{
"input": "4 5",
"output": ">"
},
{
"input": "5 2",
"output": "<"
},
{
"input": "5 3",
"output": "<"
},
{
"input": "5 4",
"output": "<"
},
{
"input": "100 101",
"output": ">"
},
{
"input": "876543 372647",
"output": "<"
},
{
"input": "1000000000 999999999",
"output": "<"
},
{
"input": "1000000000 2",
"output": "<"
},
{
"input": "1000000000 1",
"output": ">"
},
{
"input": "987654321 123456789",
"output": "<"
},
{
"input": "1000000000 1000000000",
"output": "="
},
{
"input": "4359435 4396510",
"output": ">"
},
{
"input": "25936809 25936809",
"output": "="
},
{
"input": "53602896 3",
"output": "<"
},
{
"input": "13208659 1",
"output": ">"
},
{
"input": "620537015 620537016",
"output": ">"
},
{
"input": "56498103 56498102",
"output": "<"
},
{
"input": "4 1000000000",
"output": ">"
},
{
"input": "11 15",
"output": ">"
},
{
"input": "2 6",
"output": ">"
},
{
"input": "1 100",
"output": "<"
},
{
"input": "3 9",
"output": ">"
},
{
"input": "5 25",
"output": ">"
},
{
"input": "17 18",
"output": ">"
},
{
"input": "100 99",
"output": "<"
},
{
"input": "10000035 1000432",
"output": "<"
},
{
"input": "27 3",
"output": "<"
},
{
"input": "15657413 15657414",
"output": ">"
}
] | 1,634,224,695 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | import math
x, y = map(int,input().split())
if(x==y):
print('=')
else:
a = math.log(x) * y
b = math.log(y) * x
if(a < b):
print('<')
else:
print('>') | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him.
Input Specification:
On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$).
Output Specification:
If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes).
Demo Input:
['5 8\n', '10 3\n', '6 6\n']
Demo Output:
['>\n', '<\n', '=\n']
Note:
In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | ```python
import math
x, y = map(int,input().split())
if(x==y):
print('=')
else:
a = math.log(x) * y
b = math.log(y) * x
if(a < b):
print('<')
else:
print('>')
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. | The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between $-100$ and $100$. | Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower). | [
"0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n",
"0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n",
"6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples: | 0 | [
{
"input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1",
"output": "NO"
},
{
"input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8",
"output": "YES"
},
{
"input": "2 2 4 2 4 4 2 4\n0 3 3 6 6 3 3 0",
"output": "YES"
},
{
"input": "-5 -5 5 -5 5 5 -5 5\n-5 7 0 2 5 7 0 12",
"output": "YES"
},
{
"input": "-5 -5 5 -5 5 5 -5 5\n-5 12 0 7 5 12 0 17",
"output": "NO"
},
{
"input": "-5 -5 5 -5 5 5 -5 5\n6 0 0 6 -6 0 0 -6",
"output": "YES"
},
{
"input": "-100 -100 100 -100 100 100 -100 100\n-100 0 0 -100 100 0 0 100",
"output": "YES"
},
{
"input": "92 1 92 98 -5 98 -5 1\n44 60 56 48 44 36 32 48",
"output": "YES"
},
{
"input": "-12 -54 -12 33 -99 33 -99 -54\n-77 -40 -86 -31 -77 -22 -68 -31",
"output": "YES"
},
{
"input": "3 45 19 45 19 61 3 61\n-29 45 -13 29 3 45 -13 61",
"output": "YES"
},
{
"input": "79 -19 79 15 45 15 45 -19\n-1 24 -29 52 -1 80 27 52",
"output": "NO"
},
{
"input": "75 -57 75 -21 39 -21 39 -57\n10 -42 -32 0 10 42 52 0",
"output": "NO"
},
{
"input": "-11 53 9 53 9 73 -11 73\n-10 9 -43 42 -10 75 23 42",
"output": "YES"
},
{
"input": "-10 -36 -10 27 -73 27 -73 -36\n44 -28 71 -55 44 -82 17 -55",
"output": "NO"
},
{
"input": "-63 -15 6 -15 6 54 -63 54\n15 -13 -8 10 15 33 38 10",
"output": "YES"
},
{
"input": "47 15 51 15 51 19 47 19\n19 0 -27 46 19 92 65 46",
"output": "NO"
},
{
"input": "87 -5 87 79 3 79 3 -5\n36 36 78 -6 36 -48 -6 -6",
"output": "YES"
},
{
"input": "-4 56 10 56 10 70 -4 70\n-11 47 -35 71 -11 95 13 71",
"output": "YES"
},
{
"input": "-41 6 -41 8 -43 8 -43 6\n-7 27 43 -23 -7 -73 -57 -23",
"output": "NO"
},
{
"input": "44 -58 44 7 -21 7 -21 -58\n22 19 47 -6 22 -31 -3 -6",
"output": "YES"
},
{
"input": "-37 -63 49 -63 49 23 -37 23\n-52 68 -21 37 -52 6 -83 37",
"output": "YES"
},
{
"input": "93 20 93 55 58 55 58 20\n61 -17 39 5 61 27 83 5",
"output": "YES"
},
{
"input": "-7 4 -7 58 -61 58 -61 4\n-28 45 -17 34 -28 23 -39 34",
"output": "YES"
},
{
"input": "24 -79 87 -79 87 -16 24 -16\n-59 21 -85 47 -59 73 -33 47",
"output": "NO"
},
{
"input": "-68 -15 6 -15 6 59 -68 59\n48 -18 57 -27 48 -36 39 -27",
"output": "NO"
},
{
"input": "25 1 25 91 -65 91 -65 1\n24 3 15 12 24 21 33 12",
"output": "YES"
},
{
"input": "55 24 73 24 73 42 55 42\n49 17 10 56 49 95 88 56",
"output": "YES"
},
{
"input": "69 -65 69 -28 32 -28 32 -65\n-1 50 43 6 -1 -38 -45 6",
"output": "NO"
},
{
"input": "86 -26 86 18 42 18 42 -26\n3 -22 -40 21 3 64 46 21",
"output": "YES"
},
{
"input": "52 -47 52 -30 35 -30 35 -47\n49 -22 64 -37 49 -52 34 -37",
"output": "YES"
},
{
"input": "27 -59 27 9 -41 9 -41 -59\n-10 -17 2 -29 -10 -41 -22 -29",
"output": "YES"
},
{
"input": "-90 2 0 2 0 92 -90 92\n-66 31 -86 51 -66 71 -46 51",
"output": "YES"
},
{
"input": "-93 -86 -85 -86 -85 -78 -93 -78\n-13 61 0 48 -13 35 -26 48",
"output": "NO"
},
{
"input": "-3 -45 85 -45 85 43 -3 43\n-22 0 -66 44 -22 88 22 44",
"output": "YES"
},
{
"input": "-27 -73 72 -73 72 26 -27 26\n58 11 100 -31 58 -73 16 -31",
"output": "YES"
},
{
"input": "-40 -31 8 -31 8 17 -40 17\n0 18 -35 53 0 88 35 53",
"output": "NO"
},
{
"input": "-15 -63 -15 7 -85 7 -85 -63\n-35 -40 -33 -42 -35 -44 -37 -42",
"output": "YES"
},
{
"input": "-100 -100 -100 100 100 100 100 -100\n-100 0 0 100 100 0 0 -100",
"output": "YES"
},
{
"input": "67 33 67 67 33 67 33 33\n43 11 9 45 43 79 77 45",
"output": "YES"
},
{
"input": "14 8 9 8 9 3 14 3\n-2 -13 14 3 30 -13 14 -29",
"output": "YES"
},
{
"input": "4 3 7 3 7 6 4 6\n7 29 20 16 7 3 -6 16",
"output": "YES"
},
{
"input": "14 30 3 30 3 19 14 19\n19 -13 11 -5 19 3 27 -5",
"output": "NO"
},
{
"input": "-54 3 -50 3 -50 -1 -54 -1\n3 -50 -6 -41 -15 -50 -6 -59",
"output": "NO"
},
{
"input": "3 8 3 -10 21 -10 21 8\n-9 2 -21 -10 -9 -22 3 -10",
"output": "YES"
},
{
"input": "-35 3 -21 3 -21 -11 -35 -11\n-8 -10 3 -21 -8 -32 -19 -21",
"output": "NO"
},
{
"input": "-5 -23 -5 -31 3 -31 3 -23\n-7 -23 -2 -28 3 -23 -2 -18",
"output": "YES"
},
{
"input": "3 20 10 20 10 13 3 13\n3 20 21 38 39 20 21 2",
"output": "YES"
},
{
"input": "25 3 16 3 16 12 25 12\n21 -2 16 -7 11 -2 16 3",
"output": "YES"
},
{
"input": "-1 18 -1 3 14 3 14 18\n14 3 19 8 14 13 9 8",
"output": "YES"
},
{
"input": "-44 -17 -64 -17 -64 3 -44 3\n-56 15 -44 27 -32 15 -44 3",
"output": "YES"
},
{
"input": "17 3 2 3 2 18 17 18\n22 23 2 3 -18 23 2 43",
"output": "YES"
},
{
"input": "3 -22 3 -36 -11 -36 -11 -22\n11 -44 19 -36 11 -28 3 -36",
"output": "YES"
},
{
"input": "3 45 3 48 0 48 0 45\n13 38 4 47 13 56 22 47",
"output": "NO"
},
{
"input": "3 -10 2 -10 2 -9 3 -9\n38 -10 20 -28 2 -10 20 8",
"output": "YES"
},
{
"input": "-66 3 -47 3 -47 22 -66 22\n-52 -2 -45 5 -52 12 -59 5",
"output": "YES"
},
{
"input": "3 37 -1 37 -1 41 3 41\n6 31 9 34 6 37 3 34",
"output": "NO"
},
{
"input": "13 1 15 1 15 3 13 3\n13 19 21 11 13 3 5 11",
"output": "YES"
},
{
"input": "20 8 3 8 3 -9 20 -9\n2 -11 3 -10 2 -9 1 -10",
"output": "NO"
},
{
"input": "3 41 3 21 -17 21 -17 41\n26 12 10 28 26 44 42 28",
"output": "NO"
},
{
"input": "11 11 11 3 3 3 3 11\n-12 26 -27 11 -12 -4 3 11",
"output": "YES"
},
{
"input": "-29 3 -29 12 -38 12 -38 3\n-35 9 -29 15 -23 9 -29 3",
"output": "YES"
},
{
"input": "3 -32 1 -32 1 -30 3 -30\n4 -32 -16 -52 -36 -32 -16 -12",
"output": "YES"
},
{
"input": "-16 -10 -16 9 3 9 3 -10\n-8 -1 2 9 12 -1 2 -11",
"output": "YES"
},
{
"input": "3 -42 -5 -42 -5 -34 3 -34\n-8 -54 -19 -43 -8 -32 3 -43",
"output": "YES"
},
{
"input": "-47 3 -37 3 -37 -7 -47 -7\n-37 3 -33 -1 -37 -5 -41 -1",
"output": "YES"
},
{
"input": "10 3 12 3 12 5 10 5\n12 4 20 12 12 20 4 12",
"output": "YES"
},
{
"input": "3 -41 -9 -41 -9 -53 3 -53\n18 -16 38 -36 18 -56 -2 -36",
"output": "YES"
},
{
"input": "3 40 2 40 2 41 3 41\n22 39 13 48 4 39 13 30",
"output": "NO"
},
{
"input": "21 26 21 44 3 44 3 26\n-20 38 -32 26 -20 14 -8 26",
"output": "NO"
},
{
"input": "0 7 3 7 3 10 0 10\n3 9 -17 29 -37 9 -17 -11",
"output": "YES"
},
{
"input": "3 21 3 18 6 18 6 21\n-27 18 -11 2 5 18 -11 34",
"output": "YES"
},
{
"input": "-29 13 -39 13 -39 3 -29 3\n-36 -4 -50 -18 -36 -32 -22 -18",
"output": "NO"
},
{
"input": "3 -26 -2 -26 -2 -21 3 -21\n-5 -37 -16 -26 -5 -15 6 -26",
"output": "YES"
},
{
"input": "3 9 -1 9 -1 13 3 13\n-9 17 -1 9 -9 1 -17 9",
"output": "YES"
},
{
"input": "48 8 43 8 43 3 48 3\n31 -4 43 8 55 -4 43 -16",
"output": "YES"
},
{
"input": "-3 1 3 1 3 -5 -3 -5\n20 -22 3 -5 20 12 37 -5",
"output": "YES"
},
{
"input": "14 3 14 -16 -5 -16 -5 3\n14 2 15 1 14 0 13 1",
"output": "YES"
},
{
"input": "-10 12 -10 -1 3 -1 3 12\n1 10 -2 7 -5 10 -2 13",
"output": "YES"
},
{
"input": "39 21 21 21 21 3 39 3\n27 3 47 -17 27 -37 7 -17",
"output": "YES"
},
{
"input": "3 1 3 17 -13 17 -13 1\n17 20 10 27 3 20 10 13",
"output": "NO"
},
{
"input": "15 -18 3 -18 3 -6 15 -6\n29 -1 16 -14 3 -1 16 12",
"output": "YES"
},
{
"input": "41 -6 41 3 32 3 32 -6\n33 3 35 5 33 7 31 5",
"output": "YES"
},
{
"input": "7 35 3 35 3 39 7 39\n23 15 3 35 23 55 43 35",
"output": "YES"
},
{
"input": "19 19 35 19 35 3 19 3\n25 -9 16 -18 7 -9 16 0",
"output": "NO"
},
{
"input": "-20 3 -20 9 -26 9 -26 3\n-19 4 -21 2 -19 0 -17 2",
"output": "YES"
},
{
"input": "13 3 22 3 22 -6 13 -6\n26 3 22 -1 18 3 22 7",
"output": "YES"
},
{
"input": "-4 -8 -4 -15 3 -15 3 -8\n-10 5 -27 -12 -10 -29 7 -12",
"output": "YES"
},
{
"input": "3 15 7 15 7 19 3 19\n-12 30 -23 19 -12 8 -1 19",
"output": "NO"
},
{
"input": "-12 3 5 3 5 -14 -12 -14\n-14 22 5 3 24 22 5 41",
"output": "YES"
},
{
"input": "-37 3 -17 3 -17 -17 -37 -17\n-9 -41 9 -23 -9 -5 -27 -23",
"output": "YES"
},
{
"input": "3 57 3 45 -9 45 -9 57\n8 50 21 37 8 24 -5 37",
"output": "YES"
},
{
"input": "42 3 42 -6 33 -6 33 3\n42 4 41 3 40 4 41 5",
"output": "YES"
},
{
"input": "3 59 3 45 -11 45 -11 59\n-2 50 -8 44 -2 38 4 44",
"output": "YES"
},
{
"input": "-51 3 -39 3 -39 15 -51 15\n-39 14 -53 0 -39 -14 -25 0",
"output": "YES"
},
{
"input": "-7 -15 -7 3 11 3 11 -15\n15 -1 22 -8 15 -15 8 -8",
"output": "YES"
},
{
"input": "3 -39 14 -39 14 -50 3 -50\n17 -39 5 -27 -7 -39 5 -51",
"output": "YES"
},
{
"input": "91 -27 91 29 35 29 35 -27\n59 39 95 3 59 -33 23 3",
"output": "YES"
},
{
"input": "-81 -60 -31 -60 -31 -10 -81 -10\n-58 -68 -95 -31 -58 6 -21 -31",
"output": "YES"
},
{
"input": "78 -59 78 -2 21 -2 21 -59\n48 1 86 -37 48 -75 10 -37",
"output": "YES"
},
{
"input": "-38 -26 32 -26 32 44 -38 44\n2 -27 -44 19 2 65 48 19",
"output": "YES"
},
{
"input": "73 -54 73 -4 23 -4 23 -54\n47 1 77 -29 47 -59 17 -29",
"output": "YES"
},
{
"input": "-6 -25 46 -25 46 27 -6 27\n21 -43 -21 -1 21 41 63 -1",
"output": "YES"
},
{
"input": "-17 -91 -17 -27 -81 -27 -81 -91\n-48 -21 -12 -57 -48 -93 -84 -57",
"output": "YES"
},
{
"input": "-7 16 43 16 43 66 -7 66\n18 -7 -27 38 18 83 63 38",
"output": "YES"
},
{
"input": "-46 11 16 11 16 73 -46 73\n-18 -8 -67 41 -18 90 31 41",
"output": "YES"
},
{
"input": "-33 -64 25 -64 25 -6 -33 -6\n-5 -74 -51 -28 -5 18 41 -28",
"output": "YES"
},
{
"input": "99 -100 100 -100 100 -99 99 -99\n99 -99 100 -98 99 -97 98 -98",
"output": "YES"
},
{
"input": "-100 -100 -100 -99 -99 -99 -99 -100\n-10 -10 -9 -9 -10 -8 -11 -9",
"output": "NO"
},
{
"input": "-4 3 -3 3 -3 4 -4 4\n0 -4 4 0 0 4 -4 0",
"output": "NO"
},
{
"input": "0 0 10 0 10 10 0 10\n11 9 13 7 15 9 13 11",
"output": "NO"
},
{
"input": "1 1 1 6 6 6 6 1\n5 8 8 11 11 8 8 5",
"output": "NO"
},
{
"input": "99 99 99 100 100 100 100 99\n-100 0 0 100 100 0 0 -100",
"output": "NO"
},
{
"input": "0 0 0 2 2 2 2 0\n5 1 9 5 5 9 1 5",
"output": "NO"
},
{
"input": "3 2 3 3 4 3 4 2\n0 4 4 0 0 -4 -4 0",
"output": "NO"
},
{
"input": "0 0 2 0 2 2 0 2\n4 1 7 4 4 7 1 4",
"output": "NO"
},
{
"input": "3 6 3 8 5 8 5 6\n2 9 4 11 6 9 4 7",
"output": "YES"
},
{
"input": "0 0 10 0 10 10 0 10\n-1 5 5 -1 11 5 5 11",
"output": "YES"
},
{
"input": "0 0 1 0 1 1 0 1\n3 0 6 3 3 6 0 3",
"output": "NO"
},
{
"input": "3 7 4 7 4 6 3 6\n0 0 10 10 20 0 10 -10",
"output": "NO"
},
{
"input": "0 0 0 1 1 1 1 0\n0 3 3 6 6 3 3 0",
"output": "NO"
},
{
"input": "0 0 0 4 4 4 4 0\n3 6 7 10 11 6 7 2",
"output": "NO"
},
{
"input": "0 0 0 1 1 1 1 0\n0 10 10 0 20 10 10 20",
"output": "NO"
}
] | 1,529,170,112 | 3,212 | Python 3 | WRONG_ANSWER | TESTS | 13 | 92 | 0 | x1, y1, x2, y2, x3, y3, x4, y4 = map(int, input().split())
x5, y5, x6, y6, x7, y7, x8, y8 = map(int, input().split())
len1 = min(max(x3, x1), max(x7, x5)) - max(min(x1, x3), min(x5, x7))
len2 = min(max(y1, y3), max(y6, y8)) - max(min(y1, y3), min(y8, y6))
len3 = min(max(x3, x1), max(x7, x6)) - max(min(x1, x3), min(x7, x6))
len4 = min(max(y1, y3), max(y6, y7)) - max(min(y1, y3), min(y7, y6))
len5 = min(max(x3, x1), max(x5, x6)) - max(min(x1, x3), min(x5, x6))
len6 = min(max(y1, y3), max(y5, y6)) - max(min(y1, y3), min(y5, y6))
len7 = min(max(x3, x1), max(x5, x8)) - max(min(x1, x3), min(x5, x8))
len8 = min(max(y1, y3), max(y5, y8)) - max(min(y1, y3), min(y5, y8))
len9 = min(max(x3, x1), max(x7, x8)) - max(min(x1, x3), min(x7, x8))
len10 = min(max(y1, y3), max(y7, y8)) - max(min(y1, y3), min(y7, y8))
if ((len2 >= 0 and len1 >= 0) or (len3 >=0 and len4 >= 0) or (len5 >= 0 and len6 >= 0) or(len7 >= 0 and len8 >= 0) or (len9 >= 0 and len10 >= 0)):
print("YES")
else:
print("NO") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input Specification:
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between $-100$ and $100$.
Output Specification:
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Demo Input:
['0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n', '0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n', '6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples: | ```python
x1, y1, x2, y2, x3, y3, x4, y4 = map(int, input().split())
x5, y5, x6, y6, x7, y7, x8, y8 = map(int, input().split())
len1 = min(max(x3, x1), max(x7, x5)) - max(min(x1, x3), min(x5, x7))
len2 = min(max(y1, y3), max(y6, y8)) - max(min(y1, y3), min(y8, y6))
len3 = min(max(x3, x1), max(x7, x6)) - max(min(x1, x3), min(x7, x6))
len4 = min(max(y1, y3), max(y6, y7)) - max(min(y1, y3), min(y7, y6))
len5 = min(max(x3, x1), max(x5, x6)) - max(min(x1, x3), min(x5, x6))
len6 = min(max(y1, y3), max(y5, y6)) - max(min(y1, y3), min(y5, y6))
len7 = min(max(x3, x1), max(x5, x8)) - max(min(x1, x3), min(x5, x8))
len8 = min(max(y1, y3), max(y5, y8)) - max(min(y1, y3), min(y5, y8))
len9 = min(max(x3, x1), max(x7, x8)) - max(min(x1, x3), min(x7, x8))
len10 = min(max(y1, y3), max(y7, y8)) - max(min(y1, y3), min(y7, y8))
if ((len2 >= 0 and len1 >= 0) or (len3 >=0 and len4 >= 0) or (len5 >= 0 and len6 >= 0) or(len7 >= 0 and len8 >= 0) or (len9 >= 0 and len10 >= 0)):
print("YES")
else:
print("NO")
``` | 0 |
|
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"input": "eihdi",
"output": "NO"
},
{
"input": "ehdii",
"output": "NO"
},
{
"input": "edhii",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "ehdii",
"output": "NO"
},
{
"input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto",
"output": "YES"
},
{
"input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm",
"output": "YES"
},
{
"input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv",
"output": "YES"
},
{
"input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs",
"output": "YES"
},
{
"input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji",
"output": "YES"
},
{
"input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn",
"output": "YES"
},
{
"input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx",
"output": "YES"
},
{
"input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy",
"output": "YES"
},
{
"input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc",
"output": "YES"
},
{
"input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef",
"output": "NO"
},
{
"input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa",
"output": "YES"
},
{
"input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg",
"output": "YES"
},
{
"input": "oagjghsidigeh",
"output": "NO"
},
{
"input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz",
"output": "YES"
},
{
"input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi",
"output": "YES"
},
{
"input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx",
"output": "YES"
},
{
"input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq",
"output": "YES"
}
] | 1,678,893,288 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | news = input()
news_array = list(news)
sliced_news1 = []
sliced_news2 = []
sliced_news3 = []
sliced_news4 = []
for i in range(len(news_array)):
if news_array[i] == 'h':
sliced_news1 = news_array[i - 1:len(news_array)]
break
if len(sliced_news1) > 3:
for i in range(len(sliced_news1)):
if sliced_news1[i] == 'e':
sliced_news2 = sliced_news1[i - 1:len(sliced_news1)]
break
else:
print('NO')
quit()
if len(sliced_news2) > 2:
for i in range(len(sliced_news2)):
if sliced_news2[i] == 'i':
sliced_news3 = sliced_news2[i - 1:len(sliced_news2)]
break
else:
print('NO')
quit()
if len(sliced_news3) > 2:
for i in range(len(sliced_news3)):
if sliced_news3[i] == 'd':
sliced_news4 = sliced_news3[i - 1:len(sliced_news3)]
break
else:
print('NO')
quit()
if sliced_news4.count('i'):
print('YES')
else:
print('NO')
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
Input Specification:
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output Specification:
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
Demo Input:
['abcheaibcdi\n', 'hiedi\n']
Demo Output:
['YES', 'NO']
Note:
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | ```python
news = input()
news_array = list(news)
sliced_news1 = []
sliced_news2 = []
sliced_news3 = []
sliced_news4 = []
for i in range(len(news_array)):
if news_array[i] == 'h':
sliced_news1 = news_array[i - 1:len(news_array)]
break
if len(sliced_news1) > 3:
for i in range(len(sliced_news1)):
if sliced_news1[i] == 'e':
sliced_news2 = sliced_news1[i - 1:len(sliced_news1)]
break
else:
print('NO')
quit()
if len(sliced_news2) > 2:
for i in range(len(sliced_news2)):
if sliced_news2[i] == 'i':
sliced_news3 = sliced_news2[i - 1:len(sliced_news2)]
break
else:
print('NO')
quit()
if len(sliced_news3) > 2:
for i in range(len(sliced_news3)):
if sliced_news3[i] == 'd':
sliced_news4 = sliced_news3[i - 1:len(sliced_news3)]
break
else:
print('NO')
quit()
if sliced_news4.count('i'):
print('YES')
else:
print('NO')
``` | 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,582,439,418 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 310 | 0 | def howManyDiffers(n, nums):
differs = [i for i in nums if i % 2 == 0]
evenness = [i for i in nums if i % 2 != 0]
if len(evenness) == 1:
return nums.index(evenness[0]) + 1
return nums.index(differs[0]) + 1
n = int(input())
nums = [int(i) for i in input().split()]
print(howManyDiffers(n, nums)) | 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
def howManyDiffers(n, nums):
differs = [i for i in nums if i % 2 == 0]
evenness = [i for i in nums if i % 2 != 0]
if len(evenness) == 1:
return nums.index(evenness[0]) + 1
return nums.index(differs[0]) + 1
n = int(input())
nums = [int(i) for i in input().split()]
print(howManyDiffers(n, nums))
``` | 3.9225 |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,666,977,208 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 46 | 0 | l=[1,1]
for z in range(15):
l.append(l[-1]+l[-2])
n=int(input())
s=""
for y in range(1,n+1):
if y not in l:
s+="o"
else :
s+="O"
print(s) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
l=[1,1]
for z in range(15):
l.append(l[-1]+l[-2])
n=int(input())
s=""
for y in range(1,n+1):
if y not in l:
s+="o"
else :
s+="O"
print(s)
``` | 3 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,593,454,658 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 6,758,400 | s =input()
l,u = 0,0
for i in s:
if (i>='a'and i<='z'):
l=l+1 #counting lower case
if (i>='A'and i<='Z'):
u=u+1
if l>u or l==u:
print(s.lower())
else:
print(s.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s =input()
l,u = 0,0
for i in s:
if (i>='a'and i<='z'):
l=l+1 #counting lower case
if (i>='A'and i<='Z'):
u=u+1
if l>u or l==u:
print(s.lower())
else:
print(s.upper())
``` | 3.932911 |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 1 -1",
"output": "100"
},
{
"input": "100 54 100",
"output": "54"
},
{
"input": "100 37 -100",
"output": "37"
},
{
"input": "99 41 0",
"output": "41"
},
{
"input": "97 37 -92",
"output": "42"
},
{
"input": "99 38 59",
"output": "97"
},
{
"input": "35 34 1",
"output": "35"
},
{
"input": "48 1 -1",
"output": "48"
},
{
"input": "87 65 -76",
"output": "76"
},
{
"input": "76 26 29",
"output": "55"
},
{
"input": "100 65 0",
"output": "65"
},
{
"input": "2 1 100",
"output": "1"
},
{
"input": "3 2 -100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "1 1 -100",
"output": "1"
},
{
"input": "3 1 -100",
"output": "3"
},
{
"input": "4 3 -100",
"output": "3"
},
{
"input": "3 2 -12",
"output": "2"
},
{
"input": "2 2 -100",
"output": "2"
},
{
"input": "3 2 -90",
"output": "2"
},
{
"input": "6 2 -10",
"output": "4"
},
{
"input": "3 3 -100",
"output": "2"
},
{
"input": "5 2 4",
"output": "1"
},
{
"input": "6 4 5",
"output": "3"
},
{
"input": "3 2 -6",
"output": "2"
},
{
"input": "5 1 -99",
"output": "2"
},
{
"input": "6 2 5",
"output": "1"
},
{
"input": "10 1 -100",
"output": "1"
},
{
"input": "2 2 1",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "2"
},
{
"input": "17 17 2",
"output": "2"
},
{
"input": "6 6 1",
"output": "1"
},
{
"input": "5 3 -2",
"output": "1"
},
{
"input": "6 2 -100",
"output": "4"
},
{
"input": "5 3 -100",
"output": "3"
},
{
"input": "5 4 3",
"output": "2"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "5 5 2",
"output": "2"
},
{
"input": "3 2 5",
"output": "1"
},
{
"input": "5 5 -1",
"output": "4"
},
{
"input": "5 3 3",
"output": "1"
},
{
"input": "4 2 3",
"output": "1"
},
{
"input": "88 76 74",
"output": "62"
}
] | 1,584,088,087 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 18 | 109 | 307,200 | n,a,b=map(int,input().split())
z=[i for i in range(1,n+1)]
y=z.index(a)
x=(b%n)
print(z[y+x])
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
Input Specification:
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Output Specification:
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
Demo Input:
['6 2 -5\n', '5 1 3\n', '3 2 7\n']
Demo Output:
['3\n', '4\n', '3\n']
Note:
The first example is illustrated by the picture in the statements. | ```python
n,a,b=map(int,input().split())
z=[i for i in range(1,n+1)]
y=z.index(a)
x=(b%n)
print(z[y+x])
``` | -1 |
|
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form. | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "/a//aa/a//",
"output": "/a/aa/a"
},
{
"input": "/aa//b/aa",
"output": "/aa/b/aa"
},
{
"input": "////////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/"
},
{
"input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/",
"output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb"
},
{
"input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt"
},
{
"input": "///a//a////a/a//a//a//a/////",
"output": "/a/a/a/a/a/a/a"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"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",
"output": "/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"
},
{
"input": "///////////////////////////////////////////////////////////////////////////////////////////////////z",
"output": "/z"
},
{
"input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/z"
}
] | 1,585,897,910 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | /*
读题不规范,爆零两行泪。
数据不清空,爆零两行泪。
多测不读完,爆零两行泪。
边界不特判,爆零两行泪。
贪心不证明,爆零两行泪。
D P 顺序错,爆零两行泪。
大小少等号,爆零两行泪。
变量不统一,爆零两行泪。
越界不判断,爆零两行泪。
调试不注释,爆零两行泪。
溢出不 l l,爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i+1<s.size();)if(s[i]=='/'&&s[i+1]=='/')s=s.substr(0,i+1)+s.substr(i+2,s.size()-i-2);else i++;
if(s.size()&&s[s.size()-1]=='/')s=s.substr(0,s.size()-1);
cout<<s<<"\n";
return 0;
} | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form.
Input Specification:
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
Output Specification:
The path in normalized form.
Demo Input:
['//usr///local//nginx/sbin\n']
Demo Output:
['/usr/local/nginx/sbin\n']
Note:
none | ```python
/*
读题不规范,爆零两行泪。
数据不清空,爆零两行泪。
多测不读完,爆零两行泪。
边界不特判,爆零两行泪。
贪心不证明,爆零两行泪。
D P 顺序错,爆零两行泪。
大小少等号,爆零两行泪。
变量不统一,爆零两行泪。
越界不判断,爆零两行泪。
调试不注释,爆零两行泪。
溢出不 l l,爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i+1<s.size();)if(s[i]=='/'&&s[i+1]=='/')s=s.substr(0,i+1)+s.substr(i+2,s.size()-i-2);else i++;
if(s.size()&&s[s.size()-1]=='/')s=s.substr(0,s.size()-1);
cout<<s<<"\n";
return 0;
}
``` | -1 |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number. | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"output": "130"
},
{
"input": "900000000 16",
"output": "1"
},
{
"input": "909090909 50",
"output": "3"
},
{
"input": "1001 2",
"output": "100"
},
{
"input": "5 2",
"output": "3"
},
{
"input": "2 1",
"output": "1"
}
] | 1,697,426,724 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | base_list = input().split(' ')
n = int(base_list[0])
k = int(base_list[1])
for _ in range(k):
if n % 10 == 0:
n = n / 10
else:
n -= 1
print(int(n)) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number.
Input Specification:
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Output Specification:
Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number.
Demo Input:
['512 4\n', '1000000000 9\n']
Demo Output:
['50\n', '1\n']
Note:
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | ```python
base_list = input().split(' ')
n = int(base_list[0])
k = int(base_list[1])
for _ in range(k):
if n % 10 == 0:
n = n / 10
else:
n -= 1
print(int(n))
``` | 3 |
|
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*. | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "0"
},
{
"input": "6\n2 6 3 8 7 2",
"output": "5\n2 5\n3 0\n6 0\n7 0\n8 0"
},
{
"input": "7\n2 1 2 1 2 1 2",
"output": "2\n1 2\n2 2"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "1\n1 1"
},
{
"input": "9\n2 3 3 3 2 1 2 3 2",
"output": "1\n1 0"
},
{
"input": "10\n3 1 1 1 1 3 1 2 2 1",
"output": "2\n2 1\n3 5"
},
{
"input": "12\n10 9 8 7 7 8 9 10 10 9 8 7",
"output": "0"
}
] | 1,665,348,764 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 810 | 10,342,400 | n = int(input())
a = [int(x) for x in input().split()]
b = list(set(a))
ind = [10000000]*(100001)
cd = [0]*(100001)
ans = []
for i in range(n):
if ind[a[i]] == 10000000:
ind[a[i]] = i
else:
if cd[a[i]] == 0:
cd[a[i]] = i - ind[a[i]]
ind[a[i]] = i
else:
if cd[a[i]] == (i-ind[a[i]]):
ind[a[i]] = i
else:
cd[a[i]] = -1
for i in b:
if cd[i] != -1:
ans.append([i, cd[i]])
ans.sort()
print(len(ans))
for i in ans:
print(*i) | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
Output Specification:
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
Demo Input:
['1\n2\n', '8\n1 2 1 3 1 2 1 5\n']
Demo Output:
['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n']
Note:
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | ```python
n = int(input())
a = [int(x) for x in input().split()]
b = list(set(a))
ind = [10000000]*(100001)
cd = [0]*(100001)
ans = []
for i in range(n):
if ind[a[i]] == 10000000:
ind[a[i]] = i
else:
if cd[a[i]] == 0:
cd[a[i]] = i - ind[a[i]]
ind[a[i]] = i
else:
if cd[a[i]] == (i-ind[a[i]]):
ind[a[i]] = i
else:
cd[a[i]] = -1
for i in b:
if cd[i] != -1:
ans.append([i, cd[i]])
ans.sort()
print(len(ans))
for i in ans:
print(*i)
``` | 3 |
|
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 1,668,419,665 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 61 | 0 | from math import gcd
n = int(input())
g = 0
for i in map(int, input().split()): g = gcd(g,i)
print(g*n) | Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the required minimal sum.
Demo Input:
['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n']
Demo Output:
['2\n', '6\n', '12\n', '15\n']
Note:
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | ```python
from math import gcd
n = int(input())
g = 0
for i in map(int, input().split()): g = gcd(g,i)
print(g*n)
``` | 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,672,075,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 819,200 | from fractions import Fraction
from typing import List
def main():
"""Run code."""
(y,w) = map(int, input().split())
num, den = 6-max(y,w)+1, 6
print(Fraction(num, den))
if __name__ == "__main__":
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
from typing import List
def main():
"""Run code."""
(y,w) = map(int, input().split())
num, den = 6-max(y,w)+1, 6
print(Fraction(num, den))
if __name__ == "__main__":
main()
``` | 0 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,691,686,727 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n, h = map(int, input().split())
heights = list(map(int, input().split()))
width = n + sum(1 if height > h else 0 for height in heights)
print(width)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | ```python
n, h = map(int, input().split())
heights = list(map(int, input().split()))
width = n + sum(1 if height > h else 0 for height in heights)
print(width)
``` | 3 |
|
186 | B | Growing Mushrooms | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier). | The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose. | Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate. | [
"2 3 3 50\n2 4\n4 2\n",
"4 1 1 1\n544 397\n280 101\n280 101\n693 970\n"
] | [
"1 15.00\n2 15.00\n",
"4 1656.07\n1 937.03\n2 379.99\n3 379.99\n"
] | - First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | 1,000 | [
{
"input": "2 3 3 50\n2 4\n4 2",
"output": "1 15.00\n2 15.00"
},
{
"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970",
"output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"
},
{
"input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737",
"output": "8 1641.50\n6 1417.00\n7 1368.25\n10 1067.00\n4 1005.25\n1 981.75\n9 861.75\n3 814.00\n5 671.75\n2 559.00"
},
{
"input": "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978",
"output": "5 3788.56\n10 3673.36\n2 3360.12\n6 3289.08\n4 2606.20\n3 2598.64\n9 2525.24\n7 2315.84\n1 2210.84\n8 1184.72"
},
{
"input": "8 1 4 55\n507 82\n681 492\n602 849\n367 557\n438 320\n798 699\n338 302\n391 814",
"output": "3 3666.90\n6 3506.55\n8 3431.95\n2 2945.40\n4 2393.15\n1 2064.90\n5 1896.00\n7 1487.90"
},
{
"input": "9 6 4 80\n95 269\n95 269\n781 724\n22 269\n173 655\n972 850\n22 269\n95 269\n642 666",
"output": "6 4908.00\n3 3992.80\n9 3434.40\n5 2827.60\n1 1190.00\n2 1190.00\n8 1190.00\n4 1102.40\n7 1102.40"
},
{
"input": "7 1 8 25\n98 713\n876 112\n990 771\n57 395\n171 899\n86 600\n459 320",
"output": "3 8498.25\n5 7320.25\n2 7092.00\n1 5777.50\n6 4864.50\n7 3912.00\n4 3202.75"
},
{
"input": "6 1 5 9\n105 771\n105 771\n105 771\n557 985\n105 771\n105 771",
"output": "4 5431.87\n1 3950.55\n2 3950.55\n3 3950.55\n5 3950.55\n6 3950.55"
},
{
"input": "6 2 2 78\n942 465\n593 600\n480 359\n733 648\n995 55\n526 538",
"output": "1 2088.60\n5 2014.20\n4 1751.12\n2 1460.92\n6 1307.44\n3 1117.96"
},
{
"input": "2 1 1 1\n2 2\n2 2",
"output": "1 3.98\n2 3.98"
},
{
"input": "2 1 1 100\n3 4\n4 3",
"output": "1 4.00\n2 4.00"
},
{
"input": "1 1 1 1\n1 1",
"output": "1 1.99"
}
] | 1,649,050,764 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def fun(a,b,k,t1,t2):
n1=b*t2+(a*t1*(100-k)/100)
n2=a*t2+(b*t1*(100-k)/100)
return max(n1,n2)
n,t1,t2,k=map(int,input().split())
l=[]
for i in range(n):
a,b=map(int,input().split())
l.append([fun(a,b,k,t1,t2),i+1])
b=sorted(l,key=lambda x:(-x[0],x[1]))
for x in b:
print(x[1],round(x[0],2)) | Title: Growing Mushrooms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input Specification:
The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose.
Output Specification:
Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Demo Input:
['2 3 3 50\n2 4\n4 2\n', '4 1 1 1\n544 397\n280 101\n280 101\n693 970\n']
Demo Output:
['1 15.00\n2 15.00\n', '4 1656.07\n1 937.03\n2 379.99\n3 379.99\n']
Note:
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | ```python
def fun(a,b,k,t1,t2):
n1=b*t2+(a*t1*(100-k)/100)
n2=a*t2+(b*t1*(100-k)/100)
return max(n1,n2)
n,t1,t2,k=map(int,input().split())
l=[]
for i in range(n):
a,b=map(int,input().split())
l.append([fun(a,b,k,t1,t2),i+1])
b=sorted(l,key=lambda x:(-x[0],x[1]))
for x in b:
print(x[1],round(x[0],2))
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,647,351,786 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s1=input()
s2=input()
k=s1[::-1]
if k==s2:
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
s1=input()
s2=input()
k=s1[::-1]
if k==s2:
print("yes")
else:
print("no")
``` | 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,655,400,153 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 3,379,200 | n,m,a=int(input().split())
if m%a==0:
v=m//a
else:
v=m//a+1
if n%a==0:
v2=n//a
else:
v2=n//a+1
print(v*v2) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n,m,a=int(input().split())
if m%a==0:
v=m//a
else:
v=m//a+1
if n%a==0:
v2=n//a
else:
v2=n//a+1
print(v*v2)
``` | -1 |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output": "4"
},
{
"input": "8 8 2 2 2",
"output": "6"
},
{
"input": "5 50 5 5 60",
"output": "110"
},
{
"input": "100 100 100 100 100",
"output": "200"
},
{
"input": "1 1 1 1 1",
"output": "2"
},
{
"input": "29 29 20 20 20",
"output": "58"
},
{
"input": "20 29 20 29 20",
"output": "58"
},
{
"input": "31 31 20 20 20",
"output": "60"
},
{
"input": "20 20 20 31 31",
"output": "60"
},
{
"input": "20 31 20 31 20",
"output": "60"
},
{
"input": "20 20 20 30 30",
"output": "60"
},
{
"input": "30 30 20 20 20",
"output": "60"
},
{
"input": "8 1 8 8 8",
"output": "9"
},
{
"input": "1 1 1 8 1",
"output": "9"
},
{
"input": "1 2 3 4 5",
"output": "15"
},
{
"input": "100 99 98 97 96",
"output": "490"
},
{
"input": "1 1 100 100 100",
"output": "2"
},
{
"input": "100 100 99 99 98",
"output": "296"
},
{
"input": "98 99 100 99 100",
"output": "296"
},
{
"input": "1 90 1 91 1",
"output": "181"
},
{
"input": "60 1 75 1 92",
"output": "227"
},
{
"input": "15 40 90 40 90",
"output": "95"
},
{
"input": "1 1 15 20 20",
"output": "17"
},
{
"input": "90 11 11 10 10",
"output": "110"
},
{
"input": "20 21 22 23 24",
"output": "110"
},
{
"input": "1 1 2 98 99",
"output": "199"
},
{
"input": "3 7 7 7 10",
"output": "13"
},
{
"input": "1 3 3 3 1",
"output": "2"
},
{
"input": "1 9 9 9 10",
"output": "11"
},
{
"input": "100 1 1 1 1",
"output": "101"
},
{
"input": "2 2 2 100 100",
"output": "6"
},
{
"input": "1 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2 2 5",
"output": "7"
},
{
"input": "1 2 3 4 1",
"output": "9"
},
{
"input": "11 10 10 10 10",
"output": "21"
},
{
"input": "2 2 2 10 10",
"output": "6"
},
{
"input": "1 1 1 1 4",
"output": "5"
},
{
"input": "98 98 98 98 23",
"output": "121"
},
{
"input": "1 2 3 100 100",
"output": "6"
},
{
"input": "2 2 5 10 10",
"output": "9"
},
{
"input": "2 2 3 3 3",
"output": "4"
},
{
"input": "1 1 1 1 2",
"output": "3"
},
{
"input": "12 12 7 7 7",
"output": "21"
}
] | 1,680,609,903 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 62 | 0 | import math
from collections import defaultdict
def I(): return int(input())
def II(): return map(int, input().split())
def IL(): return list(map(int, input().split()))
def SIL(): return sorted(map(int, input().split()))
def solve():
nums=IL()
nums.sort()
# obj=defaultdict(bool)
max_=0
sum=0
for i in range(len(nums)-1):
j=i+1
count=1
while j<len(nums) and nums[i]>=nums[j]:
if count<3:
count+=1
j+=1
if count!=1:
count=count*nums[i]
max_=max(max_,count)
for i in range(len(nums)):
sum+=nums[i]
print(sum-max_)
# T = I()
T=1
for _ in range(T):
solve()
#3,3,7,7,20 | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
Input Specification:
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Output Specification:
Print the minimum possible sum of numbers written on remaining cards.
Demo Input:
['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n']
Demo Output:
['26\n', '28\n', '20\n']
Note:
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | ```python
import math
from collections import defaultdict
def I(): return int(input())
def II(): return map(int, input().split())
def IL(): return list(map(int, input().split()))
def SIL(): return sorted(map(int, input().split()))
def solve():
nums=IL()
nums.sort()
# obj=defaultdict(bool)
max_=0
sum=0
for i in range(len(nums)-1):
j=i+1
count=1
while j<len(nums) and nums[i]>=nums[j]:
if count<3:
count+=1
j+=1
if count!=1:
count=count*nums[i]
max_=max(max_,count)
for i in range(len(nums)):
sum+=nums[i]
print(sum-max_)
# T = I()
T=1
for _ in range(T):
solve()
#3,3,7,7,20
``` | 3 |
|
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1",
"output": "0 0 0 0 0 0 0 0 0 -1 "
},
{
"input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 0 0 0 0 0 0 0 0 1000000000 "
},
{
"input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12",
"output": "656 -110 5840 6358 828 717 7359 7628 22 -12 "
},
{
"input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240",
"output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 "
}
] | 1,579,380,848 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 8,499,200 | n=int(input())
l=list(map(int,input().split()))
emp=[]
for i in range(n-1,-1,-1):
c=l[i]
for j in range(1,n-i):
c+=(-1)**(j+1)*(l[i+j])
l[i]=c
print(*l) | Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Output Specification:
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
Demo Input:
['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n']
Demo Output:
['2 4 6 1 3 \n', '1 -3 4 11 6 \n']
Note:
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | ```python
n=int(input())
l=list(map(int,input().split()))
emp=[]
for i in range(n-1,-1,-1):
c=l[i]
for j in range(1,n-i):
c+=(-1)**(j+1)*(l[i+j])
l[i]=c
print(*l)
``` | 0 |
|
55 | C | Pie or die | PROGRAMMING | 1,900 | [
"games"
] | C. Pie or die | 2 | 256 | Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. | First line contains 3 integers, separated by space: 1<=≤<=*n*,<=*m*<=≤<=100 — dimensions of the board and 0<=≤<=*k*<=≤<=100 — the number of pies. Each of the next *k* lines contains 2 integers, separated by space: 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* — coordinates of the corresponding pie. There could be more than one pie at a cell. | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | [
"2 2 1\n1 2\n",
"3 4 0\n",
"100 50 2\n50 25\n50 25\n"
] | [
"YES",
"NO",
"NO"
] | none | 1,500 | [
{
"input": "2 2 1\n1 2",
"output": "YES"
},
{
"input": "3 4 0",
"output": "NO"
},
{
"input": "100 50 2\n50 25\n50 25",
"output": "NO"
},
{
"input": "20 20 4\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "15 15 1\n8 8",
"output": "NO"
},
{
"input": "8 8 2\n4 4\n5 5",
"output": "YES"
},
{
"input": "100 100 2\n50 96\n51 96",
"output": "YES"
},
{
"input": "100 100 2\n50 95\n51 95",
"output": "NO"
},
{
"input": "20 20 1\n16 10",
"output": "YES"
},
{
"input": "20 20 4\n15 9\n15 10\n15 11\n15 12",
"output": "NO"
},
{
"input": "11 11 1\n6 6",
"output": "NO"
},
{
"input": "11 11 1\n6 5",
"output": "YES"
},
{
"input": "35 13 20\n13 8\n19 8\n24 7\n20 6\n23 7\n23 6\n30 7\n29 7\n7 7\n6 8\n9 8\n29 6\n20 7\n25 6\n19 6\n23 8\n26 6\n12 6\n15 7\n6 8",
"output": "NO"
},
{
"input": "50 17 27\n17 8\n19 6\n25 8\n30 10\n22 10\n30 9\n25 8\n27 6\n19 7\n29 11\n39 8\n31 8\n39 8\n40 7\n11 8\n30 11\n32 8\n31 11\n36 12\n10 11\n32 8\n8 7\n7 12\n17 11\n27 7\n8 8\n23 12",
"output": "NO"
},
{
"input": "24 29 22\n16 6\n14 22\n7 15\n11 17\n12 22\n10 13\n12 22\n12 13\n6 16\n12 21\n11 11\n9 13\n18 22\n7 20\n13 6\n6 14\n17 10\n9 13\n7 23\n14 11\n7 22\n8 12",
"output": "NO"
},
{
"input": "32 45 3\n12 30\n27 9\n14 27",
"output": "NO"
},
{
"input": "35 15 63\n6 6\n14 9\n7 6\n25 6\n25 8\n13 9\n18 7\n20 8\n30 10\n25 10\n7 7\n18 8\n11 10\n12 6\n8 8\n6 9\n21 9\n27 10\n28 8\n28 9\n7 9\n28 9\n10 10\n29 10\n25 8\n28 7\n22 6\n13 9\n14 7\n23 9\n20 8\n28 10\n22 7\n12 8\n13 7\n27 9\n17 8\n10 8\n19 10\n6 10\n26 6\n19 8\n28 9\n15 9\n14 7\n25 10\n17 8\n21 8\n29 6\n7 6\n16 10\n7 10\n25 7\n9 9\n30 9\n23 8\n28 8\n7 10\n12 6\n20 9\n24 8\n6 6\n26 7",
"output": "NO"
},
{
"input": "41 50 37\n21 24\n20 32\n10 12\n35 7\n8 19\n30 22\n21 11\n35 12\n7 8\n16 10\n13 39\n6 43\n31 12\n16 14\n25 32\n27 21\n6 34\n22 26\n7 41\n18 13\n24 19\n9 44\n36 21\n17 16\n36 24\n6 31\n19 20\n12 19\n27 36\n6 31\n11 13\n19 9\n20 12\n25 25\n18 27\n17 36\n8 16",
"output": "NO"
},
{
"input": "96 95 31\n14 23\n70 47\n11 77\n53 66\n63 87\n3 14\n57 44\n65 69\n80 74\n49 6\n57 86\n75 8\n2 32\n75 21\n14 51\n56 46\n77 6\n17 89\n87 3\n21 18\n70 67\n47 64\n13 47\n61 33\n56 30\n28 2\n65 18\n17 90\n44 77\n54 26\n32 70",
"output": "YES"
},
{
"input": "80 51 47\n67 41\n74 7\n68 41\n6 2\n19 38\n37 28\n65 4\n6 25\n39 11\n19 34\n47 36\n62 26\n27 44\n70 45\n24 33\n41 2\n13 10\n3 17\n78 35\n53 46\n62 47\n33 17\n17 49\n2 3\n47 38\n72 35\n4 8\n32 21\n52 43\n67 12\n28 22\n53 34\n36 11\n45 45\n32 12\n5 11\n6 3\n55 21\n73 4\n55 21\n36 13\n48 18\n19 8\n70 24\n43 45\n59 50\n58 7",
"output": "YES"
},
{
"input": "25 92 38\n21 36\n20 18\n9 29\n18 77\n10 58\n10 39\n5 3\n21 51\n11 78\n16 32\n24 71\n15 17\n23 23\n25 59\n18 57\n11 2\n16 35\n1 47\n20 59\n19 54\n11 55\n4 33\n15 41\n17 18\n16 67\n4 15\n5 23\n3 24\n20 70\n5 87\n11 1\n23 66\n21 83\n2 32\n17 22\n2 26\n16 42\n24 15",
"output": "YES"
},
{
"input": "67 41 68\n35 16\n66 14\n1 15\n43 6\n26 17\n30 13\n42 11\n32 20\n66 14\n15 35\n35 6\n12 11\n25 9\n39 37\n31 14\n52 11\n4 32\n17 14\n32 1\n58 31\n30 20\n7 23\n13 3\n27 25\n60 27\n56 39\n60 39\n11 5\n33 14\n29 12\n13 34\n30 16\n25 16\n64 25\n47 6\n33 36\n14 40\n19 38\n57 34\n67 8\n10 13\n7 36\n22 24\n6 33\n23 40\n13 19\n65 6\n14 37\n37 21\n27 12\n41 36\n60 15\n27 11\n23 33\n67 40\n45 39\n1 41\n50 21\n28 38\n20 24\n41 34\n43 35\n51 5\n59 37\n27 4\n28 17\n63 20\n1 9",
"output": "YES"
},
{
"input": "14 95 49\n11 48\n9 12\n1 18\n7 54\n11 20\n9 82\n12 1\n12 84\n1 13\n2 13\n12 57\n13 15\n12 18\n9 47\n13 14\n10 14\n13 94\n7 46\n14 14\n6 46\n7 95\n9 29\n13 15\n6 76\n8 60\n6 27\n9 63\n5 39\n5 70\n10 59\n5 75\n3 19\n9 32\n13 59\n5 13\n4 5\n13 80\n10 62\n13 65\n5 25\n4 81\n7 12\n10 94\n8 55\n7 61\n11 58\n7 77\n12 14\n12 47",
"output": "YES"
},
{
"input": "15 96 22\n4 7\n7 40\n13 30\n8 53\n6 78\n5 9\n15 35\n3 13\n5 31\n2 9\n13 50\n11 17\n4 2\n10 91\n11 74\n14 49\n8 30\n10 66\n12 44\n6 19\n9 62\n15 50",
"output": "YES"
},
{
"input": "19 19 50\n11 16\n4 11\n5 12\n19 19\n7 16\n15 10\n8 17\n8 1\n11 10\n5 19\n5 14\n17 6\n12 15\n18 17\n17 14\n10 5\n15 11\n8 8\n5 8\n18 18\n7 11\n8 4\n11 9\n6 16\n1 15\n19 13\n5 12\n10 10\n4 19\n12 4\n8 14\n19 9\n7 1\n19 11\n15 8\n4 19\n19 9\n6 7\n15 7\n2 16\n12 9\n3 18\n17 10\n3 5\n11 7\n12 6\n4 15\n19 4\n17 15\n3 10",
"output": "YES"
},
{
"input": "93 40 43\n14 15\n58 9\n72 15\n40 40\n46 20\n17 26\n31 26\n91 36\n24 28\n32 27\n51 10\n2 35\n73 7\n6 33\n59 21\n59 39\n33 8\n22 21\n77 20\n30 38\n76 35\n40 6\n48 31\n67 29\n30 24\n6 16\n39 27\n24 29\n14 16\n5 25\n76 14\n61 25\n85 13\n60 9\n80 7\n49 19\n35 20\n90 31\n57 40\n67 27\n3 27\n21 16\n21 38",
"output": "YES"
},
{
"input": "70 50 62\n31 22\n41 21\n31 47\n2 46\n22 8\n6 4\n45 32\n40 29\n10 11\n62 40\n70 26\n48 25\n13 44\n53 22\n3 8\n41 19\n13 8\n21 41\n66 20\n34 34\n41 48\n9 35\n23 26\n29 30\n39 27\n58 11\n35 2\n67 3\n59 23\n41 10\n54 9\n10 18\n23 44\n5 2\n37 30\n31 24\n2 21\n2 36\n34 5\n59 44\n7 4\n23 22\n47 27\n14 50\n54 50\n6 4\n64 1\n29 5\n5 37\n60 50\n58 45\n70 4\n4 46\n68 43\n62 34\n15 12\n16 2\n70 21\n59 8\n13 27\n25 41\n13 20",
"output": "YES"
},
{
"input": "61 96 15\n27 36\n19 64\n27 53\n59 63\n48 56\n55 30\n10 23\n6 79\n32 74\n7 51\n29 65\n60 16\n43 74\n40 80\n14 31",
"output": "YES"
},
{
"input": "87 50 62\n34 31\n42 21\n2 23\n20 25\n57 39\n46 26\n59 46\n29 33\n32 35\n79 41\n54 19\n65 7\n41 6\n40 23\n8 41\n2 31\n56 5\n37 33\n63 23\n79 4\n85 27\n53 38\n58 21\n16 11\n15 46\n33 39\n38 6\n27 41\n6 15\n25 47\n58 16\n28 50\n43 38\n48 20\n5 48\n31 6\n8 18\n40 10\n32 29\n44 20\n42 46\n63 21\n18 10\n28 49\n66 26\n64 28\n73 23\n16 29\n48 12\n23 21\n84 14\n10 45\n75 37\n80 3\n75 24\n31 25\n8 42\n67 22\n80 45\n8 31\n16 28\n49 34",
"output": "YES"
},
{
"input": "23 100 53\n16 63\n16 31\n8 31\n4 86\n8 43\n8 27\n21 6\n13 49\n11 54\n5 86\n1 41\n19 14\n2 98\n15 76\n6 25\n6 57\n2 45\n6 98\n10 27\n16 74\n22 72\n22 13\n22 20\n15 63\n18 17\n14 32\n14 32\n2 28\n7 46\n23 16\n20 64\n18 17\n3 69\n22 77\n2 98\n11 20\n22 17\n21 8\n19 77\n19 13\n18 25\n9 24\n18 83\n19 27\n7 37\n16 19\n9 60\n11 70\n3 30\n4 84\n9 54\n22 33\n3 22",
"output": "YES"
},
{
"input": "36 89 27\n21 66\n3 60\n11 32\n10 81\n30 31\n27 62\n11 81\n24 41\n30 6\n13 45\n34 86\n26 46\n9 62\n8 86\n17 56\n4 86\n25 36\n23 72\n18 55\n18 87\n22 67\n18 12\n19 75\n21 60\n16 49\n33 63\n26 12",
"output": "YES"
},
{
"input": "93 93 50\n7 5\n73 91\n66 55\n12 24\n82 46\n38 49\n86 72\n51 69\n17 73\n9 85\n86 69\n65 2\n40 88\n92 26\n45 80\n74 45\n4 55\n57 93\n80 70\n49 69\n29 46\n67 38\n46 12\n16 87\n62 3\n79 62\n29 45\n58 30\n48 4\n76 73\n14 68\n31 8\n49 85\n73 78\n18 7\n87 56\n82 54\n52 73\n29 71\n87 74\n75 84\n45 28\n47 57\n44 53\n21 5\n86 5\n57 51\n45 9\n93 8\n82 43",
"output": "YES"
},
{
"input": "11 38 21\n2 21\n2 28\n7 19\n9 18\n7 25\n8 4\n3 23\n2 32\n5 34\n10 36\n8 21\n4 6\n6 6\n4 35\n8 34\n10 18\n11 4\n10 2\n10 13\n4 37\n2 29",
"output": "YES"
},
{
"input": "26 11 59\n13 6\n18 6\n12 6\n18 6\n21 6\n19 6\n12 6\n7 6\n6 6\n16 6\n7 6\n9 6\n19 6\n19 6\n15 6\n16 6\n16 6\n18 6\n17 6\n8 6\n13 6\n18 6\n11 6\n21 6\n9 6\n19 6\n20 6\n8 6\n20 6\n14 6\n11 6\n18 6\n7 6\n16 6\n19 6\n6 6\n6 6\n7 6\n13 6\n9 6\n16 6\n9 6\n15 6\n12 6\n17 6\n16 6\n9 6\n11 6\n10 6\n16 6\n14 6\n15 6\n7 6\n20 6\n7 6\n8 6\n17 6\n14 6\n14 6",
"output": "NO"
},
{
"input": "30 84 35\n20 60\n23 21\n14 24\n24 72\n13 76\n25 35\n11 64\n15 57\n9 55\n14 66\n10 24\n13 68\n11 8\n19 43\n11 14\n16 26\n11 22\n10 26\n15 66\n17 65\n21 34\n7 61\n24 64\n18 16\n22 18\n12 9\n10 40\n8 24\n16 52\n10 9\n7 17\n21 78\n18 75\n10 45\n16 29",
"output": "NO"
},
{
"input": "100 77 53\n62 72\n23 51\n42 8\n66 33\n62 16\n28 53\n72 54\n71 34\n30 26\n91 28\n27 37\n81 47\n22 40\n42 23\n92 46\n36 37\n86 70\n62 22\n20 9\n46 36\n86 67\n46 61\n33 30\n68 49\n44 57\n34 7\n89 36\n48 39\n47 62\n76 56\n22 41\n7 52\n16 8\n70 50\n52 27\n27 17\n44 30\n66 44\n62 10\n95 37\n94 39\n91 68\n12 49\n85 55\n63 28\n64 15\n75 31\n93 26\n53 51\n53 55\n66 65\n38 36\n40 15",
"output": "NO"
},
{
"input": "66 94 26\n11 75\n46 72\n55 74\n34 10\n33 84\n25 11\n13 23\n27 73\n45 22\n54 34\n53 63\n28 8\n57 46\n26 78\n52 46\n32 38\n22 55\n17 71\n56 18\n9 60\n31 54\n6 84\n59 57\n60 81\n51 49\n41 77",
"output": "NO"
},
{
"input": "68 100 18\n17 85\n10 77\n59 55\n29 46\n25 74\n55 11\n37 16\n57 61\n26 11\n11 88\n19 18\n28 38\n32 12\n36 49\n32 6\n57 45\n30 6\n59 95",
"output": "NO"
},
{
"input": "28 61 4\n12 18\n21 31\n14 52\n6 36",
"output": "NO"
},
{
"input": "11 73 1\n4 67",
"output": "YES"
},
{
"input": "11 79 0",
"output": "NO"
},
{
"input": "11 23 1\n11 9",
"output": "YES"
},
{
"input": "25 11 0",
"output": "NO"
},
{
"input": "39 11 1\n18 3",
"output": "YES"
},
{
"input": "69 11 0",
"output": "NO"
},
{
"input": "18 15 45\n6 7\n7 14\n12 3\n17 1\n15 3\n7 11\n9 3\n7 11\n15 4\n8 1\n12 2\n17 7\n14 15\n2 9\n12 4\n14 9\n18 8\n2 2\n17 1\n7 9\n2 4\n16 1\n12 7\n17 10\n4 1\n18 13\n10 13\n9 12\n14 1\n1 6\n3 10\n6 2\n15 3\n4 8\n14 6\n5 14\n8 11\n8 13\n6 7\n16 9\n2 7\n17 14\n17 11\n7 9\n15 8",
"output": "YES"
},
{
"input": "16 18 70\n14 17\n16 8\n14 1\n7 1\n5 3\n7 5\n15 15\n15 2\n8 17\n12 12\n8 7\n10 16\n16 6\n14 7\n2 7\n12 4\n1 9\n6 9\n1 10\n10 13\n7 11\n2 2\n9 5\n3 10\n14 7\n4 5\n2 7\n7 16\n5 7\n7 14\n14 6\n10 16\n8 1\n4 14\n3 15\n8 11\n3 16\n12 1\n10 12\n13 3\n14 17\n5 5\n6 8\n13 10\n11 13\n3 5\n15 7\n10 3\n6 12\n13 15\n7 5\n3 8\n7 18\n6 7\n15 1\n9 6\n6 17\n11 2\n2 17\n7 16\n6 6\n2 18\n2 10\n5 16\n7 17\n3 8\n15 2\n11 11\n5 13\n16 1",
"output": "YES"
},
{
"input": "14 20 68\n6 7\n2 15\n4 6\n10 18\n6 9\n14 14\n5 18\n9 15\n5 15\n2 9\n9 13\n10 17\n4 2\n12 12\n6 19\n7 13\n10 11\n1 1\n3 16\n7 6\n8 16\n10 17\n1 13\n12 11\n13 13\n2 20\n14 12\n11 18\n10 8\n12 4\n13 7\n13 11\n1 1\n10 6\n14 17\n1 2\n11 5\n6 12\n13 2\n4 3\n8 19\n12 8\n8 7\n5 1\n2 10\n11 10\n12 19\n2 10\n8 4\n12 13\n3 15\n8 8\n5 9\n14 15\n5 19\n7 7\n1 16\n6 12\n11 18\n5 13\n1 12\n10 14\n4 5\n2 8\n3 20\n14 7\n6 3\n4 18",
"output": "YES"
},
{
"input": "19 13 83\n5 2\n12 11\n5 6\n3 11\n17 8\n10 8\n3 10\n9 10\n16 3\n15 12\n14 2\n11 8\n18 6\n15 10\n11 12\n2 1\n15 3\n16 3\n1 7\n15 7\n2 9\n11 13\n18 9\n4 7\n13 4\n7 4\n3 1\n14 8\n4 5\n5 7\n8 3\n17 2\n18 2\n16 3\n10 12\n6 2\n3 6\n5 2\n10 3\n18 9\n14 3\n3 6\n6 5\n12 8\n7 12\n2 11\n6 6\n18 6\n14 4\n3 10\n3 2\n13 3\n12 9\n2 10\n15 6\n1 5\n9 12\n6 12\n4 6\n18 3\n7 2\n9 13\n3 10\n19 13\n6 7\n5 1\n4 10\n12 13\n8 12\n15 1\n4 3\n3 8\n4 8\n3 7\n4 13\n8 7\n7 13\n2 8\n14 6\n12 1\n16 8\n9 4\n5 8",
"output": "YES"
},
{
"input": "13 19 1\n6 10",
"output": "NO"
},
{
"input": "14 17 0",
"output": "NO"
},
{
"input": "20 19 5\n7 14\n14 12\n7 12\n15 9\n12 6",
"output": "NO"
},
{
"input": "17 15 3\n10 7\n12 6\n8 6",
"output": "NO"
},
{
"input": "14 17 4\n9 9\n8 7\n8 12\n7 9",
"output": "NO"
},
{
"input": "15 11 0",
"output": "NO"
},
{
"input": "14 16 4\n6 11\n6 8\n8 6\n6 7",
"output": "NO"
},
{
"input": "16 16 0",
"output": "NO"
},
{
"input": "19 20 2\n10 14\n8 11",
"output": "NO"
},
{
"input": "13 15 1\n7 10",
"output": "NO"
},
{
"input": "11 100 4\n6 10\n6 20\n6 30\n6 80",
"output": "NO"
},
{
"input": "100 11 2\n40 6\n70 6",
"output": "NO"
},
{
"input": "100 11 5\n20 6\n30 6\n43 7\n78 6\n89 6",
"output": "YES"
},
{
"input": "20 20 5\n10 6\n6 8\n16 11\n11 11\n7 15",
"output": "YES"
},
{
"input": "30 30 5\n7 15\n24 11\n15 15\n8 24\n9 6",
"output": "NO"
}
] | 1,497,287,230 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | a = int(input())
b = int(input())
n = int(input())
T = 0
for i in range(n):
x = int(input())
y = int(input())
if a - x > 4 or b - y > 4:
T = 0
else:
T = 1
if T:
print ("YES")
else:
print("NO")
| Title: Pie or die
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy.
Input Specification:
First line contains 3 integers, separated by space: 1<=≤<=*n*,<=*m*<=≤<=100 — dimensions of the board and 0<=≤<=*k*<=≤<=100 — the number of pies. Each of the next *k* lines contains 2 integers, separated by space: 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* — coordinates of the corresponding pie. There could be more than one pie at a cell.
Output Specification:
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
Demo Input:
['2 2 1\n1 2\n', '3 4 0\n', '100 50 2\n50 25\n50 25\n']
Demo Output:
['YES', 'NO', 'NO']
Note:
none | ```python
a = int(input())
b = int(input())
n = int(input())
T = 0
for i in range(n):
x = int(input())
y = int(input())
if a - x > 4 or b - y > 4:
T = 0
else:
T = 1
if T:
print ("YES")
else:
print("NO")
``` | -1 |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314",
"output": "1762894"
},
{
"input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585",
"output": "2960349"
},
{
"input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933",
"output": "99140444"
},
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686",
"output": "301124161"
},
{
"input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495",
"output": "30125295"
},
{
"input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165",
"output": "136422"
},
{
"input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348",
"output": "2578628"
},
{
"input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338",
"output": "9168707"
},
{
"input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657",
"output": "144901921"
},
{
"input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860",
"output": "809931"
},
{
"input": "a\n0\n5 1 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": "5"
},
{
"input": "lol\n3\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",
"output": "21"
}
] | 1,645,311,797 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | s = input()
n = int(input())
l = list(map(int, input().split()))
size = s.index(s[-1]) + 1
max = max(l)
ans = 0
for i in range(size+1,n*2+1):
ans += (i * max)
for character in s:
temp = s.index(character) + 1
ans += (temp * l[temp-1])
print(ans) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input Specification:
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Output Specification:
Print a single integer — the largest possible value of the resulting string DZY could get.
Demo Input:
['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n']
Demo Output:
['41\n']
Note:
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | ```python
s = input()
n = int(input())
l = list(map(int, input().split()))
size = s.index(s[-1]) + 1
max = max(l)
ans = 0
for i in range(size+1,n*2+1):
ans += (i * max)
for character in s:
temp = s.index(character) + 1
ans += (temp * l[temp-1])
print(ans)
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,671,255,711 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n = map(int, input().split())
a = m * n
if a % 2 == 0:
print(int(a / 2))
else:
a = a - 1
print(int(a / 2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m,n = map(int, input().split())
a = m * n
if a % 2 == 0:
print(int(a / 2))
else:
a = a - 1
print(int(a / 2))
``` | 3.977 |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": "919067153",
"output": "5"
},
{
"input": "690422411",
"output": "7"
},
{
"input": "-408490162",
"output": "1"
},
{
"input": "-8",
"output": "16"
},
{
"input": "-6",
"output": "14"
},
{
"input": "-4",
"output": "12"
},
{
"input": "-2",
"output": "10"
},
{
"input": "0",
"output": "8"
},
{
"input": "2",
"output": "6"
},
{
"input": "4",
"output": "4"
},
{
"input": "6",
"output": "2"
},
{
"input": "8",
"output": "10"
},
{
"input": "1000000000",
"output": "8"
},
{
"input": "-1000000000",
"output": "2"
},
{
"input": "88888",
"output": "1"
},
{
"input": "89",
"output": "9"
},
{
"input": "-80000000",
"output": "2"
},
{
"input": "-8888",
"output": "1"
},
{
"input": "-17",
"output": "9"
},
{
"input": "78",
"output": "2"
},
{
"input": "-19",
"output": "1"
},
{
"input": "-999999998",
"output": "9"
},
{
"input": "-999999997",
"output": "8"
},
{
"input": "999999997",
"output": "1"
},
{
"input": "811111111",
"output": "1"
},
{
"input": "-8",
"output": "16"
},
{
"input": "-5",
"output": "13"
},
{
"input": "-7",
"output": "15"
},
{
"input": "1000000000",
"output": "8"
}
] | 1,652,610,010 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 4,300,800 | n = int(input())
i = 0
for i in range(16):
n += 1
i += 1
if '8' in str(n):
break
print(i) | Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
Input Specification:
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Output Specification:
Print the minimum *b* in a line.
Demo Input:
['179\n', '-1\n', '18\n']
Demo Output:
['1\n', '9\n', '10\n']
Note:
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | ```python
n = int(input())
i = 0
for i in range(16):
n += 1
i += 1
if '8' in str(n):
break
print(i)
``` | 3 |
|
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6].
Write a program that checks if an array is unimodal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input": "1\n7",
"output": "YES"
},
{
"input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527",
"output": "YES"
},
{
"input": "5\n5 5 6 6 1",
"output": "NO"
},
{
"input": "3\n4 4 2",
"output": "YES"
},
{
"input": "4\n4 5 5 6",
"output": "NO"
},
{
"input": "3\n516 516 515",
"output": "YES"
},
{
"input": "5\n502 503 508 508 507",
"output": "YES"
},
{
"input": "10\n538 538 538 538 538 538 538 538 538 538",
"output": "YES"
},
{
"input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426",
"output": "YES"
},
{
"input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513",
"output": "YES"
},
{
"input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337",
"output": "YES"
},
{
"input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479",
"output": "YES"
},
{
"input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393",
"output": "YES"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543",
"output": "YES"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521",
"output": "YES"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504",
"output": "YES"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496",
"output": "YES"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173",
"output": "YES"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333",
"output": "YES"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1",
"output": "YES"
},
{
"input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999",
"output": "NO"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543",
"output": "NO"
},
{
"input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527",
"output": "NO"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521",
"output": "NO"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504",
"output": "NO"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496",
"output": "NO"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173",
"output": "NO"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n2 1 1",
"output": "NO"
},
{
"input": "3\n2 1 2",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346",
"output": "YES"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475",
"output": "YES"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271",
"output": "YES"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346",
"output": "NO"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475",
"output": "NO"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271",
"output": "YES"
},
{
"input": "2\n1 3",
"output": "YES"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "5\n2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n1 3 2 2",
"output": "NO"
},
{
"input": "6\n1 2 1 2 2 1",
"output": "NO"
},
{
"input": "2\n4 2",
"output": "YES"
},
{
"input": "3\n3 2 2",
"output": "NO"
},
{
"input": "9\n1 2 2 3 3 4 3 2 1",
"output": "NO"
},
{
"input": "4\n5 5 4 4",
"output": "NO"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "5\n5 4 3 2 1",
"output": "YES"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 2 3 4 5",
"output": "YES"
},
{
"input": "3\n2 2 1",
"output": "YES"
},
{
"input": "3\n4 3 3",
"output": "NO"
},
{
"input": "7\n1 5 5 4 3 3 1",
"output": "NO"
},
{
"input": "6\n3 3 1 2 2 1",
"output": "NO"
},
{
"input": "5\n1 2 1 2 1",
"output": "NO"
},
{
"input": "2\n5 1",
"output": "YES"
},
{
"input": "9\n1 2 3 4 4 3 2 2 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "2\n5 4",
"output": "YES"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 99",
"output": "YES"
},
{
"input": "4\n1 2 3 4",
"output": "YES"
},
{
"input": "3\n5 5 2",
"output": "YES"
},
{
"input": "4\n1 4 2 3",
"output": "NO"
},
{
"input": "2\n3 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 1",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 2 3 2 2",
"output": "NO"
},
{
"input": "5\n5 6 6 5 5",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n5 4 3 3 2",
"output": "NO"
},
{
"input": "7\n1 3 3 3 2 1 1",
"output": "NO"
},
{
"input": "9\n5 6 6 5 5 4 4 3 3",
"output": "NO"
},
{
"input": "6\n1 5 5 3 2 2",
"output": "NO"
},
{
"input": "5\n2 1 3 3 1",
"output": "NO"
},
{
"input": "2\n4 3",
"output": "YES"
},
{
"input": "5\n3 2 2 1 1",
"output": "NO"
},
{
"input": "4\n5 4 3 2",
"output": "YES"
},
{
"input": "4\n4 4 1 1",
"output": "NO"
},
{
"input": "4\n3 3 1 1",
"output": "NO"
},
{
"input": "4\n4 4 2 2",
"output": "NO"
},
{
"input": "5\n4 4 3 2 2",
"output": "NO"
},
{
"input": "8\n4 4 4 4 5 6 7 8",
"output": "NO"
},
{
"input": "5\n3 5 4 4 3",
"output": "NO"
},
{
"input": "6\n2 5 3 3 2 2",
"output": "NO"
},
{
"input": "4\n5 5 2 2",
"output": "NO"
},
{
"input": "5\n1 2 2 3 5",
"output": "NO"
}
] | 1,640,575,151 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | x, lst = int(input()), input().split()
l = [int(ch) for ch in l]
def is_modal(x, l):
i = 1
for i in range(i,x):
if not (l[i - 1] < l[i]):
break
else:
return "Yes"
for i in range(i,x):
if not (l[i - 1] == l[i]):
break
else:
return "Yes"
for i in range(i,x):
if not (l[i - 1] > l[i]):
return "No"
else:
return "Yes"
print(is_modal(x,l)) | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6].
Write a program that checks if an array is unimodal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array.
Output Specification:
Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Demo Input:
['6\n1 5 5 5 4 2\n', '5\n10 20 30 20 10\n', '4\n1 2 1 2\n', '7\n3 3 3 3 3 3 3\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | ```python
x, lst = int(input()), input().split()
l = [int(ch) for ch in l]
def is_modal(x, l):
i = 1
for i in range(i,x):
if not (l[i - 1] < l[i]):
break
else:
return "Yes"
for i in range(i,x):
if not (l[i - 1] == l[i]):
break
else:
return "Yes"
for i in range(i,x):
if not (l[i - 1] > l[i]):
return "No"
else:
return "Yes"
print(is_modal(x,l))
``` | -1 |
|
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 45 45 45 45 45 45 45",
"output": "0"
},
{
"input": "3\n120 120 120",
"output": "120"
},
{
"input": "5\n110 90 70 50 40",
"output": "40"
},
{
"input": "2\n170 190",
"output": "20"
},
{
"input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10",
"output": "10"
},
{
"input": "5\n30 60 180 60 30",
"output": "0"
},
{
"input": "2\n359 1",
"output": "358"
},
{
"input": "5\n100 100 30 100 30",
"output": "40"
},
{
"input": "5\n36 34 35 11 244",
"output": "128"
},
{
"input": "5\n96 94 95 71 4",
"output": "18"
},
{
"input": "2\n85 275",
"output": "190"
},
{
"input": "3\n281 67 12",
"output": "202"
},
{
"input": "5\n211 113 25 9 2",
"output": "62"
},
{
"input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1",
"output": "212"
},
{
"input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "92"
},
{
"input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 358",
"output": "356"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341",
"output": "322"
},
{
"input": "33\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 328",
"output": "296"
},
{
"input": "70\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291",
"output": "222"
},
{
"input": "130\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 231",
"output": "102"
},
{
"input": "200\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 161",
"output": "0"
},
{
"input": "222\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 139",
"output": "0"
},
{
"input": "10\n8 3 11 4 1 10 10 1 8 304",
"output": "248"
},
{
"input": "12\n8 7 7 3 11 2 10 1 10 8 10 283",
"output": "206"
},
{
"input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275",
"output": "190"
},
{
"input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280",
"output": "200"
},
{
"input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275",
"output": "190"
},
{
"input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189",
"output": "18"
},
{
"input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189",
"output": "18"
},
{
"input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168",
"output": "0"
},
{
"input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5",
"output": "0"
},
{
"input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68",
"output": "0"
},
{
"input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "6\n27 15 28 34 41 215",
"output": "70"
},
{
"input": "7\n41 38 41 31 22 41 146",
"output": "14"
},
{
"input": "8\n24 27 34 23 29 23 30 170",
"output": "20"
},
{
"input": "9\n11 11 20 20 33 32 35 26 172",
"output": "6"
},
{
"input": "10\n36 13 28 13 33 34 23 25 34 121",
"output": "0"
},
{
"input": "11\n19 37 13 41 37 15 32 12 19 35 100",
"output": "10"
},
{
"input": "12\n37 25 34 38 21 24 34 38 11 29 28 41",
"output": "2"
},
{
"input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28",
"output": "2"
},
{
"input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44",
"output": "4"
},
{
"input": "3\n95 91 174",
"output": "12"
},
{
"input": "4\n82 75 78 125",
"output": "46"
},
{
"input": "6\n87 75 88 94 15 1",
"output": "4"
},
{
"input": "10\n27 52 58 64 45 64 1 19 2 28",
"output": "12"
},
{
"input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1",
"output": "0"
},
{
"input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3",
"output": "0"
},
{
"input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1",
"output": "0"
},
{
"input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2",
"output": "0"
},
{
"input": "5\n35 80 45 100 100",
"output": "40"
},
{
"input": "4\n90 179 90 1",
"output": "2"
},
{
"input": "5\n50 50 20 160 80",
"output": "0"
},
{
"input": "5\n30 175 30 5 120",
"output": "10"
},
{
"input": "4\n170 30 10 150",
"output": "20"
},
{
"input": "6\n90 30 90 30 90 30",
"output": "60"
},
{
"input": "4\n70 80 110 100",
"output": "20"
},
{
"input": "7\n35 45 70 100 10 10 90",
"output": "0"
},
{
"input": "6\n50 90 10 90 20 100",
"output": "20"
},
{
"input": "6\n10 155 162 1 26 6",
"output": "18"
},
{
"input": "7\n80 90 80 45 10 10 45",
"output": "20"
},
{
"input": "4\n18 36 162 144",
"output": "36"
},
{
"input": "5\n20 50 50 160 80",
"output": "40"
},
{
"input": "5\n10 30 140 20 160",
"output": "0"
},
{
"input": "6\n90 80 60 50 40 40",
"output": "20"
},
{
"input": "9\n40 20 20 20 20 20 20 40 160",
"output": "40"
},
{
"input": "4\n90 54 90 126",
"output": "72"
},
{
"input": "4\n150 170 30 10",
"output": "20"
},
{
"input": "8\n130 12 13 85 41 67 5 7",
"output": "26"
},
{
"input": "7\n70 170 20 10 30 30 30",
"output": "20"
},
{
"input": "8\n100 100 50 50 15 15 15 15",
"output": "40"
},
{
"input": "4\n100 70 80 110",
"output": "20"
},
{
"input": "5\n160 130 40 20 10",
"output": "20"
},
{
"input": "4\n20 149 151 40",
"output": "22"
},
{
"input": "4\n100 10 100 150",
"output": "60"
},
{
"input": "6\n19 64 105 168 1 3",
"output": "16"
},
{
"input": "8\n10 10 70 70 90 90 10 10",
"output": "0"
}
] | 1,575,129,598 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 49 | 140 | 0 | def main():
input()
t = sorted(map(int, input().split()))[::-1]
a = 0
b = 0
for i in t:
if a > b:
b+=i
else:
a+=i
print(abs(a-b))
main() | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Output Specification:
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
Demo Input:
['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n']
Demo Output:
['0\n', '40\n', '360\n', '0\n']
Note:
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | ```python
def main():
input()
t = sorted(map(int, input().split()))[::-1]
a = 0
b = 0
for i in t:
if a > b:
b+=i
else:
a+=i
print(abs(a-b))
main()
``` | 0 |
|
174 | A | Problem About Equation | PROGRAMMING | 1,100 | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | 500 | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
"input": "3 5\n1 2 1",
"output": "2.000000\n1.000000\n2.000000"
},
{
"input": "10 95\n0 0 0 0 0 1 1 1 1 1",
"output": "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000"
},
{
"input": "3 5\n1 2 3",
"output": "2.666667\n1.666667\n0.666667"
},
{
"input": "3 5\n1 3 2",
"output": "2.666667\n0.666667\n1.666667"
},
{
"input": "3 5\n2 1 3",
"output": "1.666667\n2.666667\n0.666667"
},
{
"input": "3 5\n2 3 1",
"output": "1.666667\n0.666667\n2.666667"
},
{
"input": "3 5\n3 1 2",
"output": "0.666667\n2.666667\n1.666667"
},
{
"input": "3 5\n3 2 1",
"output": "0.666667\n1.666667\n2.666667"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "2 1\n2 2",
"output": "0.500000\n0.500000"
},
{
"input": "3 2\n2 1 2",
"output": "0.333333\n1.333333\n0.333333"
},
{
"input": "3 3\n2 2 1",
"output": "0.666667\n0.666667\n1.666667"
},
{
"input": "3 3\n3 1 2",
"output": "0.000000\n2.000000\n1.000000"
},
{
"input": "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72",
"output": "-1"
},
{
"input": "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6",
"output": "-1"
},
{
"input": "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92",
"output": "-1"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99",
"output": "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0..."
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100",
"output": "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0..."
},
{
"input": "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99",
"output": "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1..."
},
{
"input": "10 100\n52 52 51 52 52 52 51 51 52 52",
"output": "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000"
},
{
"input": "10 100\n13 13 13 13 12 13 12 13 12 12",
"output": "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000"
},
{
"input": "10 100\n50 51 47 51 48 46 49 51 46 51",
"output": "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000"
},
{
"input": "10 100\n13 13 9 12 12 11 13 8 10 13",
"output": "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000"
},
{
"input": "93 91\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",
"output": "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0..."
},
{
"input": "93 97\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",
"output": "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1..."
},
{
"input": "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99",
"output": "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1..."
},
{
"input": "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0..."
},
{
"input": "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99",
"output": "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1..."
},
{
"input": "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52",
"output": "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923"
},
{
"input": "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13",
"output": "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118"
},
{
"input": "9 91\n52 51 50 52 52 51 50 48 51",
"output": "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889"
},
{
"input": "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12",
"output": "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529"
},
{
"input": "2 3\n1 1",
"output": "1.500000\n1.500000"
},
{
"input": "2 90\n0 89",
"output": "89.500000\n0.500000"
},
{
"input": "4 17\n3 4 8 1",
"output": "5.250000\n4.250000\n0.250000\n7.250000"
},
{
"input": "2 9\n5 5",
"output": "4.500000\n4.500000"
},
{
"input": "7 28\n1 3 9 10 9 6 10",
"output": "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143"
},
{
"input": "5 11\n1 2 3 4 5",
"output": "4.200000\n3.200000\n2.200000\n1.200000\n0.200000"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0.600000\n0.600000\n0.600000\n0.600000\n0.600000"
},
{
"input": "3 1\n100 100 100",
"output": "0.333333\n0.333333\n0.333333"
},
{
"input": "5 50\n2 2 3 2 2",
"output": "10.200000\n10.200000\n9.200000\n10.200000\n10.200000"
},
{
"input": "3 3\n2 2 3",
"output": "1.333333\n1.333333\n0.333333"
},
{
"input": "2 52\n2 100",
"output": "-1"
},
{
"input": "3 2\n2 2 3",
"output": "1.000000\n1.000000\n0.000000"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0.200000\n0.200000\n0.200000\n0.200000\n0.200000"
},
{
"input": "2 4\n1 2",
"output": "2.500000\n1.500000"
},
{
"input": "5 49\n1 2 3 4 5",
"output": "11.800000\n10.800000\n9.800000\n8.800000\n7.800000"
}
] | 1,605,955,191 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 | n, b = map(int, input().split())
a = list(float(x) for x in input().split())
s = max(a)
c = [0]*n
for i in range(n):
m = s-a[i]
b = b-m
c[i] = c[i]+m
if b > 0:
for i in range(n):
c[i] = c[i] + b/n
for i in range(n):
print("%.6f" % c[i])
else:
print("-1") | Title: Problem About Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal.
Input Specification:
The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug.
Output Specification:
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Demo Input:
['5 50\n1 2 3 4 5\n', '2 2\n1 100\n']
Demo Output:
['12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n', '-1\n']
Note:
none | ```python
n, b = map(int, input().split())
a = list(float(x) for x in input().split())
s = max(a)
c = [0]*n
for i in range(n):
m = s-a[i]
b = b-m
c[i] = c[i]+m
if b > 0:
for i in range(n):
c[i] = c[i] + b/n
for i in range(n):
print("%.6f" % c[i])
else:
print("-1")
``` | 0 |
|
837 | D | Round Subset | PROGRAMMING | 2,100 | [
"dp",
"math"
] | null | null | Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible. | The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<=200,<=1<=≤<=*k*<=≤<=*n*).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1018). | Print maximal roundness of product of the chosen subset of length *k*. | [
"3 2\n50 4 20\n",
"5 3\n15 16 3 25 9\n",
"3 3\n9 77 13\n"
] | [
"3\n",
"3\n",
"0\n"
] | In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0. | 0 | [
{
"input": "3 2\n50 4 20",
"output": "3"
},
{
"input": "5 3\n15 16 3 25 9",
"output": "3"
},
{
"input": "3 3\n9 77 13",
"output": "0"
},
{
"input": "1 1\n200000000",
"output": "8"
},
{
"input": "1 1\n3",
"output": "0"
},
{
"input": "3 1\n1000000000000000000 800000000000000000 625",
"output": "18"
},
{
"input": "20 13\n93050001 1 750000001 950000001 160250001 482000001 145875001 900000001 500000001 513300001 313620001 724750001 205800001 400000001 800000001 175000001 875000001 852686005 868880001 342500001",
"output": "0"
},
{
"input": "5 3\n1360922189858001 5513375057164001 4060879738933651 3260997351273601 5540397778584001",
"output": "0"
},
{
"input": "5 3\n670206146698567481 75620705254979501 828058059097865201 67124386759325201 946737848872942801",
"output": "0"
},
{
"input": "5 4\n539134530963895499 265657472022483040 798956216114326361 930406714691011229 562844921643925634",
"output": "1"
},
{
"input": "200 10\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",
"output": "0"
},
{
"input": "200 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "200 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "200 200\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",
"output": "0"
},
{
"input": "5 2\n625 5 100 16 10",
"output": "4"
},
{
"input": "5 2\n64 32 16 8 3125",
"output": "5"
},
{
"input": "2 2\n2199023255552 11920928955078125",
"output": "23"
},
{
"input": "1 1\n500",
"output": "2"
},
{
"input": "3 1\n125 10 8",
"output": "1"
},
{
"input": "7 5\n50 312500 10000 1250 2000000 250 1250000",
"output": "18"
},
{
"input": "4 2\n3125 1000 1000 32",
"output": "6"
},
{
"input": "3 1\n4 10 25",
"output": "1"
},
{
"input": "3 1\n16 10 75",
"output": "1"
},
{
"input": "3 2\n100 5120 19531250",
"output": "11"
},
{
"input": "4 2\n16 200 500 625",
"output": "5"
},
{
"input": "7 4\n5000 1250 100 200 10 5000 640",
"output": "13"
},
{
"input": "2 1\n125 10",
"output": "1"
},
{
"input": "3 2\n16 625 10",
"output": "4"
},
{
"input": "4 2\n10 4 25 5",
"output": "2"
},
{
"input": "2 1\n10 25",
"output": "1"
},
{
"input": "3 1\n10 16 625",
"output": "1"
},
{
"input": "4 2\n10 200 625 16",
"output": "4"
},
{
"input": "3 1\n1000 16 625",
"output": "3"
},
{
"input": "3 2\n6250 100 160",
"output": "6"
},
{
"input": "3 2\n1250 100 80",
"output": "5"
},
{
"input": "3 2\n1024 1000 9765625",
"output": "10"
},
{
"input": "5 2\n125 10 10 3 3",
"output": "2"
},
{
"input": "4 2\n31250 200 500 320",
"output": "7"
},
{
"input": "3 1\n16 10 125",
"output": "1"
},
{
"input": "5 3\n125 8 1000 100 100",
"output": "7"
},
{
"input": "3 2\n25 4 10",
"output": "2"
},
{
"input": "3 2\n125 8 10",
"output": "3"
},
{
"input": "6 2\n125 125 100 100 8 8",
"output": "4"
},
{
"input": "3 1\n32 3125 10",
"output": "1"
},
{
"input": "5 3\n4 5 125 16 1",
"output": "4"
},
{
"input": "7 4\n5 125 2 5 2 5 20",
"output": "4"
},
{
"input": "200 200\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 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 2",
"output": "100"
},
{
"input": "2 1\n200 250",
"output": "2"
},
{
"input": "5 3\n500 10 250 20 8",
"output": "6"
},
{
"input": "4 2\n2 2 25 1",
"output": "1"
},
{
"input": "2 2\n16 25",
"output": "2"
}
] | 1,649,482,658 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 99 | 1,326 | 14,028,800 |
n,k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[-1 for i in range(5200)] for j in range(234)]
dp[0][0] = 0
for _ in range(n):
t,f = 0,0
p = arr[_]
while p%2 == 0:
t+=1
p//= 2
while p%5 == 0:
f += 1
p //= 5
for i in range(k-1, -1,-1):
for j in range(5200):
if dp[i][j]!=-1:
dp[i+1][j+f] = max(dp[i+1][j+f], dp[i][j]+t)
ans = 0
for i in range(5200):
if dp[k][i]!=-1:
ans = max(ans, min(i, dp[k][i]))
print(ans) | Title: Round Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input Specification:
The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<=200,<=1<=≤<=*k*<=≤<=*n*).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1018).
Output Specification:
Print maximal roundness of product of the chosen subset of length *k*.
Demo Input:
['3 2\n50 4 20\n', '5 3\n15 16 3 25 9\n', '3 3\n9 77 13\n']
Demo Output:
['3\n', '3\n', '0\n']
Note:
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0. | ```python
n,k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[-1 for i in range(5200)] for j in range(234)]
dp[0][0] = 0
for _ in range(n):
t,f = 0,0
p = arr[_]
while p%2 == 0:
t+=1
p//= 2
while p%5 == 0:
f += 1
p //= 5
for i in range(k-1, -1,-1):
for j in range(5200):
if dp[i][j]!=-1:
dp[i+1][j+f] = max(dp[i+1][j+f], dp[i][j]+t)
ans = 0
for i in range(5200):
if dp[k][i]!=-1:
ans = max(ans, min(i, dp[k][i]))
print(ans)
``` | 3 |
|
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500",
"output": "6"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39",
"output": "6"
},
{
"input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064",
"output": "5"
},
{
"input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697",
"output": "21"
}
] | 1,698,233,049 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
queue = list(map(int, input().split()))
queue = sorted(queue)
satis = [queue[0]]
wait = 0
for i in range(1, n):
wait = sum(satis)
if queue[i] > wait:
satis.append(queue[i])
print(len(satis)) | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Output Specification:
Print a single number — the maximum number of not disappointed people in the queue.
Demo Input:
['5\n15 2 1 5 3\n']
Demo Output:
['4\n']
Note:
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | ```python
n = int(input())
queue = list(map(int, input().split()))
queue = sorted(queue)
satis = [queue[0]]
wait = 0
for i in range(1, n):
wait = sum(satis)
if queue[i] > wait:
satis.append(queue[i])
print(len(satis))
``` | 0 |
|
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes. | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions. | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 57 78\n66 60 45"
},
{
"input": "0 17 14\n15 0 15\n16 13 0",
"output": "14 17 14\n15 15 15\n16 13 16"
},
{
"input": "0 97 56\n69 0 71\n84 43 0",
"output": "57 97 56\n69 70 71\n84 43 83"
},
{
"input": "0 1099 1002\n1027 0 1049\n1074 977 0",
"output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063"
},
{
"input": "0 98721 99776\n99575 0 99123\n98922 99977 0",
"output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148"
},
{
"input": "0 6361 2304\n1433 0 8103\n7232 3175 0",
"output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897"
},
{
"input": "0 99626 99582\n99766 0 99258\n99442 99398 0",
"output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696"
},
{
"input": "0 99978 99920\n99950 0 99918\n99948 99890 0",
"output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964"
},
{
"input": "0 840 666\n612 0 948\n894 720 0",
"output": "834 840 666\n612 780 948\n894 720 726"
},
{
"input": "0 28 10\n12 0 24\n26 8 0",
"output": "16 28 10\n12 18 24\n26 8 20"
},
{
"input": "0 120 83\n98 0 90\n105 68 0",
"output": "79 120 83\n98 94 90\n105 68 109"
},
{
"input": "0 86900 85807\n85836 0 86842\n86871 85778 0",
"output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368"
},
{
"input": "0 74 78\n78 0 74\n74 78 0",
"output": "76 74 78\n78 76 74\n74 78 76"
},
{
"input": "0 505 681\n605 0 657\n581 757 0",
"output": "707 505 681\n605 631 657\n581 757 555"
},
{
"input": "0 662 918\n822 0 854\n758 1014 0",
"output": "934 662 918\n822 838 854\n758 1014 742"
},
{
"input": "0 93 95\n93 0 97\n95 97 0",
"output": "97 93 95\n93 95 97\n95 97 93"
},
{
"input": "0 709 712\n719 0 695\n702 705 0",
"output": "700 709 712\n719 707 695\n702 705 714"
},
{
"input": "0 7 6\n9 0 1\n4 3 0",
"output": "2 7 6\n9 5 1\n4 3 8"
},
{
"input": "0 9 2\n3 0 7\n8 1 0",
"output": "4 9 2\n3 5 7\n8 1 6"
},
{
"input": "0 1 43\n13 0 61\n31 73 0",
"output": "67 1 43\n13 37 61\n31 73 7"
},
{
"input": "0 100000 100000\n100000 0 100000\n100000 100000 0",
"output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"
}
] | 1,380,805,773 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 312 | 0 | #!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
s = [list(readln()) for _ in range(3)]
for x in range(1, 10**5 + 1):
ss = x + s[0][1] + s[0][2]
y = ss - s[1][0] - s[1][2]
z = ss - s[2][0] - s[2][1]
if x + y + z == ss:
s[0][0] = x
s[1][1] = y
s[2][2] = z
for _ in s:
print(*tuple(_))
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes.
Input Specification:
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Output Specification:
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions.
Demo Input:
['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n']
Demo Output:
['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n']
Note:
none | ```python
#!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
s = [list(readln()) for _ in range(3)]
for x in range(1, 10**5 + 1):
ss = x + s[0][1] + s[0][2]
y = ss - s[1][0] - s[1][2]
z = ss - s[2][0] - s[2][1]
if x + y + z == ss:
s[0][0] = x
s[1][1] = y
s[2][2] = z
for _ in s:
print(*tuple(_))
``` | 3 |
|
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,427,698,669 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 0 | def gcd(a, b):
if b == 0:
return a;
return gcd(b, a % b)
l, r = map(int, input().split())
found = False
for a in range(l, r-1):
for b in range(a+1, r):
if gcd(a, b) == 1:
for c in range(b+1, r+1):
if gcd(b, c) == 1 and gcd(a, c) != 1:
found = True
break
if found:
break
if found:
break
if found:
print(a, b, c)
else:
print(-1)
| Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
def gcd(a, b):
if b == 0:
return a;
return gcd(b, a % b)
l, r = map(int, input().split())
found = False
for a in range(l, r-1):
for b in range(a+1, r):
if gcd(a, b) == 1:
for c in range(b+1, r+1):
if gcd(b, c) == 1 and gcd(a, c) != 1:
found = True
break
if found:
break
if found:
break
if found:
print(a, b, c)
else:
print(-1)
``` | 3 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,643,116,269 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 204,800 | n = int(input())
t = input()
kol1=t.count('0')
kol2=t.count('1')
print(n-(min(kol1,kol2)*2))
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n = int(input())
t = input()
kol1=t.count('0')
kol2=t.count('1')
print(n-(min(kol1,kol2)*2))
``` | 3 |
|
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n1 1\n1 1",
"output": "maybe"
},
{
"input": "2\n4126 4126\n4126 4126",
"output": "maybe"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423",
"output": "rated"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110",
"output": "unrated"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143",
"output": "maybe"
},
{
"input": "2\n3936 3936\n2967 2967",
"output": "maybe"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 1\n1 2",
"output": "rated"
},
{
"input": "2\n2967 2967\n3936 3936",
"output": "unrated"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300",
"output": "unrated"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n3 2\n3 2",
"output": "rated"
},
{
"input": "3\n5 5\n4 4\n3 4",
"output": "rated"
},
{
"input": "3\n200 200\n200 200\n300 300",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699",
"output": "maybe"
},
{
"input": "2\n10 10\n8 8",
"output": "maybe"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80",
"output": "unrated"
},
{
"input": "2\n1 2\n2 1",
"output": "rated"
},
{
"input": "3\n5 5\n4 3\n3 3",
"output": "rated"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450",
"output": "rated"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700",
"output": "unrated"
},
{
"input": "2\n1600 1600\n1400 1400",
"output": "maybe"
},
{
"input": "2\n3 1\n9 8",
"output": "rated"
},
{
"input": "2\n2 1\n1 1",
"output": "rated"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670",
"output": "unrated"
},
{
"input": "2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n10 11\n5 4",
"output": "rated"
},
{
"input": "2\n15 14\n13 12",
"output": "rated"
},
{
"input": "2\n2 1\n2 2",
"output": "rated"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106",
"output": "unrated"
},
{
"input": "3\n4 5\n3 3\n2 2",
"output": "rated"
},
{
"input": "2\n10 9\n10 10",
"output": "rated"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100",
"output": "rated"
},
{
"input": "2\n3 3\n5 5",
"output": "unrated"
},
{
"input": "2\n1500 1500\n3000 2000",
"output": "rated"
},
{
"input": "2\n5 6\n5 5",
"output": "rated"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500",
"output": "rated"
},
{
"input": "2\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n1 2\n1 1",
"output": "rated"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n15 14\n14 13",
"output": "rated"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900",
"output": "unrated"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884",
"output": "rated"
},
{
"input": "2\n100 99\n100 100",
"output": "rated"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n100 101\n100 100\n100 100",
"output": "rated"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890",
"output": "rated"
},
{
"input": "2\n2 3\n1 1",
"output": "rated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n3 2\n2 2",
"output": "rated"
},
{
"input": "2\n3 2\n3 3",
"output": "rated"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n3 2\n3 3\n3 3",
"output": "rated"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "3\n1000 1000\n500 500\n400 300",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000",
"output": "unrated"
},
{
"input": "2\n1 1\n2 3",
"output": "rated"
},
{
"input": "2\n6 2\n6 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246",
"output": "unrated"
},
{
"input": "2\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699",
"output": "maybe"
},
{
"input": "2\n20 30\n10 5",
"output": "rated"
},
{
"input": "3\n1 1\n2 2\n1 1",
"output": "unrated"
},
{
"input": "2\n1 2\n3 3",
"output": "rated"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 2\n2 1",
"output": "rated"
},
{
"input": "2\n100 100\n90 89",
"output": "rated"
},
{
"input": "2\n1000 900\n2000 2000",
"output": "rated"
},
{
"input": "2\n50 10\n10 50",
"output": "rated"
},
{
"input": "2\n200 200\n100 100",
"output": "maybe"
},
{
"input": "3\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "3\n1000 1000\n300 300\n100 100",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4",
"output": "unrated"
},
{
"input": "2\n5 3\n6 3",
"output": "rated"
},
{
"input": "2\n1200 1100\n1200 1000",
"output": "rated"
},
{
"input": "2\n5 5\n4 4",
"output": "maybe"
},
{
"input": "2\n5 5\n3 3",
"output": "maybe"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100",
"output": "unrated"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6",
"output": "maybe"
},
{
"input": "3\n1000 1000\n300 300\n10 10",
"output": "maybe"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n3 3\n1 1",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n1000 1000\n700 700",
"output": "maybe"
},
{
"input": "2\n4 3\n5 3",
"output": "rated"
},
{
"input": "2\n1000 1000\n1100 1100",
"output": "unrated"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n1 2\n1 3",
"output": "rated"
},
{
"input": "2\n3 3\n1 2",
"output": "rated"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "2\n10 10\n1 2",
"output": "rated"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900",
"output": "unrated"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699",
"output": "unrated"
},
{
"input": "2\n100 100\n110 110",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n3 3\n3 2\n4 4",
"output": "rated"
},
{
"input": "3\n5 2\n4 4\n3 3",
"output": "rated"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n1 1\n3 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n3 4",
"output": "rated"
},
{
"input": "3\n1 2\n2 2\n3 3",
"output": "rated"
},
{
"input": "3\n1 2\n1 2\n1 2",
"output": "rated"
},
{
"input": "2\n2 1\n2 1",
"output": "rated"
},
{
"input": "2\n1 2\n3 4",
"output": "rated"
},
{
"input": "2\n3 2\n2 3",
"output": "rated"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1 1\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n2 2",
"output": "unrated"
},
{
"input": "2\n10 12\n8 8",
"output": "rated"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500",
"output": "unrated"
},
{
"input": "2\n1 2\n2 2",
"output": "rated"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100",
"output": "rated"
},
{
"input": "2\n10 12\n10 10",
"output": "rated"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300",
"output": "maybe"
},
{
"input": "3\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "3\n2 6\n3 5\n4 4",
"output": "rated"
},
{
"input": "2\n5 6\n4 6",
"output": "rated"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8",
"output": "unrated"
},
{
"input": "2\n4 4\n3 3",
"output": "maybe"
}
] | 1,610,513,599 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n = int(input())
m = []
for i in range(n):
a,b = map(int,input().split())
if a < b:
print('rated')
continue
m.append(a)
m.append(b)
k = sorted(m,reverse=True)
if k == m:
print('maybe')
else:
print('unrated')
| Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
Output Specification:
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
Demo Input:
['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n']
Demo Output:
['rated\n', 'unrated\n', 'maybe\n']
Note:
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | ```python
n = int(input())
m = []
for i in range(n):
a,b = map(int,input().split())
if a < b:
print('rated')
continue
m.append(a)
m.append(b)
k = sorted(m,reverse=True)
if k == m:
print('maybe')
else:
print('unrated')
``` | 0 |
|
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReality\nSoul\nSpace\nMind"
},
{
"input": "3\nblue\norange\npurple",
"output": "3\nTime\nReality\nMind"
},
{
"input": "2\nyellow\nred",
"output": "4\nPower\nSoul\nSpace\nTime"
},
{
"input": "1\ngreen",
"output": "5\nReality\nSpace\nPower\nSoul\nMind"
},
{
"input": "2\npurple\ngreen",
"output": "4\nReality\nMind\nSpace\nSoul"
},
{
"input": "1\nblue",
"output": "5\nPower\nReality\nSoul\nTime\nMind"
},
{
"input": "2\npurple\nblue",
"output": "4\nMind\nSoul\nTime\nReality"
},
{
"input": "2\ngreen\nblue",
"output": "4\nReality\nMind\nPower\nSoul"
},
{
"input": "3\npurple\ngreen\nblue",
"output": "3\nMind\nReality\nSoul"
},
{
"input": "1\norange",
"output": "5\nReality\nTime\nPower\nSpace\nMind"
},
{
"input": "2\npurple\norange",
"output": "4\nReality\nMind\nTime\nSpace"
},
{
"input": "2\norange\ngreen",
"output": "4\nSpace\nMind\nReality\nPower"
},
{
"input": "3\norange\npurple\ngreen",
"output": "3\nReality\nSpace\nMind"
},
{
"input": "2\norange\nblue",
"output": "4\nTime\nMind\nReality\nPower"
},
{
"input": "3\nblue\ngreen\norange",
"output": "3\nPower\nMind\nReality"
},
{
"input": "4\nblue\norange\ngreen\npurple",
"output": "2\nMind\nReality"
},
{
"input": "1\nred",
"output": "5\nTime\nSoul\nMind\nPower\nSpace"
},
{
"input": "2\nred\npurple",
"output": "4\nMind\nSpace\nTime\nSoul"
},
{
"input": "2\nred\ngreen",
"output": "4\nMind\nSpace\nPower\nSoul"
},
{
"input": "3\nred\npurple\ngreen",
"output": "3\nSoul\nSpace\nMind"
},
{
"input": "2\nblue\nred",
"output": "4\nMind\nTime\nPower\nSoul"
},
{
"input": "3\nred\nblue\npurple",
"output": "3\nTime\nMind\nSoul"
},
{
"input": "3\nred\nblue\ngreen",
"output": "3\nSoul\nPower\nMind"
},
{
"input": "4\npurple\nblue\ngreen\nred",
"output": "2\nMind\nSoul"
},
{
"input": "2\norange\nred",
"output": "4\nPower\nMind\nTime\nSpace"
},
{
"input": "3\nred\norange\npurple",
"output": "3\nMind\nSpace\nTime"
},
{
"input": "3\nred\norange\ngreen",
"output": "3\nMind\nSpace\nPower"
},
{
"input": "4\nred\norange\ngreen\npurple",
"output": "2\nSpace\nMind"
},
{
"input": "3\nblue\norange\nred",
"output": "3\nPower\nMind\nTime"
},
{
"input": "4\norange\nblue\npurple\nred",
"output": "2\nTime\nMind"
},
{
"input": "4\ngreen\norange\nred\nblue",
"output": "2\nMind\nPower"
},
{
"input": "5\npurple\norange\nblue\nred\ngreen",
"output": "1\nMind"
},
{
"input": "1\nyellow",
"output": "5\nPower\nSoul\nReality\nSpace\nTime"
},
{
"input": "2\npurple\nyellow",
"output": "4\nTime\nReality\nSpace\nSoul"
},
{
"input": "2\ngreen\nyellow",
"output": "4\nSpace\nReality\nPower\nSoul"
},
{
"input": "3\npurple\nyellow\ngreen",
"output": "3\nSoul\nReality\nSpace"
},
{
"input": "2\nblue\nyellow",
"output": "4\nTime\nReality\nPower\nSoul"
},
{
"input": "3\nyellow\nblue\npurple",
"output": "3\nSoul\nReality\nTime"
},
{
"input": "3\ngreen\nyellow\nblue",
"output": "3\nSoul\nReality\nPower"
},
{
"input": "4\nyellow\nblue\ngreen\npurple",
"output": "2\nReality\nSoul"
},
{
"input": "2\nyellow\norange",
"output": "4\nTime\nSpace\nReality\nPower"
},
{
"input": "3\nyellow\npurple\norange",
"output": "3\nSpace\nReality\nTime"
},
{
"input": "3\norange\nyellow\ngreen",
"output": "3\nSpace\nReality\nPower"
},
{
"input": "4\ngreen\nyellow\norange\npurple",
"output": "2\nSpace\nReality"
},
{
"input": "3\nyellow\nblue\norange",
"output": "3\nTime\nReality\nPower"
},
{
"input": "4\norange\npurple\nblue\nyellow",
"output": "2\nReality\nTime"
},
{
"input": "4\nblue\norange\nyellow\ngreen",
"output": "2\nReality\nPower"
},
{
"input": "5\ngreen\nyellow\norange\nblue\npurple",
"output": "1\nReality"
},
{
"input": "3\nyellow\npurple\nred",
"output": "3\nTime\nSoul\nSpace"
},
{
"input": "3\nred\ngreen\nyellow",
"output": "3\nPower\nSoul\nSpace"
},
{
"input": "4\nred\npurple\ngreen\nyellow",
"output": "2\nSpace\nSoul"
},
{
"input": "3\nred\nyellow\nblue",
"output": "3\nPower\nSoul\nTime"
},
{
"input": "4\nblue\nyellow\nred\npurple",
"output": "2\nTime\nSoul"
},
{
"input": "4\nblue\nyellow\nred\ngreen",
"output": "2\nSoul\nPower"
},
{
"input": "5\nred\nyellow\ngreen\nblue\npurple",
"output": "1\nSoul"
},
{
"input": "3\nred\nyellow\norange",
"output": "3\nPower\nSpace\nTime"
},
{
"input": "4\norange\ngreen\nyellow\nred",
"output": "2\nPower\nSpace"
},
{
"input": "5\norange\nred\ngreen\nyellow\npurple",
"output": "1\nSpace"
},
{
"input": "4\nyellow\nred\norange\nblue",
"output": "2\nTime\nPower"
},
{
"input": "5\npurple\nblue\norange\nyellow\nred",
"output": "1\nTime"
},
{
"input": "5\norange\nblue\nyellow\nred\ngreen",
"output": "1\nPower"
}
] | 1,580,110,425 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 307,200 | # your code goes here
n=int(input())
dict={}
dict={'purple':'Power','green':'Time','blue':'Space','orange':'Soul','red':'Reality','yellow':'Mind Gem '}
y=[]
f=[]
count=0
for i in range(n):
z=input()
y.append(z)
if 'purple' not in y:
count=count+1
f.append(dict['purple'])
if 'green' not in y:
count=count+1
f.append(dict['green'])
if 'blue' not in y:
count=count+1
f.append(dict['blue'])
if 'orange' not in y:
count=count+1
f.append(dict['orange'])
if 'red' not in y:
count=count+1
f.append(dict['red'])
if 'yellow' not in y:
count=count+1
f.append(dict['yellow'])
print(count)
for i in range(count):
print(f[i]) | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input Specification:
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output Specification:
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Demo Input:
['4\nred\npurple\nyellow\norange\n', '0\n']
Demo Output:
['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n']
Note:
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | ```python
# your code goes here
n=int(input())
dict={}
dict={'purple':'Power','green':'Time','blue':'Space','orange':'Soul','red':'Reality','yellow':'Mind Gem '}
y=[]
f=[]
count=0
for i in range(n):
z=input()
y.append(z)
if 'purple' not in y:
count=count+1
f.append(dict['purple'])
if 'green' not in y:
count=count+1
f.append(dict['green'])
if 'blue' not in y:
count=count+1
f.append(dict['blue'])
if 'orange' not in y:
count=count+1
f.append(dict['orange'])
if 'red' not in y:
count=count+1
f.append(dict['red'])
if 'yellow' not in y:
count=count+1
f.append(dict['yellow'])
print(count)
for i in range(count):
print(f[i])
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,592,825,430 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | l=[]
x=y=z=0
for i in range(n):
l.append([int(x) for x in input().split()])
for i in range(n):
x+=l[i][0]
y+=l[i][1]
z+=l[i][2]
if x==0 and y==0 and z==0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
l=[]
x=y=z=0
for i in range(n):
l.append([int(x) for x in input().split()])
for i in range(n):
x+=l[i][0]
y+=l[i][1]
z+=l[i][2]
if x==0 and y==0 and z==0:
print("YES")
else:
print("NO")
``` | -1 |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v",
"output": "ertuv"
},
{
"input": "asdfghjkli ware",
"output": "asdfghjkliw"
},
{
"input": "udggmyop ze",
"output": "udggmyopz"
},
{
"input": "fapkdme rtzxovx",
"output": "fapkdmer"
},
{
"input": "mybiqxmnqq l",
"output": "ml"
},
{
"input": "dtbqya fyyymv",
"output": "df"
},
{
"input": "fyclu zokbxiahao",
"output": "fycluz"
},
{
"input": "qngatnviv rdych",
"output": "qngar"
},
{
"input": "ttvnhrnng lqkfulhrn",
"output": "tl"
},
{
"input": "fya fgx",
"output": "ff"
},
{
"input": "nuis zvjjqlre",
"output": "nuisz"
},
{
"input": "ly qtsmze",
"output": "lq"
},
{
"input": "d kgfpjsurfw",
"output": "dk"
},
{
"input": "lwli ewrpu",
"output": "le"
},
{
"input": "rr wldsfubcs",
"output": "rrw"
},
{
"input": "h qart",
"output": "hq"
},
{
"input": "vugvblnzx kqdwdulm",
"output": "vk"
},
{
"input": "xohesmku ef",
"output": "xe"
},
{
"input": "twvvsl wtcyawv",
"output": "tw"
},
{
"input": "obljndajv q",
"output": "obljndajq"
},
{
"input": "jjxwj kxccwx",
"output": "jjk"
},
{
"input": "sk fftzmv",
"output": "sf"
},
{
"input": "cgpegngs aufzxkyyrw",
"output": "ca"
},
{
"input": "reyjzjdvq skuch",
"output": "res"
},
{
"input": "ardaae mxgdulijf",
"output": "am"
},
{
"input": "bgopsdfji uaps",
"output": "bgopsdfjiu"
},
{
"input": "amolfed pun",
"output": "amolfedp"
},
{
"input": "badkiln yort",
"output": "badkilny"
},
{
"input": "aaaaaaaaaz york",
"output": "aaaaaaaaay"
},
{
"input": "bbbbcbbbbd c",
"output": "bbbbc"
},
{
"input": "aa ab",
"output": "aa"
},
{
"input": "ab b",
"output": "ab"
},
{
"input": "aaaaa ab",
"output": "aa"
},
{
"input": "aa a",
"output": "aa"
},
{
"input": "aba b",
"output": "ab"
},
{
"input": "aaaaaaa aaaaaa",
"output": "aa"
},
{
"input": "a a",
"output": "aa"
},
{
"input": "a aa",
"output": "aa"
},
{
"input": "a b",
"output": "ab"
},
{
"input": "b a",
"output": "ba"
},
{
"input": "z a",
"output": "za"
},
{
"input": "aaa a",
"output": "aa"
},
{
"input": "aa aa",
"output": "aa"
},
{
"input": "a aaa",
"output": "aa"
},
{
"input": "aaaaaaaaaa aaaaaaaaaa",
"output": "aa"
},
{
"input": "aaaaaaaaaa a",
"output": "aa"
},
{
"input": "a aaaaaaaaaa",
"output": "aa"
},
{
"input": "zzaa b",
"output": "zb"
},
{
"input": "ca cf",
"output": "cac"
},
{
"input": "abhi ia",
"output": "abhi"
},
{
"input": "aaaa aaaab",
"output": "aa"
},
{
"input": "aar raa",
"output": "aar"
},
{
"input": "harry hotter",
"output": "hah"
},
{
"input": "aaaaaaa a",
"output": "aa"
},
{
"input": "apple pie",
"output": "ap"
},
{
"input": "aaa aaa",
"output": "aa"
},
{
"input": "kabc buba",
"output": "kab"
},
{
"input": "asd ss",
"output": "as"
},
{
"input": "bbb b",
"output": "bb"
}
] | 1,514,436,231 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 5,529,600 | s = input()
x = s.split(" ")
f = x[0]
sec = x[1]
ans=f[0]
f = f.replace(ans,"")
last = sec[0]
for i in f:
if i<=last:
ans+=i
print(ans+last) | Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
Input Specification:
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output Specification:
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
Demo Input:
['harry potter\n', 'tom riddle\n']
Demo Output:
['hap\n', 'tomr\n']
Note:
none | ```python
s = input()
x = s.split(" ")
f = x[0]
sec = x[1]
ans=f[0]
f = f.replace(ans,"")
last = sec[0]
for i in f:
if i<=last:
ans+=i
print(ans+last)
``` | 0 |
|
771 | D | Bear and Company | PROGRAMMING | 2,500 | [
"dp"
] | null | null | Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string *s* that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.
Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string *s*.
What is the minimum possible number of moves Limak can do? | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string.
The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*. | Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK". | [
"4\nVKVK\n",
"5\nBVVKV\n",
"7\nVVKEVKK\n",
"20\nVKVKVVVKVOVKVQKKKVVK\n",
"5\nLIMAK\n"
] | [
"3\n",
"2\n",
"3\n",
"8\n",
"0\n"
] | In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".
In the second sample, there are two optimal sequences of moves. One is "BVVKV" → "VBVKV" → "VVBKV". The other is "BVVKV" → "BVKVV" → "BKVVV".
In the fifth sample, no swaps are necessary. | 1,500 | [
{
"input": "4\nVKVK",
"output": "3"
},
{
"input": "5\nBVVKV",
"output": "2"
},
{
"input": "7\nVVKEVKK",
"output": "3"
},
{
"input": "20\nVKVKVVVKVOVKVQKKKVVK",
"output": "8"
},
{
"input": "5\nLIMAK",
"output": "0"
},
{
"input": "1\nV",
"output": "0"
},
{
"input": "1\nK",
"output": "0"
},
{
"input": "1\nZ",
"output": "0"
},
{
"input": "17\nVAKVAKLIMAKVVVKKK",
"output": "4"
},
{
"input": "10\nVVKAVZVAAZ",
"output": "1"
},
{
"input": "17\nQZVRZKDKMZZAKKZVA",
"output": "0"
},
{
"input": "51\nAVVVVVVVVVVKKKKKKKKKKVVVVVVVVVVVVVVVKKKKKKKKKKKKKKK",
"output": "135"
},
{
"input": "75\nVFZVZRVZAZJAKAZKAVVKZKVHZZZZAVAAKKAADKNAKRFKAAAZKZVAKAAAJAVKYAAZAKAVKASZAAK",
"output": "3"
},
{
"input": "75\nVVKAVKKVAKVXCKKZKKAVVVAKKKKVVKSKVVWVLEVVHVXKKKVKVJKVVVZVVKKKVVKVVVKKKVVKZKV",
"output": "19"
},
{
"input": "2\nVK",
"output": "1"
},
{
"input": "2\nKV",
"output": "0"
},
{
"input": "3\nVKK",
"output": "2"
},
{
"input": "3\nKVV",
"output": "0"
},
{
"input": "75\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKV",
"output": "703"
},
{
"input": "75\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKOOOKVKV",
"output": "175"
},
{
"input": "6\nVVVKKK",
"output": "9"
},
{
"input": "7\nVVVKKKO",
"output": "3"
},
{
"input": "12\nVKVKVKVKVKVK",
"output": "21"
},
{
"input": "5\nVKOVK",
"output": "2"
},
{
"input": "3\nKKV",
"output": "0"
},
{
"input": "6\nVVOKKK",
"output": "0"
},
{
"input": "15\nVOKVOKVVKKKKKKK",
"output": "4"
},
{
"input": "10\nKKZKKVKZKV",
"output": "1"
},
{
"input": "15\nVKKHKKKKZVKKVKV",
"output": "4"
},
{
"input": "22\nVKKVKVKKVKVKZKKVKVAKKK",
"output": "14"
},
{
"input": "46\nVVFVKKVAKVKKVGVKKKKZKKKKKKKAKKZKVVVVKKZVVKFVKK",
"output": "9"
},
{
"input": "50\nKKAKVVNAVVVVKKVKKZVKKKKVKFTVVKKVVVVVZVLKKKKKKVKVVV",
"output": "11"
},
{
"input": "75\nVKVVKVKKKVVZKVZKVKVKVVKIAVKVVVKKKVDKVKKVKAKKAKNAKVZKAAVVAKUKVKKVKKVZVAKKKVV",
"output": "27"
},
{
"input": "75\nAJAKVZASUKAYZFSZRPAAVAGZKFZZHZZZKKKVLQAAVAHQHAZCVEZAAZZAAZIAAAZKKAAUKROVKAK",
"output": "1"
},
{
"input": "75\nKAVVZVKKVVKVKVLVVKKKVVAKVVKEVAVVKKVVKVDVVKKVKKVZKKAKKKVKVZAVVKKKZVVDKVVAKZV",
"output": "20"
},
{
"input": "75\nVKKVKKAKKKVVVVVZKKKKVKAVKKAZKKKKVKVVKVVKVVKCKKVVVVVZKKVKKKVKKKVVKVKVKOVVZKK",
"output": "26"
},
{
"input": "74\nVVVKVKKKAZVVVKKKKKVVVVKKVVVKKVAKVVVVVVKVKVKVVMVVKVVVKVKKVVVVVKVKKKVVVXKVVK",
"output": "66"
},
{
"input": "74\nVJVKVUKVVVVVVKVLVKKVVKZVNZVKKVVVAVVVKKAKZKZVAZVVKVKKZKKVNAVAKVKKCVVVKKVKVV",
"output": "19"
},
{
"input": "75\nZXPZMAKZZZZZZAZXAZAAPOAFAZUZZAZABQZZAZZBZAAAZZFANYAAZZZZAZHZARACAAZAZDPCAVZ",
"output": "0"
},
{
"input": "75\nVZVVVZAUVZZTZZCTJZAVZVSVAAACVAHZVVAFZSVVAZAZVXVKVZVZVVZTAZREOVZZEVAVBAVAAAF",
"output": "1"
},
{
"input": "75\nAZKZWAOZZLTZIZTAYKOALAAKKKZAASKAAZFHVZKZAAZUKAKZZBIAZZWAZZZZZPZZZRAZZZAZJZA",
"output": "0"
},
{
"input": "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ",
"output": "1"
},
{
"input": "52\nAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZK",
"output": "1"
},
{
"input": "64\nVVKKVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZVVVKKKKK",
"output": "7"
},
{
"input": "64\nVVKKAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZKVVVKKKKK",
"output": "7"
},
{
"input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK",
"output": "1406"
},
{
"input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK",
"output": "1406"
},
{
"input": "72\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK",
"output": "35"
},
{
"input": "73\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB",
"output": "32"
},
{
"input": "72\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB",
"output": "30"
},
{
"input": "67\nVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKXVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKK",
"output": "213"
},
{
"input": "57\nVVVVKKKKKKAAVVVVVVVVKKKKKKKVVVVVVVVVKKKKKKKKKKKKKKKKKKKKO",
"output": "34"
},
{
"input": "13\nVVVVKKAVVKVKK",
"output": "10"
},
{
"input": "65\nVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK",
"output": "50"
},
{
"input": "67\nVVVVKKAVVKVKKVVVVKKAVVKVKKAOVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK",
"output": "44"
},
{
"input": "52\nZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZK",
"output": "28"
},
{
"input": "63\nKKKVVVKAAKVVVTVVVKAUVKKKVKVKKVKVKVVKVKKVKVKKKQVKVVVKVKKVKKKKKKZ",
"output": "43"
},
{
"input": "75\nVVKVKKKVKVVKKKKKVVKKKKVVVKVKKKAVAKKKVVKVKEVVVVVVVVKKKKKVVVVVKVVVKKKVVKVVKVV",
"output": "114"
},
{
"input": "75\nVVVVVKVKVVKKEVVVVVAKVKKZKVVPKKZKAVKVAKVMZKZVUVKKIVVZVVVKVKZVVVVKKVKVZZVOVKV",
"output": "23"
},
{
"input": "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK",
"output": "36"
},
{
"input": "75\nVVKVKKVZAVVKHKRAVKAKVKKVKKAAVKVVNZVKKKVVKMAVVKKWKKVVKVHKKVKVZVVKZZKVKVIKZVK",
"output": "22"
},
{
"input": "75\nKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK",
"output": "0"
},
{
"input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
"output": "0"
},
{
"input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVK",
"output": "74"
},
{
"input": "75\nKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
"output": "0"
},
{
"input": "38\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKK",
"output": "40"
},
{
"input": "74\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKK",
"output": "98"
},
{
"input": "71\nZKKKVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVKKKKKKKKKKKVVVVVVVVVVKKKKKKK",
"output": "153"
},
{
"input": "68\nKKVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKV",
"output": "400"
},
{
"input": "75\nKVVKCVKVVVVKVVVKVKVAVVMVVVVVKKVVVKVVVVVKKVVVVVKVVKVVVKKKKKVKKVKAVVVVVVVVVVK",
"output": "71"
},
{
"input": "74\nKKKZKVKKKKVKKKKVKVZKKKZKKKKKZKVKKZZKKBVKKVAKVKVKZVVKKKKKKKKKVKKVVKKVVKKKVK",
"output": "45"
},
{
"input": "75\nKVKVVKVKVKVVVVVKVKKKVKVVKVVKVVKKKKEKVVVKKKVVKVVVVVVVKKVKKVVVKAKVVKKVVVVVKUV",
"output": "103"
},
{
"input": "75\nKKVVAVVVVKVKAVVAKVKVKVVVVKKKKKAZVKVKVKJVVVAKVVKKKVVVVZVAVVVZKVZAKVVVVVVVAKK",
"output": "18"
}
] | 1,689,436,618 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689436618.748709")# 1689436618.7487276 | Title: Bear and Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string *s* that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.
Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string *s*.
What is the minimum possible number of moves Limak can do?
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string.
The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*.
Output Specification:
Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".
Demo Input:
['4\nVKVK\n', '5\nBVVKV\n', '7\nVVKEVKK\n', '20\nVKVKVVVKVOVKVQKKKVVK\n', '5\nLIMAK\n']
Demo Output:
['3\n', '2\n', '3\n', '8\n', '0\n']
Note:
In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".
In the second sample, there are two optimal sequences of moves. One is "BVVKV" → "VBVKV" → "VVBKV". The other is "BVVKV" → "BVKVV" → "BKVVV".
In the fifth sample, no swaps are necessary. | ```python
print("_RANDOM_GUESS_1689436618.748709")# 1689436618.7487276
``` | 0 |
|
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex *v* and a color *x*, and then color all vectices in the subtree of *v* (including *v* itself) in color *x*. In other words, for every vertex *u*, such that the path from root to *u* passes through *v*, set *c**u*<==<=*x*.
It is guaranteed that you have to color each vertex in a color different from 0.
You can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)). | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the color you should color the *i*-th vertex into.
It is guaranteed that the given graph is a tree. | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):
<img class="tex-graphics" src="https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On seond step we color all vertices in the subtree of vertex 5 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On third step we color all vertices in the subtree of vertex 2 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The tree from the second sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):
<img class="tex-graphics" src="https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On second step we color all vertices in the subtree of vertex 3 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On third step we color all vertices in the subtree of vertex 6 into color 2:
<img class="tex-graphics" src="https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On fourth step we color all vertices in the subtree of vertex 4 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On fith step we color all vertices in the subtree of vertex 7 into color 3:
<img class="tex-graphics" src="https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
"input": "4\n1 2 3\n4 1 2 4",
"output": "4"
},
{
"input": "5\n1 2 1 4\n1 1 1 2 2",
"output": "2"
},
{
"input": "3\n1 2\n2 1 1",
"output": "2"
},
{
"input": "4\n1 1 1\n3 1 3 1",
"output": "3"
},
{
"input": "4\n1 1 2\n4 1 4 1",
"output": "2"
},
{
"input": "4\n1 2 2\n3 1 2 3",
"output": "4"
},
{
"input": "3\n1 1\n1 2 2",
"output": "3"
}
] | 1,682,940,194 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import heapq
cycle = 0
v = [[]] * 1000
heapq.heapify(v)
visited = [0] * 1000
color = [0] * 1000
def dfs(u, col):
visited[u] = 1
cnt = 0
for i in range(len(v[u])):
node = v[u][i]
if visited[node] == False:
cnt += (1 - (color[node] == col)) + dfs(node, color[node])
visited[u] = 2
return cnt
visited = [0] * len(visited)
color = [0] * len(color)
n = int(input())
p = [int(i) for i in input().split()]
p_index = 0
for i in range(2, n + 1):
p_temp = p[p_index]
heapq.heappush(v[p_temp], i)
p_index += 1
c = [int(i) for i in input().split()]
for i in range(1, n + 1):
color[i] = c[i - 1]
print(2 + dfs(1, color[1]))
| Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex *v* and a color *x*, and then color all vectices in the subtree of *v* (including *v* itself) in color *x*. In other words, for every vertex *u*, such that the path from root to *u* passes through *v*, set *c**u*<==<=*x*.
It is guaranteed that you have to color each vertex in a color different from 0.
You can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)).
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the color you should color the *i*-th vertex into.
It is guaranteed that the given graph is a tree.
Output Specification:
Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.
Demo Input:
['6\n1 2 2 1 5\n2 1 1 1 1 1\n', '7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n']
Demo Output:
['3\n', '5\n']
Note:
The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):
<img class="tex-graphics" src="https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On seond step we color all vertices in the subtree of vertex 5 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On third step we color all vertices in the subtree of vertex 2 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The tree from the second sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):
<img class="tex-graphics" src="https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On second step we color all vertices in the subtree of vertex 3 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On third step we color all vertices in the subtree of vertex 6 into color 2:
<img class="tex-graphics" src="https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On fourth step we color all vertices in the subtree of vertex 4 into color 1:
<img class="tex-graphics" src="https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On fith step we color all vertices in the subtree of vertex 7 into color 3:
<img class="tex-graphics" src="https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import heapq
cycle = 0
v = [[]] * 1000
heapq.heapify(v)
visited = [0] * 1000
color = [0] * 1000
def dfs(u, col):
visited[u] = 1
cnt = 0
for i in range(len(v[u])):
node = v[u][i]
if visited[node] == False:
cnt += (1 - (color[node] == col)) + dfs(node, color[node])
visited[u] = 2
return cnt
visited = [0] * len(visited)
color = [0] * len(color)
n = int(input())
p = [int(i) for i in input().split()]
p_index = 0
for i in range(2, n + 1):
p_temp = p[p_index]
heapq.heappush(v[p_temp], i)
p_index += 1
c = [int(i) for i in input().split()]
for i in range(1, n + 1):
color[i] = c[i - 1]
print(2 + dfs(1, color[1]))
``` | 0 |
|
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX",
"output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX"
},
{
"input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO",
"output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO"
},
{
"input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD",
"output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD"
},
{
"input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW",
"output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW"
},
{
"input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL",
"output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL"
},
{
"input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC",
"output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC"
},
{
"input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN",
"output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN"
},
{
"input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE",
"output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE"
},
{
"input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP",
"output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP"
},
{
"input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG",
"output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG"
},
{
"input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV",
"output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV"
},
{
"input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI",
"output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI"
},
{
"input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX",
"output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX"
},
{
"input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ",
"output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ"
},
{
"input": "P",
"output": "P"
},
{
"input": "Xyzzy",
"output": "Xyzzy"
},
{
"input": "Zzz",
"output": "Zzz"
},
{
"input": "Zp",
"output": "Zp"
}
] | 1,698,685,387 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | a = str
a = input()
b = a[0].upper() + a[1:]
print(b)
# bce001
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input Specification:
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output Specification:
Output the given word after capitalization.
Demo Input:
['ApPLe\n', 'konjac\n']
Demo Output:
['ApPLe\n', 'Konjac\n']
Note:
none | ```python
a = str
a = input()
b = a[0].upper() + a[1:]
print(b)
# bce001
``` | 3 |
|
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets. | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "3"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "2"
},
{
"input": "1 0 1",
"output": "1"
},
{
"input": "101 99 97",
"output": "-1"
},
{
"input": "1000000000 0 1",
"output": "-1"
},
{
"input": "137 137 136",
"output": "1"
},
{
"input": "255 255 255",
"output": "2"
},
{
"input": "1 0 1000000000",
"output": "1000000000"
},
{
"input": "123 456 789",
"output": "9"
},
{
"input": "666666 6666666 666665",
"output": "-1"
},
{
"input": "1000000000 999999999 999999999",
"output": "-1"
},
{
"input": "100000000 100000001 99999999",
"output": "-1"
},
{
"input": "3 2 1000000000",
"output": "-1"
},
{
"input": "999999999 1000000000 999999998",
"output": "-1"
},
{
"input": "12938621 192872393 102739134",
"output": "21"
},
{
"input": "666666666 1230983 666666666",
"output": "1"
},
{
"input": "123456789 123456789 123456787",
"output": "1"
},
{
"input": "5 6 0",
"output": "-1"
},
{
"input": "11 0 12",
"output": "-1"
},
{
"input": "2 11 0",
"output": "-1"
},
{
"input": "2 1 0",
"output": "-1"
},
{
"input": "10 11 12",
"output": "2"
},
{
"input": "11 12 5",
"output": "-1"
},
{
"input": "11 12 3",
"output": "-1"
},
{
"input": "11 15 4",
"output": "-1"
},
{
"input": "2 3 1",
"output": "-1"
},
{
"input": "11 12 0",
"output": "-1"
},
{
"input": "11 13 2",
"output": "-1"
},
{
"input": "11 23 22",
"output": "4"
},
{
"input": "10 21 0",
"output": "-1"
},
{
"input": "11 23 1",
"output": "-1"
},
{
"input": "11 10 12",
"output": "-1"
},
{
"input": "11 1 12",
"output": "-1"
},
{
"input": "11 5 12",
"output": "-1"
},
{
"input": "11 8 12",
"output": "-1"
},
{
"input": "11 12 1",
"output": "-1"
},
{
"input": "5 4 6",
"output": "-1"
},
{
"input": "10 1 22",
"output": "-1"
},
{
"input": "2 3 0",
"output": "-1"
},
{
"input": "11 23 2",
"output": "-1"
},
{
"input": "2 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "11 0 15",
"output": "-1"
},
{
"input": "11 5 0",
"output": "-1"
},
{
"input": "11 5 15",
"output": "-1"
},
{
"input": "10 0 13",
"output": "-1"
},
{
"input": "4 7 0",
"output": "-1"
},
{
"input": "10 2 8",
"output": "-1"
},
{
"input": "11 5 22",
"output": "2"
},
{
"input": "11 13 0",
"output": "-1"
},
{
"input": "2 0 3",
"output": "-1"
},
{
"input": "10 10 0",
"output": "1"
},
{
"input": "10 11 10",
"output": "2"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "11 22 3",
"output": "2"
},
{
"input": "11 12 10",
"output": "-1"
},
{
"input": "10 2 13",
"output": "-1"
},
{
"input": "5 6 1",
"output": "-1"
},
{
"input": "10 21 5",
"output": "-1"
},
{
"input": "10 11 9",
"output": "-1"
},
{
"input": "10 17 7",
"output": "-1"
},
{
"input": "3 4 1",
"output": "-1"
},
{
"input": "4 5 3",
"output": "-1"
},
{
"input": "11 3 23",
"output": "-1"
},
{
"input": "11 3 12",
"output": "-1"
},
{
"input": "2 5 0",
"output": "-1"
},
{
"input": "10 21 2",
"output": "-1"
},
{
"input": "5 1 6",
"output": "-1"
},
{
"input": "10 11 0",
"output": "-1"
},
{
"input": "10 9 11",
"output": "-1"
},
{
"input": "7 10 5",
"output": "-1"
},
{
"input": "5 7 2",
"output": "-1"
},
{
"input": "6 5 7",
"output": "-1"
},
{
"input": "11 16 2",
"output": "-1"
},
{
"input": "11 1000000000 10",
"output": "-1"
},
{
"input": "10 2 21",
"output": "-1"
},
{
"input": "10 15 1",
"output": "-1"
},
{
"input": "5 2 8",
"output": "-1"
},
{
"input": "11 10000000 10",
"output": "-1"
},
{
"input": "10 1 101",
"output": "-1"
},
{
"input": "20 24 2",
"output": "-1"
},
{
"input": "11 24 0",
"output": "-1"
},
{
"input": "11 17 4",
"output": "-1"
},
{
"input": "11 13 1",
"output": "-1"
},
{
"input": "10 11 2",
"output": "-1"
},
{
"input": "11 23 3",
"output": "-1"
},
{
"input": "10 99 0",
"output": "-1"
},
{
"input": "6 7 4",
"output": "-1"
},
{
"input": "11 1 22",
"output": "2"
},
{
"input": "11 2 13",
"output": "-1"
},
{
"input": "2 1 3",
"output": "-1"
},
{
"input": "11 6 18",
"output": "-1"
},
{
"input": "11 122 4",
"output": "-1"
},
{
"input": "11 21 10",
"output": "-1"
},
{
"input": "3 2 4",
"output": "-1"
},
{
"input": "9 11 2",
"output": "-1"
},
{
"input": "11 0 7",
"output": "-1"
},
{
"input": "5 9 4",
"output": "-1"
},
{
"input": "100 105 5",
"output": "-1"
},
{
"input": "11 15 0",
"output": "-1"
},
{
"input": "5 6 4",
"output": "-1"
},
{
"input": "3 4 2",
"output": "-1"
},
{
"input": "2 9 0",
"output": "-1"
},
{
"input": "11 13 11",
"output": "2"
},
{
"input": "11 15 5",
"output": "-1"
},
{
"input": "11 4 15",
"output": "-1"
},
{
"input": "10 1 0",
"output": "-1"
},
{
"input": "11 16 8",
"output": "-1"
},
{
"input": "10 43 0",
"output": "-1"
},
{
"input": "11 13 5",
"output": "-1"
},
{
"input": "11 22 0",
"output": "2"
},
{
"input": "5 6 3",
"output": "-1"
},
{
"input": "2 1 11",
"output": "-1"
},
{
"input": "4 5 1",
"output": "-1"
},
{
"input": "11 23 0",
"output": "-1"
},
{
"input": "11 4 12",
"output": "-1"
},
{
"input": "12 13 1",
"output": "-1"
},
{
"input": "10 19 9",
"output": "-1"
},
{
"input": "3 7 2",
"output": "-1"
},
{
"input": "12 18 0",
"output": "-1"
},
{
"input": "11 25 3",
"output": "-1"
},
{
"input": "11 23 5",
"output": "-1"
},
{
"input": "2 1 5",
"output": "-1"
},
{
"input": "2 0 5",
"output": "-1"
},
{
"input": "11 24 1",
"output": "-1"
},
{
"input": "10 11 4",
"output": "-1"
},
{
"input": "2 0 1",
"output": "-1"
},
{
"input": "10 0 21",
"output": "-1"
},
{
"input": "3 0 7",
"output": "-1"
},
{
"input": "18 11 21",
"output": "-1"
},
{
"input": "3 7 0",
"output": "-1"
},
{
"input": "5 11 0",
"output": "-1"
},
{
"input": "11 5 13",
"output": "-1"
},
{
"input": "11 9 34",
"output": "-1"
},
{
"input": "11 13 9",
"output": "-1"
},
{
"input": "10 0 22",
"output": "-1"
},
{
"input": "5 1 12",
"output": "-1"
},
{
"input": "11 2 12",
"output": "-1"
},
{
"input": "11 9 12",
"output": "-1"
},
{
"input": "11 24 2",
"output": "-1"
},
{
"input": "11 23 6",
"output": "-1"
},
{
"input": "11 20 4",
"output": "-1"
},
{
"input": "2 5 1",
"output": "-1"
},
{
"input": "120 132 133",
"output": "2"
},
{
"input": "11 111 4",
"output": "-1"
},
{
"input": "10 7 11",
"output": "-1"
},
{
"input": "6 13 0",
"output": "-1"
},
{
"input": "5 11 1",
"output": "-1"
},
{
"input": "11 5 27",
"output": "-1"
},
{
"input": "11 15 3",
"output": "-1"
},
{
"input": "11 0 13",
"output": "-1"
},
{
"input": "11 13 10",
"output": "-1"
},
{
"input": "11 25 5",
"output": "-1"
},
{
"input": "4 3 5",
"output": "-1"
},
{
"input": "100 199 100",
"output": "2"
},
{
"input": "11 2 22",
"output": "2"
},
{
"input": "10 20 2",
"output": "2"
},
{
"input": "5 5 0",
"output": "1"
},
{
"input": "10 11 1",
"output": "-1"
},
{
"input": "11 12 2",
"output": "-1"
},
{
"input": "5 16 3",
"output": "-1"
},
{
"input": "12 14 1",
"output": "-1"
},
{
"input": "10 22 2",
"output": "-1"
},
{
"input": "2 4 0",
"output": "2"
},
{
"input": "11 34 7",
"output": "-1"
},
{
"input": "6 13 1",
"output": "-1"
},
{
"input": "11 0 23",
"output": "-1"
},
{
"input": "20 21 19",
"output": "-1"
},
{
"input": "11 33 22",
"output": "5"
},
{
"input": "10 4 41",
"output": "-1"
},
{
"input": "3 4 0",
"output": "-1"
},
{
"input": "11 15 7",
"output": "-1"
},
{
"input": "5 0 6",
"output": "-1"
},
{
"input": "11 3 22",
"output": "2"
},
{
"input": "2 6 0",
"output": "3"
},
{
"input": "10 11 11",
"output": "2"
},
{
"input": "11 33 0",
"output": "3"
},
{
"input": "4 6 2",
"output": "-1"
},
{
"input": "11 76 2",
"output": "-1"
},
{
"input": "7 9 4",
"output": "-1"
},
{
"input": "10 43 1",
"output": "-1"
},
{
"input": "22 25 5",
"output": "-1"
},
{
"input": "3 5 2",
"output": "-1"
},
{
"input": "11 1 24",
"output": "-1"
},
{
"input": "12 25 3",
"output": "-1"
},
{
"input": "11 0 22",
"output": "2"
},
{
"input": "4 2 5",
"output": "-1"
},
{
"input": "11 13 3",
"output": "-1"
},
{
"input": "11 12 9",
"output": "-1"
},
{
"input": "11 35 1",
"output": "-1"
},
{
"input": "5 3 6",
"output": "-1"
},
{
"input": "5 11 4",
"output": "-1"
},
{
"input": "12 8 14",
"output": "-1"
},
{
"input": "10 12 9",
"output": "-1"
},
{
"input": "11 12 13",
"output": "2"
},
{
"input": "11 15 2",
"output": "-1"
},
{
"input": "11 23 4",
"output": "-1"
},
{
"input": "5 3 11",
"output": "-1"
},
{
"input": "6 13 2",
"output": "-1"
},
{
"input": "4 1 0",
"output": "-1"
},
{
"input": "11 32 10",
"output": "-1"
},
{
"input": "2 11 1",
"output": "-1"
},
{
"input": "10 11 7",
"output": "-1"
},
{
"input": "11 26 0",
"output": "-1"
},
{
"input": "100 205 5",
"output": "-1"
},
{
"input": "4 0 2",
"output": "-1"
},
{
"input": "10 11 8",
"output": "-1"
},
{
"input": "11 22 5",
"output": "2"
},
{
"input": "4 0 5",
"output": "-1"
},
{
"input": "11 87 22",
"output": "9"
},
{
"input": "4 8 0",
"output": "2"
},
{
"input": "9 8 17",
"output": "-1"
},
{
"input": "10 20 0",
"output": "2"
},
{
"input": "10 9 19",
"output": "-1"
},
{
"input": "12 2 13",
"output": "-1"
},
{
"input": "11 24 5",
"output": "-1"
},
{
"input": "10 1 11",
"output": "-1"
},
{
"input": "4 0 9",
"output": "-1"
},
{
"input": "3 0 1",
"output": "-1"
},
{
"input": "11 12 4",
"output": "-1"
},
{
"input": "3 8 2",
"output": "-1"
},
{
"input": "11 17 10",
"output": "-1"
},
{
"input": "6 1 13",
"output": "-1"
},
{
"input": "11 25 0",
"output": "-1"
},
{
"input": "12 0 13",
"output": "-1"
},
{
"input": "10 5 20",
"output": "2"
},
{
"input": "11 89 2",
"output": "-1"
},
{
"input": "2 4 1",
"output": "2"
},
{
"input": "10 31 0",
"output": "-1"
},
{
"input": "11 34 1",
"output": "-1"
},
{
"input": "999 6693 8331",
"output": "14"
},
{
"input": "10 55 1",
"output": "-1"
},
{
"input": "11 12 8",
"output": "-1"
},
{
"input": "1 9 22",
"output": "31"
},
{
"input": "7572 9186 895",
"output": "-1"
},
{
"input": "3 2 11",
"output": "-1"
},
{
"input": "2 1 4",
"output": "2"
},
{
"input": "11 10 19",
"output": "-1"
},
{
"input": "100 199 99",
"output": "-1"
},
{
"input": "2537 8926 1523",
"output": "-1"
},
{
"input": "11 0 5",
"output": "-1"
},
{
"input": "5 1 11",
"output": "-1"
},
{
"input": "12 13 5",
"output": "-1"
},
{
"input": "10 12 0",
"output": "-1"
},
{
"input": "5 4 7",
"output": "-1"
},
{
"input": "12 25 1",
"output": "-1"
},
{
"input": "7 9 0",
"output": "-1"
},
{
"input": "4 15 0",
"output": "-1"
},
{
"input": "5 11 2",
"output": "-1"
},
{
"input": "11 58 3",
"output": "-1"
},
{
"input": "10 11 5",
"output": "-1"
},
{
"input": "10 3 1003",
"output": "-1"
},
{
"input": "11 14 0",
"output": "-1"
},
{
"input": "11 8 23",
"output": "-1"
},
{
"input": "11 22 4",
"output": "2"
},
{
"input": "5 2 0",
"output": "-1"
},
{
"input": "11 1 35",
"output": "-1"
},
{
"input": "12 25 5",
"output": "-1"
},
{
"input": "11 37 4",
"output": "-1"
},
{
"input": "20 42 3",
"output": "-1"
},
{
"input": "10 12 2",
"output": "-1"
},
{
"input": "4 1 5",
"output": "-1"
},
{
"input": "5 16 0",
"output": "-1"
},
{
"input": "11 13 7",
"output": "-1"
},
{
"input": "5 0 3",
"output": "-1"
},
{
"input": "11 2 11",
"output": "1"
},
{
"input": "3 2 2000",
"output": "-1"
},
{
"input": "3 0 4241",
"output": "-1"
},
{
"input": "2 12 11",
"output": "11"
},
{
"input": "10 2 82",
"output": "-1"
},
{
"input": "11 0 11",
"output": "1"
},
{
"input": "11 20 20",
"output": "2"
},
{
"input": "5 0 10",
"output": "2"
},
{
"input": "11 1 0",
"output": "-1"
},
{
"input": "11 13 13",
"output": "2"
}
] | 1,637,204,598 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 279 | 77 | 0 | k,a,b = [int(i) for i in input().split()]
t = int(a//k + b//k)
if a//k == 0 and b%k != 0:
print(-1)
elif b//k == 0 and a%k != 0:
print(-1)
else:
print(t if t != 0 or a+b == 0 else -1)
| Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input Specification:
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0).
Output Specification:
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Demo Input:
['11 11 5\n', '11 2 3\n']
Demo Output:
['1\n', '-1\n']
Note:
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | ```python
k,a,b = [int(i) for i in input().split()]
t = int(a//k + b//k)
if a//k == 0 and b%k != 0:
print(-1)
elif b//k == 0 and a%k != 0:
print(-1)
else:
print(t if t != 0 or a+b == 0 else -1)
``` | 3 |
|
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#"
},
{
"input": "1 1 0\n.",
"output": "."
},
{
"input": "2 3 1\n..#\n#..",
"output": "X.#\n#.."
},
{
"input": "2 3 1\n#..\n..#",
"output": "#.X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n..#",
"output": "...\n.#X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n#..",
"output": "...\nX#.\n#.."
},
{
"input": "5 4 4\n#..#\n....\n.##.\n....\n#..#",
"output": "#XX#\nXX..\n.##.\n....\n#..#"
},
{
"input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..",
"output": "X#..#\nX.#.#\n#....\n##.#.\n###.."
},
{
"input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#",
"output": "#.....\n#X#.#X\nX#...#\n...#.#"
},
{
"input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#",
"output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#"
},
{
"input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###",
"output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###"
},
{
"input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################",
"output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################"
},
{
"input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#",
"output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#"
},
{
"input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###",
"output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###"
},
{
"input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######",
"output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######"
},
{
"input": "3 5 1\n#...#\n..#..\n..#..",
"output": "#...#\n..#..\nX.#.."
},
{
"input": "4 5 10\n.....\n.....\n..#..\n..#..",
"output": "XXX..\nXXX..\nXX#..\nXX#.."
},
{
"input": "3 5 3\n.....\n..#..\n..#..",
"output": ".....\nX.#..\nXX#.."
},
{
"input": "3 5 1\n#....\n..#..\n..###",
"output": "#....\n..#.X\n..###"
},
{
"input": "4 5 1\n.....\n.##..\n..#..\n..###",
"output": ".....\n.##..\n..#.X\n..###"
},
{
"input": "3 5 2\n..#..\n..#..\n....#",
"output": "X.#..\nX.#..\n....#"
},
{
"input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########",
"output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########"
},
{
"input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###",
"output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###"
},
{
"input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..",
"output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.."
},
{
"input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..",
"output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.."
},
{
"input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########",
"output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########"
},
{
"input": "4 5 1\n.....\n.###.\n..#..\n..#..",
"output": ".....\n.###.\n..#..\n.X#.."
},
{
"input": "2 5 2\n###..\n###..",
"output": "###X.\n###X."
},
{
"input": "2 5 3\n.....\n..#..",
"output": "X....\nXX#.."
},
{
"input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############",
"output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n#####",
"output": ".....\n.##.X\n..###\n..###\n#####"
},
{
"input": "4 4 1\n....\n.#..\n..##\n..##",
"output": "....\n.#.X\n..##\n..##"
},
{
"input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##",
"output": "....#\n.##..\n.##.X\n...##\n...##"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n..###",
"output": ".....\n.##.X\n..###\n..###\n..###"
},
{
"input": "4 5 1\n#....\n#.#..\n..###\n..###",
"output": "#....\n#.#.X\n..###\n..###"
},
{
"input": "4 4 3\n....\n.#..\n..##\n..##",
"output": "...X\n.#XX\n..##\n..##"
},
{
"input": "4 7 6\n.......\n....#..\n.##.#..\n....#..",
"output": "X......\nX...#..\nX##.#..\nXXX.#.."
},
{
"input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######",
"output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######"
}
] | 1,678,112,054 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 6 | 202 | 19,660,800 | def rl():
return list(map(int,input().split()))
def ri():
return int(input())
def rs():
return input()
def rm():
return map(int,input().split())
def main():
n,m,k=rm()
dr=[1,0,-1,0,1]
g=[]
v=[[False for j in range(m)] for i in range(n)]
for i in range(n):
s=rs()
g.append([s[i] for i in range(m)])
def val(x,y):
if x>-1 and x<n and y>-1 and y<m and g[x][y]=='.' and not v[x][y]: return True
return False
sx,sy=-1,-1
for i in range(n):
for j in range(m):
if g[i][j]=='.': sx,sy=i,j
def dfs(x,y):
v[x][y]=True
nonlocal k
for i in range(4):
# print(x+dr[i],y+dr[i+1])
if val(x+dr[i],y+dr[i+1]):
dfs(x+dr[i],y+dr[i+1])
if k>0: k-=1; g[x][y]='X'
dfs(sx,sy)
# print(k,sx,sy)
for i in range(n):
s=''
for j in range(m):
s+=g[i][j]
print(s)
main() | Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Output Specification:
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
Demo Input:
['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n']
Demo Output:
['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n']
Note:
none | ```python
def rl():
return list(map(int,input().split()))
def ri():
return int(input())
def rs():
return input()
def rm():
return map(int,input().split())
def main():
n,m,k=rm()
dr=[1,0,-1,0,1]
g=[]
v=[[False for j in range(m)] for i in range(n)]
for i in range(n):
s=rs()
g.append([s[i] for i in range(m)])
def val(x,y):
if x>-1 and x<n and y>-1 and y<m and g[x][y]=='.' and not v[x][y]: return True
return False
sx,sy=-1,-1
for i in range(n):
for j in range(m):
if g[i][j]=='.': sx,sy=i,j
def dfs(x,y):
v[x][y]=True
nonlocal k
for i in range(4):
# print(x+dr[i],y+dr[i+1])
if val(x+dr[i],y+dr[i+1]):
dfs(x+dr[i],y+dr[i+1])
if k>0: k-=1; g[x][y]='X'
dfs(sx,sy)
# print(k,sx,sy)
for i in range(n):
s=''
for j in range(m):
s+=g[i][j]
print(s)
main()
``` | -1 |
|
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 6"
},
{
"input": "5\n1 1 1 1 1",
"output": "0 10"
},
{
"input": "5\n2 2 2 2 2",
"output": "0 10"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0 45"
},
{
"input": "3\n2 2 2",
"output": "0 3"
},
{
"input": "3\n3 3 3",
"output": "0 3"
},
{
"input": "2\n10000000 100000000",
"output": "90000000 1"
},
{
"input": "5\n5 5 5 5 5",
"output": "0 10"
},
{
"input": "5\n3 3 3 3 3",
"output": "0 10"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0 15"
},
{
"input": "2\n5 6",
"output": "1 1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0 45"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0 45"
},
{
"input": "4\n4 4 4 4",
"output": "0 6"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0 21"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "0 55"
},
{
"input": "8\n8 8 8 8 8 8 8 8",
"output": "0 28"
},
{
"input": "2\n3 2",
"output": "1 1"
}
] | 1,657,521,959 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 9,830,400 | n = int(input())
lis = list(map(int, input().split()))
lis.sort()
mins = lis.count(lis[0])
maxs = lis.count(lis[-1])
print(lis[-1] - lis[0], mins * maxs) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
Input Specification:
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
Output Specification:
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Demo Input:
['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n']
Demo Output:
['1 1', '4 1', '2 4']
Note:
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | ```python
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
mins = lis.count(lis[0])
maxs = lis.count(lis[-1])
print(lis[-1] - lis[0], mins * maxs)
``` | 0 |
|
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits. | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471"
},
{
"input": "45154",
"output": "22578"
},
{
"input": "60324",
"output": "30163"
},
{
"input": "91840",
"output": "45921"
},
{
"input": "41909",
"output": "20955"
},
{
"input": "58288",
"output": "29145"
},
{
"input": "91641",
"output": "45821"
},
{
"input": "62258",
"output": "31130"
},
{
"input": "79811",
"output": "39906"
},
{
"input": "88740",
"output": "44371"
},
{
"input": "12351",
"output": "6176"
},
{
"input": "1960",
"output": "981"
},
{
"input": "29239",
"output": "14620"
},
{
"input": "85801",
"output": "42901"
},
{
"input": "43255",
"output": "21628"
},
{
"input": "13439",
"output": "6720"
},
{
"input": "35668",
"output": "17835"
},
{
"input": "19122",
"output": "9562"
},
{
"input": "60169",
"output": "30085"
},
{
"input": "50588",
"output": "25295"
},
{
"input": "2467",
"output": "1234"
},
{
"input": "39315",
"output": "19658"
},
{
"input": "29950",
"output": "14976"
},
{
"input": "17286",
"output": "8644"
},
{
"input": "7359066",
"output": "3679534"
},
{
"input": "1016391",
"output": "508196"
},
{
"input": "7928871",
"output": "3964436"
},
{
"input": "3968891",
"output": "1984446"
},
{
"input": "2636452",
"output": "1318227"
},
{
"input": "5076901",
"output": "2538451"
},
{
"input": "9870265",
"output": "4935133"
},
{
"input": "2453786",
"output": "1226894"
},
{
"input": "7263670",
"output": "3631836"
},
{
"input": "1890845",
"output": "945423"
},
{
"input": "574128507",
"output": "287064254"
},
{
"input": "648476655",
"output": "324238328"
},
{
"input": "97349542",
"output": "48674772"
},
{
"input": "716489761",
"output": "358244881"
},
{
"input": "858771038",
"output": "429385520"
},
{
"input": "520778784",
"output": "260389393"
},
{
"input": "439004204",
"output": "219502103"
},
{
"input": "589992198",
"output": "294996100"
},
{
"input": "371106544",
"output": "185553273"
},
{
"input": "894241590",
"output": "447120796"
},
{
"input": "123957268",
"output": "61978635"
},
{
"input": "234149297",
"output": "117074649"
},
{
"input": "789954052",
"output": "394977027"
},
{
"input": "667978920",
"output": "333989461"
},
{
"input": "154647261",
"output": "77323631"
},
{
"input": "751453521",
"output": "375726761"
},
{
"input": "848862308",
"output": "424431155"
},
{
"input": "323926781",
"output": "161963391"
},
{
"input": "576768825",
"output": "288384413"
},
{
"input": "31293802",
"output": "15646902"
},
{
"input": "2",
"output": "2"
},
{
"input": "1000000000",
"output": "500000001"
},
{
"input": "3",
"output": "2"
}
] | 1,573,655,468 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 1,000 | 0 | import math
n = int(input())
cnt = 2
d = 2
while True:
if n//d >= 2:
cnt += 1
d += 1
else:
break
print(cnt if n >= 2 else 1)
| Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits.
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output Specification:
Output one integer — the answer to the problem.
Demo Input:
['7\n', '8\n', '9\n']
Demo Output:
['4\n', '5\n', '5\n']
Note:
In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | ```python
import math
n = int(input())
cnt = 2
d = 2
while True:
if n//d >= 2:
cnt += 1
d += 1
else:
break
print(cnt if n >= 2 else 1)
``` | 0 |
|
624 | B | Making a String | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. | The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer — the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | 1,000 | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "25999999675"
},
{
"input": "2\n559476582 796461544",
"output": "1355938126"
},
{
"input": "2\n257775227 621811272",
"output": "879586499"
},
{
"input": "10\n876938317 219479349 703839299 977218449 116819315 752405530 393874852 286326991 592978634 155758306",
"output": "5075639042"
},
{
"input": "26\n72 49 87 47 94 96 36 91 43 11 19 83 36 38 10 93 95 81 4 96 60 38 97 37 36 41",
"output": "1478"
},
{
"input": "26\n243 364 768 766 633 535 502 424 502 283 592 877 137 891 837 990 681 898 831 487 595 604 747 856 805 688",
"output": "16535"
},
{
"input": "26\n775 517 406 364 548 951 680 984 466 141 960 513 660 849 152 250 176 601 199 370 971 554 141 224 724 543",
"output": "13718"
},
{
"input": "26\n475 344 706 807 925 813 974 166 578 226 624 591 419 894 574 909 544 597 170 990 893 785 399 172 792 748",
"output": "16115"
},
{
"input": "26\n130 396 985 226 487 671 188 706 106 649 38 525 210 133 298 418 953 431 577 69 12 982 264 373 283 266",
"output": "10376"
},
{
"input": "26\n605 641 814 935 936 547 524 702 133 674 173 102 318 620 248 523 77 718 318 635 322 362 306 86 8 442",
"output": "11768"
},
{
"input": "26\n220 675 725 888 725 654 546 806 379 182 604 667 734 394 889 731 572 193 850 651 844 734 163 671 820 887",
"output": "16202"
},
{
"input": "26\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "25675"
},
{
"input": "26\n1001 1001 1000 1000 1001 1000 1001 1001 1001 1000 1000 1001 1001 1000 1000 1000 1000 1001 1000 1001 1001 1000 1001 1001 1001 1000",
"output": "25701"
},
{
"input": "26\n1000 1001 1000 1001 1000 1001 1001 1000 1001 1002 1002 1000 1001 1000 1000 1000 1001 1002 1001 1000 1000 1001 1000 1002 1001 1002",
"output": "25727"
},
{
"input": "26\n1003 1002 1002 1003 1000 1000 1000 1003 1000 1001 1003 1003 1000 1002 1002 1002 1001 1003 1000 1001 1000 1001 1001 1000 1003 1003",
"output": "25753"
},
{
"input": "26\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",
"output": "1"
},
{
"input": "26\n8717 9417 1409 7205 3625 6247 8626 9486 464 4271 1698 8449 4551 1528 7456 9198 4886 2889 7534 506 7867 9410 1635 4955 2580 2580",
"output": "137188"
},
{
"input": "26\n197464663 125058028 622449215 11119637 587496049 703992162 219591040 965159268 229879004 278894000 841629744 616893922 218779915 362575332 844188865 342411376 369680019 43823059 921419789 999588082 943769007 35365522 301907919 758302419 427454397 807507709",
"output": "12776400142"
},
{
"input": "26\n907247856 970380443 957324066 929910532 947150618 944189007 998282297 988343406 981298600 943026596 953932265 972691398 950024048 923033790 996423650 972134755 946404759 918183059 902987271 965507679 906967700 982106487 933997242 972594441 977736332 928874832",
"output": "24770753129"
},
{
"input": "26\n999999061 999999688 999999587 999999429 999999110 999999563 999999120 999999111 999999794 999999890 999999004 999999448 999999770 999999543 999999460 999999034 999999361 999999305 999999201 999999778 999999432 999999844 999999133 999999342 999999600 999999319",
"output": "25999984927"
},
{
"input": "3\n587951561 282383259 612352726",
"output": "1482687546"
},
{
"input": "4\n111637338 992238139 787658714 974622806",
"output": "2866156997"
},
{
"input": "5\n694257603 528073418 726928894 596328666 652863391",
"output": "3198451972"
},
{
"input": "6\n217943380 532900593 902234882 513005821 369342573 495810412",
"output": "3031237661"
},
{
"input": "7\n446656860 478792281 77541870 429682977 85821755 826122363 563802405",
"output": "2908420511"
},
{
"input": "8\n29278125 778590752 252847858 51388836 802299938 215370803 901540149 242074772",
"output": "3273391233"
},
{
"input": "9\n552962902 724482439 133182550 673093696 518779120 604618242 534250189 847695567 403066553",
"output": "4992131258"
},
{
"input": "10\n600386086 862479376 284190454 781950823 672077209 5753052 145701234 680334621 497013634 35429365",
"output": "4565315854"
},
{
"input": "11\n183007351 103343359 164525146 698627979 388556391 926007595 483438978 580927711 659384363 201890880 920750904",
"output": "5310460657"
},
{
"input": "12\n706692128 108170535 339831134 320333838 810063277 20284739 821176722 481520801 467848308 604388203 881959821 874133307",
"output": "6436402813"
},
{
"input": "13\n525349200 54062222 810108418 237010994 821513756 409532178 158915465 87142595 630219037 770849718 843168738 617993222 504443485",
"output": "6470309028"
},
{
"input": "14\n812998169 353860693 690443110 153688149 537992938 798779618 791624505 282706982 733654279 468319337 568341847 597888944 649703235 667623671",
"output": "8107625477"
},
{
"input": "15\n336683946 299752380 865749098 775393009 959499824 893055762 365399057 419335880 896025008 575845364 529550764 341748859 30999793 464432689 19445239",
"output": "7772916672"
},
{
"input": "16\n860368723 540615364 41056086 692070164 970950302 282304201 998108096 24957674 999460249 37279175 490759681 26673285 412295352 671298115 627182888 90740349",
"output": "7766119704"
},
{
"input": "17\n148018692 545442539 980325266 313776023 687429485 376580345 40875544 925549764 161831978 144805202 451968598 475560904 262583806 468107133 60900936 281546097 912565045",
"output": "7237867357"
},
{
"input": "18\n966674765 786305522 860659958 935480883 108937371 60800080 673584584 826142855 560238516 606238013 413177515 455456626 643879364 969943855 963609881 177380550 544192822 864797474",
"output": "11417500634"
},
{
"input": "19\n490360541 496161402 330938242 852158038 120387849 686083328 247359135 431764649 427637949 8736336 843378328 435352349 494167818 766752874 161292122 368186298 470791896 813444279 170758124",
"output": "8615711557"
},
{
"input": "20\n654616375 542649443 729213190 188364665 238384327 726353863 974350390 526804424 601329631 886592063 734805196 275562411 861801362 374466292 119830901 403120565 670982545 63210795 130397643 601611646",
"output": "10304447727"
},
{
"input": "21\n942265343 252505322 904519178 810069524 954862509 115602302 548124942 132426218 999736168 584061682 696014113 960485837 712089816 581331718 317512142 593926314 302610323 716885305 477125514 813997503 535631456",
"output": "12951783229"
},
{
"input": "22\n465951120 788339601 784853870 726746679 376370396 504849742 180834982 33019308 867135601 455551901 657223030 940381560 93386374 378140736 161286599 548696254 934237100 75589518 764917898 731412064 205669368 630662937",
"output": "11305256638"
},
{
"input": "23\n989635897 498195481 255132154 643423835 387820874 894097181 223601429 228583694 265543138 153021520 618431947 684241474 943673829 174949754 358967839 444530707 801900686 965299835 347682577 648826625 406714384 129525158 958578251",
"output": "12022378269"
},
{
"input": "24\n277285866 739058464 135466846 265129694 104300056 519381429 856310469 834204489 132942572 260547547 343605057 664137197 619941683 676786476 497713592 635336455 138557168 618975345 635474960 861212482 76752297 923357675 517046816 274123722",
"output": "11607648357"
},
{
"input": "25\n95942939 979921447 310772834 181806850 525806942 613657573 194049213 734797579 531349109 721980358 304813974 113025815 470230137 473595494 695394833 590106396 770183946 567622150 218239639 778627043 41761505 127248600 134450869 860350034 901937574",
"output": "11937672853"
},
{
"input": "26\n619627716 984748623 486078822 98484005 537257421 2906012 62795060 635390669 103777246 829506385 971050595 92921538 851525695 680460920 893076074 780912144 401811723 221297659 269996214 991012900 242806521 626109821 987889730 682613155 209557740 806895799",
"output": "14070510187"
},
{
"input": "26\n10 1 20 2 23 3 14 6 7 13 26 21 11 8 16 25 12 15 19 9 17 22 24 18 5 4",
"output": "351"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "11"
},
{
"input": "5\n2 2 2 2 2",
"output": "3"
},
{
"input": "10\n10 10 10 10 10 10 10 10 1 1",
"output": "53"
},
{
"input": "10\n100 100 10 10 10 10 10 1 1 1",
"output": "240"
},
{
"input": "6\n5 3 3 3 3 1",
"output": "11"
},
{
"input": "4\n4 3 2 1",
"output": "10"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
}
] | 1,496,337,521 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | dicio = {}
def vernodicio(x):
if x not in dicio:
dicio[x] = True
return x
else:
return vernodicio(x-1)
k = 0
x = int(input())
lista = map(int,input().split())
dicio={}
for i in range(x):
v = vernodicio(lista[i])
k += v
print (k)
# 1496337518524
| Title: Making a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.
Input Specification:
The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string.
Output Specification:
Print a single integer — the maximum length of the string that meets all the requirements.
Demo Input:
['3\n2 5 5\n', '3\n1 1 2\n']
Demo Output:
['11\n', '3\n']
Note:
For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | ```python
dicio = {}
def vernodicio(x):
if x not in dicio:
dicio[x] = True
return x
else:
return vernodicio(x-1)
k = 0
x = int(input())
lista = map(int,input().split())
dicio={}
for i in range(x):
v = vernodicio(lista[i])
k += v
print (k)
# 1496337518524
``` | -1 |
|
446 | C | DZY Loves Fibonacci Numbers | PROGRAMMING | 2,400 | [
"data structures",
"math",
"number theory"
] | null | null | In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Moreover, there are *m* queries, each query has one of the two types:
1. Format of the query "1 *l* *r*". In reply to the query, you need to add *F**i*<=-<=*l*<=+<=1 to each element *a**i*, where *l*<=≤<=*i*<=≤<=*r*. 1. Format of the query "2 *l* *r*". In reply to the query you should output the value of modulo 1000000009 (109<=+<=9).
Help DZY reply to all the queries. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — initial array *a*.
Then, *m* lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1<=≤<=*l*<=≤<=*r*<=≤<=*n* holds. | For each query of the second type, print the value of the sum on a single line. | [
"4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3\n"
] | [
"17\n12\n"
] | After the first query, *a* = [2, 3, 5, 7].
For the second query, *sum* = 2 + 3 + 5 + 7 = 17.
After the third query, *a* = [2, 4, 6, 9].
For the fourth query, *sum* = 2 + 4 + 6 = 12. | 1,500 | [
{
"input": "4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3",
"output": "17\n12"
},
{
"input": "2 2\n1 2\n2 1 2\n2 1 2",
"output": "3\n3"
},
{
"input": "10 20\n56 12 68 23 41 29 97 69 79 76\n1 3 5\n1 8 9\n2 3 10\n1 7 10\n2 1 10\n1 5 10\n2 2 4\n1 2 4\n1 5 6\n2 1 2\n2 4 5\n1 1 5\n1 8 9\n2 5 8\n2 4 7\n2 9 10\n2 4 9\n1 2 10\n1 2 9\n2 7 8",
"output": "488\n563\n105\n69\n71\n256\n210\n175\n373\n217"
}
] | 1,659,804,324 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 2,867,200 | def Fibonacci(n):
if n == 0:
return 0
elif n == 1 or n == 2:
return 1
else:
return Fibonacci(n-1) + Fibonacci(n-2)
a=list()
x = input().split(" ")
n=int(x[0])
m=int(x[1])
a = input().split(" ")
a = [int(i) for i in a]
for i in range(0,m):
inp = input().split(" ")
type= int(inp[0])
l=int(inp[1])
r=int(inp[2])
if type==1:
for i in range(l,r+1):
a[i]+=Fibonacci(i-l+1)
elif type==2:
sum=0
for i in range(l,r+1):
sum+=a[i]
print(sum)
| Title: DZY Loves Fibonacci Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Moreover, there are *m* queries, each query has one of the two types:
1. Format of the query "1 *l* *r*". In reply to the query, you need to add *F**i*<=-<=*l*<=+<=1 to each element *a**i*, where *l*<=≤<=*i*<=≤<=*r*. 1. Format of the query "2 *l* *r*". In reply to the query you should output the value of modulo 1000000009 (109<=+<=9).
Help DZY reply to all the queries.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — initial array *a*.
Then, *m* lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1<=≤<=*l*<=≤<=*r*<=≤<=*n* holds.
Output Specification:
For each query of the second type, print the value of the sum on a single line.
Demo Input:
['4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3\n']
Demo Output:
['17\n12\n']
Note:
After the first query, *a* = [2, 3, 5, 7].
For the second query, *sum* = 2 + 3 + 5 + 7 = 17.
After the third query, *a* = [2, 4, 6, 9].
For the fourth query, *sum* = 2 + 4 + 6 = 12. | ```python
def Fibonacci(n):
if n == 0:
return 0
elif n == 1 or n == 2:
return 1
else:
return Fibonacci(n-1) + Fibonacci(n-2)
a=list()
x = input().split(" ")
n=int(x[0])
m=int(x[1])
a = input().split(" ")
a = [int(i) for i in a]
for i in range(0,m):
inp = input().split(" ")
type= int(inp[0])
l=int(inp[1])
r=int(inp[2])
if type==1:
for i in range(l,r+1):
a[i]+=Fibonacci(i-l+1)
elif type==2:
sum=0
for i in range(l,r+1):
sum+=a[i]
print(sum)
``` | -1 |
|
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 1,670,065,618 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | # LUOGU_RID: 96439898
import sys
a=sys.stdin.readline().strip()
b=sys.stdin.readline().strip()
c=sys.stdin.readline().strip()
f1=f2=0
try:
k1=a.index(b)
k2=a.index(c)
if k1>k2:
f1=1
except:
pass
# print(k1, k2)
try:
k1=a.rindex(b)
k2=a.rindex(c)
if k1<k2:
f2=1
except:
pass
if f1 and f2:
print('both')
elif f1:
print('backward')
elif f2:
print('forward')
else:
print('fantasy') | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
Input Specification:
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output Specification:
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
Demo Input:
['atob\na\nb\n', 'aaacaaa\naca\naa\n']
Demo Output:
['forward\n', 'both\n']
Note:
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | ```python
# LUOGU_RID: 96439898
import sys
a=sys.stdin.readline().strip()
b=sys.stdin.readline().strip()
c=sys.stdin.readline().strip()
f1=f2=0
try:
k1=a.index(b)
k2=a.index(c)
if k1>k2:
f1=1
except:
pass
# print(k1, k2)
try:
k1=a.rindex(b)
k2=a.rindex(c)
if k1<k2:
f2=1
except:
pass
if f1 and f2:
print('both')
elif f1:
print('backward')
elif f2:
print('forward')
else:
print('fantasy')
``` | 0 |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case? | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. | Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished. | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "2999999999"
},
{
"input": "10\n5 7 8 1 10 3 6 4 10 6",
"output": "294"
},
{
"input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8",
"output": "24212"
},
{
"input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62",
"output": "261115"
},
{
"input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644",
"output": "2519223"
},
{
"input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950",
"output": "24496504"
},
{
"input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899",
"output": "685659563557"
},
{
"input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460",
"output": "27409624352"
},
{
"input": "1\n84355694",
"output": "84355694"
},
{
"input": "2\n885992042 510468669",
"output": "1906929379"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1",
"output": "2686"
},
{
"input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1",
"output": "4667"
}
] | 1,567,750,901 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 248 | 0 | n = int(input())
sum1 = 0
cnt = 1
s = input()
l = [int(i) for i in s.split()]
if n > 1:
for i in range(1, n):
cnt += 1
sum1 += 1 + (cnt * (l[i] - 1))
sum1 += l[0]
print(sum1)
else:
print(l[0])
| Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Output Specification:
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['2\n1 1\n', '2\n2 2\n', '1\n10\n']
Demo Output:
['2', '5', '10']
Note:
Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished. | ```python
n = int(input())
sum1 = 0
cnt = 1
s = input()
l = [int(i) for i in s.split()]
if n > 1:
for i in range(1, n):
cnt += 1
sum1 += 1 + (cnt * (l[i] - 1))
sum1 += l[0]
print(sum1)
else:
print(l[0])
``` | 3.938 |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 1,540,724,256 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | flags = str(input())
first = str(input())
second = str(input())
a = flags.find(first))
b = flags.find(second))
t = flags[::-1]
c = t.find(first))
d = t.find(second))
if(a<b) and(c>d):
print("forward")
else if(a>b) and (c<d):
print("backward")
else if(a>b) and(c>d):
print("both")
else:
print("fantasy") | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
Input Specification:
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output Specification:
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
Demo Input:
['atob\na\nb\n', 'aaacaaa\naca\naa\n']
Demo Output:
['forward\n', 'both\n']
Note:
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | ```python
flags = str(input())
first = str(input())
second = str(input())
a = flags.find(first))
b = flags.find(second))
t = flags[::-1]
c = t.find(first))
d = t.find(second))
if(a<b) and(c>d):
print("forward")
else if(a>b) and (c<d):
print("backward")
else if(a>b) and(c>d):
print("both")
else:
print("fantasy")
``` | -1 |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up. | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$. | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "1 10\n1",
"output": "9"
},
{
"input": "1 10000000\n1",
"output": "9999999"
},
{
"input": "1 8\n1",
"output": "7"
},
{
"input": "7 17\n1 5 9 10 11 14 16",
"output": "9"
},
{
"input": "4 17\n1 5 9 10",
"output": "12"
},
{
"input": "5 12\n1 2 3 4 5",
"output": "9"
},
{
"input": "2 1000000000\n100 111",
"output": "999999989"
},
{
"input": "3 90591\n90579 90580 90581",
"output": "90589"
},
{
"input": "5 16\n1 2 3 4 5",
"output": "13"
},
{
"input": "6 981231233\n1 6 15 30 130 1875",
"output": "981229468"
},
{
"input": "1 3\n1",
"output": "2"
},
{
"input": "3 12\n4 7 11",
"output": "8"
},
{
"input": "1 100000\n1",
"output": "99999"
},
{
"input": "2 5\n1 3",
"output": "3"
},
{
"input": "1 1000000000\n1",
"output": "999999999"
},
{
"input": "1 1000000000\n999999999",
"output": "999999999"
},
{
"input": "3 4\n1 2 3",
"output": "2"
},
{
"input": "3 5\n1 2 3",
"output": "3"
},
{
"input": "1 4\n2",
"output": "3"
},
{
"input": "3 5\n1 3 4",
"output": "3"
},
{
"input": "9 20\n5 9 11 12 14 15 16 17 19",
"output": "12"
},
{
"input": "2 4\n1 2",
"output": "3"
},
{
"input": "1 10\n2",
"output": "9"
},
{
"input": "2 6\n2 4",
"output": "4"
},
{
"input": "2 4\n1 3",
"output": "2"
},
{
"input": "3 6\n1 2 4",
"output": "4"
},
{
"input": "7 9863\n65 96 97 98 101 112 1115",
"output": "9819"
}
] | 1,665,967,236 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 13 | 93 | 46,284,800 | n,M = map(int,input().split())
number = [int(i) for i in input().split()]
number.insert(0,0)
number.append(M)
a = 0
time = set()
for i in range(1,n+2):
if i%2==1:
a = a+number[i]-number[i-1]
time.add(a)
b = M-a
for i in range(1,n+1):
if number[i]-1!= number[i-1] or number[i]+1!=number[i+1]:
if i%2==1:
b = b+number[i]-number[i-1]
c = b-1
time.add(c)
if i%2==0:
b = b-number[i]+number[i-1]
print(max(time)) | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
Input Specification:
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
Output Specification:
Print the only integer — maximum possible total time when the lamp is lit.
Demo Input:
['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n']
Demo Output:
['8\n', '9\n', '6\n']
Note:
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | ```python
n,M = map(int,input().split())
number = [int(i) for i in input().split()]
number.insert(0,0)
number.append(M)
a = 0
time = set()
for i in range(1,n+2):
if i%2==1:
a = a+number[i]-number[i-1]
time.add(a)
b = M-a
for i in range(1,n+1):
if number[i]-1!= number[i-1] or number[i]+1!=number[i+1]:
if i%2==1:
b = b+number[i]-number[i-1]
c = b-1
time.add(c)
if i%2==0:
b = b-number[i]+number[i-1]
print(max(time))
``` | 0 |
|
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,570,114,657 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | def lcm(a,b):
if(a<b):
c=b
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
else :
c=a
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
x = input()
a = x.split(" ")
print(int(int(a[2])/(lcm(int(a[0]),int(a[1])))))
| 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
def lcm(a,b):
if(a<b):
c=b
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
else :
c=a
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
x = input()
a = x.split(" ")
print(int(int(a[2])/(lcm(int(a[0]),int(a[1])))))
``` | 3 |
|
749 | C | Voting | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"two pointers"
] | null | null | There are *n* employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:
1. Each of *n* employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee *n*. If at the moment when it's time for the *i*-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). 1. When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. 1. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with *n* who are still eligible to vote make their statements. 1. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of employees.
The next line contains *n* characters. The *i*-th character is 'D' if the *i*-th employee is from depublicans fraction or 'R' if he is from remocrats. | Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. | [
"5\nDDRRR\n",
"6\nDDRRRR\n"
] | [
"D\n",
"R\n"
] | Consider one of the voting scenarios for the first sample:
1. Employee 1 denies employee 5 to vote. 1. Employee 2 denies employee 3 to vote. 1. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). 1. Employee 4 denies employee 2 to vote. 1. Employee 5 has no right to vote and skips his turn (he was denied by employee 1). 1. Employee 1 denies employee 4. 1. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans. | 1,500 | [
{
"input": "5\nDDRRR",
"output": "D"
},
{
"input": "6\nDDRRRR",
"output": "R"
},
{
"input": "1\nD",
"output": "D"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "2\nDR",
"output": "D"
},
{
"input": "3\nRDD",
"output": "D"
},
{
"input": "3\nDRD",
"output": "D"
},
{
"input": "4\nDRRD",
"output": "D"
},
{
"input": "4\nDRRR",
"output": "R"
},
{
"input": "4\nRDRD",
"output": "R"
},
{
"input": "5\nDRDRR",
"output": "D"
},
{
"input": "4\nRRRR",
"output": "R"
},
{
"input": "5\nRDDRD",
"output": "D"
},
{
"input": "5\nDDRRD",
"output": "D"
},
{
"input": "5\nDRRRD",
"output": "R"
},
{
"input": "5\nDDDDD",
"output": "D"
},
{
"input": "6\nDRRDDR",
"output": "D"
},
{
"input": "7\nRDRDRDD",
"output": "R"
},
{
"input": "7\nRDRDDRD",
"output": "D"
},
{
"input": "7\nRRRDDDD",
"output": "R"
},
{
"input": "8\nRRRDDDDD",
"output": "D"
},
{
"input": "9\nRRRDDDDDR",
"output": "R"
},
{
"input": "9\nRRDDDRRDD",
"output": "R"
},
{
"input": "9\nRRDDDRDRD",
"output": "D"
},
{
"input": "10\nDDRRRDRRDD",
"output": "D"
},
{
"input": "11\nDRDRRDDRDDR",
"output": "D"
},
{
"input": "12\nDRDRDRDRRDRD",
"output": "D"
},
{
"input": "13\nDRDDDDRRRRDDR",
"output": "D"
},
{
"input": "14\nDDRDRRDRDRDDDD",
"output": "D"
},
{
"input": "15\nDDRRRDDRDRRRDRD",
"output": "D"
},
{
"input": "50\nDDDRDRDDDDRRRRDDDDRRRDRRRDDDRRRRDRDDDRRDRRDDDRDDDD",
"output": "D"
},
{
"input": "50\nDRDDDDDDDRDRDDRRRDRDRDRDDDRRDRRDRDRRDDDRDDRDRDRDDR",
"output": "D"
},
{
"input": "100\nRDRRDRDDDDRDRRDDRDRRDDRRDDRRRDRRRDDDRDDRDDRRDRDRRRDRDRRRDRRDDDRDDRRRDRDRRRDDRDRDDDDDDDRDRRDDDDDDRRDD",
"output": "D"
},
{
"input": "100\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD",
"output": "R"
},
{
"input": "6\nRDDRDR",
"output": "D"
},
{
"input": "6\nDRRDRD",
"output": "R"
},
{
"input": "8\nDDDRRRRR",
"output": "R"
},
{
"input": "7\nRRRDDDD",
"output": "R"
},
{
"input": "7\nRDDRRDD",
"output": "D"
},
{
"input": "9\nRDDDRRDRR",
"output": "R"
},
{
"input": "5\nRDRDD",
"output": "R"
},
{
"input": "5\nRRDDD",
"output": "R"
},
{
"input": "8\nRDDRDRRD",
"output": "R"
},
{
"input": "10\nDRRRDDRDRD",
"output": "R"
},
{
"input": "7\nDRRDDRR",
"output": "R"
},
{
"input": "12\nRDDDRRDRRDDR",
"output": "D"
},
{
"input": "7\nRDRDDDR",
"output": "D"
},
{
"input": "7\nDDRRRDR",
"output": "R"
},
{
"input": "10\nDRRDRDRDRD",
"output": "R"
},
{
"input": "21\nDDDDRRRRRDRDRDRDRDRDR",
"output": "R"
},
{
"input": "11\nRDDDDDRRRRR",
"output": "D"
},
{
"input": "10\nRDDDRRRDDR",
"output": "D"
},
{
"input": "4\nRDDR",
"output": "R"
},
{
"input": "7\nRDRDDRD",
"output": "D"
},
{
"input": "8\nRDDDRRRD",
"output": "R"
},
{
"input": "16\nDRRDRDRDRDDRDRDR",
"output": "R"
},
{
"input": "8\nDRRDRDRD",
"output": "R"
},
{
"input": "6\nRDDDRR",
"output": "D"
},
{
"input": "10\nDDRRRRRDDD",
"output": "D"
},
{
"input": "7\nDDRRRRD",
"output": "R"
},
{
"input": "12\nRDDRDRDRRDRD",
"output": "D"
},
{
"input": "9\nDDRRRDRDR",
"output": "R"
},
{
"input": "20\nRDDRDRDRDRRDRDRDRDDR",
"output": "D"
},
{
"input": "7\nRRDDDRD",
"output": "D"
},
{
"input": "12\nDRRRRRRDDDDD",
"output": "R"
},
{
"input": "12\nRDRDDRDRDRDR",
"output": "D"
},
{
"input": "6\nDDDDDD",
"output": "D"
},
{
"input": "10\nRRRDDRDDDD",
"output": "R"
},
{
"input": "40\nRDDDRDDDRDRRDRDRRRRRDRDRDRDRRDRDRDRRDDDD",
"output": "R"
},
{
"input": "50\nRRDDDRRDRRRDDRDDDDDRDDRRRRRRDRDDRDDDRDRRDDRDDDRDRD",
"output": "D"
},
{
"input": "5\nRDRDR",
"output": "R"
},
{
"input": "9\nDRRDRDDRR",
"output": "R"
},
{
"input": "6\nDRRRDD",
"output": "R"
},
{
"input": "10\nDDDDRRRRRR",
"output": "D"
},
{
"input": "9\nRRDDDDRRD",
"output": "D"
}
] | 1,668,507,065 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 144 | 124 | 12,595,200 | from collections import deque
n=int(input())
a=input()
q1=deque()
q2=deque()
for i in range(n):
if a[i]=='D':
q1.append(i)
else:
q2.append(i)
while q1 and q2:
# print(q1[0],q2[0])
if q1[0]<q2[0]:
q2.popleft()
q1.append(n+q1.popleft())
else:
q1.popleft()
q2.append(n+q2.popleft())
if q1:
print("D")
else:
print("R") | Title: Voting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:
1. Each of *n* employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee *n*. If at the moment when it's time for the *i*-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). 1. When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. 1. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with *n* who are still eligible to vote make their statements. 1. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of employees.
The next line contains *n* characters. The *i*-th character is 'D' if the *i*-th employee is from depublicans fraction or 'R' if he is from remocrats.
Output Specification:
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
Demo Input:
['5\nDDRRR\n', '6\nDDRRRR\n']
Demo Output:
['D\n', 'R\n']
Note:
Consider one of the voting scenarios for the first sample:
1. Employee 1 denies employee 5 to vote. 1. Employee 2 denies employee 3 to vote. 1. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). 1. Employee 4 denies employee 2 to vote. 1. Employee 5 has no right to vote and skips his turn (he was denied by employee 1). 1. Employee 1 denies employee 4. 1. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans. | ```python
from collections import deque
n=int(input())
a=input()
q1=deque()
q2=deque()
for i in range(n):
if a[i]=='D':
q1.append(i)
else:
q2.append(i)
while q1 and q2:
# print(q1[0],q2[0])
if q1[0]<q2[0]:
q2.popleft()
q1.append(n+q1.popleft())
else:
q1.popleft()
q2.append(n+q2.popleft())
if q1:
print("D")
else:
print("R")
``` | 3 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,699,912,238 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 307,200 | n = int(input())
user_input = input()
input_list = user_input.split(" ")
skills = {
'prog' : [],
'math' : [],
'PE' : []
}
for i,value in enumerate(input_list):
if value == '1':
skills['prog'].append(i+1)
if value == '2':
skills['math'].append(i+1)
if value == '3':
skills['PE'].append(i+1)
teams = min(min(len(skills['prog']), len(skills['math'])), len(skills['PE']))
print(teams)
for i in range(teams):
prog = skills['prog']
math = skills['math']
PE = skills['PE']
print(prog[i], math[i], PE[i]) | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
n = int(input())
user_input = input()
input_list = user_input.split(" ")
skills = {
'prog' : [],
'math' : [],
'PE' : []
}
for i,value in enumerate(input_list):
if value == '1':
skills['prog'].append(i+1)
if value == '2':
skills['math'].append(i+1)
if value == '3':
skills['PE'].append(i+1)
teams = min(min(len(skills['prog']), len(skills['math'])), len(skills['PE']))
print(teams)
for i in range(teams):
prog = skills['prog']
math = skills['math']
PE = skills['PE']
print(prog[i], math[i], PE[i])
``` | 3 |
|
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"output": "653"
},
{
"input": "194",
"output": "120"
},
{
"input": "906",
"output": "786"
},
{
"input": "659",
"output": "535"
},
{
"input": "75",
"output": "37"
},
{
"input": "787",
"output": "664"
},
{
"input": "851",
"output": "730"
},
{
"input": "563",
"output": "446"
},
{
"input": "979",
"output": "862"
},
{
"input": "395",
"output": "291"
},
{
"input": "755",
"output": "634"
},
{
"input": "171",
"output": "103"
},
{
"input": "883",
"output": "759"
},
{
"input": "400",
"output": "294"
},
{
"input": "817",
"output": "693"
},
{
"input": "177",
"output": "107"
},
{
"input": "593",
"output": "476"
},
{
"input": "305",
"output": "214"
},
{
"input": "721",
"output": "595"
},
{
"input": "785",
"output": "664"
},
{
"input": "497",
"output": "383"
},
{
"input": "913",
"output": "791"
},
{
"input": "625",
"output": "507"
},
{
"input": "334",
"output": "236"
},
{
"input": "10000",
"output": "12471"
},
{
"input": "9999",
"output": "12467"
}
] | 1,598,430,780 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 3,000 | 7,680,000 | def pythagoras():
n=int(input())
l=[x**2 for x in range(1,n+1)]
sumlist=[]
count=0
for i in range(n-1):
for j in range(i+1,n):
sumlist.append(l[i]+l[j])
for i in range(n):
for j in range(len(sumlist)-1):
if sumlist[j]==l[i]:
count += 1
print(count)
pythagoras()
| Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
Input Specification:
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5\n', '74\n']
Demo Output:
['1\n', '35\n']
Note:
none | ```python
def pythagoras():
n=int(input())
l=[x**2 for x in range(1,n+1)]
sumlist=[]
count=0
for i in range(n-1):
for j in range(i+1,n):
sumlist.append(l[i]+l[j])
for i in range(n):
for j in range(len(sumlist)-1):
if sumlist[j]==l[i]:
count += 1
print(count)
pythagoras()
``` | 0 |
|
873 | C | Strange Game On Matrix | PROGRAMMING | 1,600 | [
"greedy",
"two pointers"
] | null | null | Ivan is playing a strange game.
He has a matrix *a* with *n* rows and *m* columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:
1. Initially Ivan's score is 0; 1. In each column, Ivan will find the topmost 1 (that is, if the current column is *j*, then he will find minimum *i* such that *a**i*,<=*j*<==<=1). If there are no 1's in the column, this column is skipped; 1. Ivan will look at the next *min*(*k*,<=*n*<=-<=*i*<=+<=1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score.
Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. | The first line contains three integer numbers *n*, *m* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100).
Then *n* lines follow, *i*-th of them contains *m* integer numbers — the elements of *i*-th row of matrix *a*. Each number is either 0 or 1. | Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. | [
"4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1\n",
"3 2 1\n1 0\n0 1\n0 0\n"
] | [
"4 1\n",
"2 0\n"
] | In the first example Ivan will replace the element *a*<sub class="lower-index">1, 2</sub>. | 0 | [
{
"input": "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1",
"output": "4 1"
},
{
"input": "3 2 1\n1 0\n0 1\n0 0",
"output": "2 0"
},
{
"input": "3 4 2\n0 1 1 1\n1 0 1 1\n1 0 0 1",
"output": "7 0"
},
{
"input": "3 57 3\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 1 0\n1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0\n1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1",
"output": "80 0"
},
{
"input": "1 1 1\n1",
"output": "1 0"
},
{
"input": "1 1 1\n0",
"output": "0 0"
},
{
"input": "2 2 1\n0 1\n1 0",
"output": "2 0"
},
{
"input": "100 1 20\n0\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n1\n1\n0\n0\n0\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n0\n0\n1\n1\n1\n1\n1\n0\n1",
"output": "13 34"
},
{
"input": "1 100 1\n0 0 1 1 1 0 1 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 1 1 1 1 0 0 1 0 1 1 1 0 1 0 0 1 0 0 1 1 1",
"output": "53 0"
}
] | 1,630,824,486 | 1,086 | PyPy 3 | OK | TESTS | 20 | 124 | 22,528,000 | import bisect
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0, 0]
for j in range(m):
x = []
for i in range(n):
if a[i][j] == 1:
x.append(i)
m, c = 0, 0
for i in range(len(x)):
j = bisect.bisect_left(x, x[i] + k - 0.5)
if m < j - i:
m = j - i
c = i
ans[0] += m
ans[1] += c
print(*ans) | Title: Strange Game On Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan is playing a strange game.
He has a matrix *a* with *n* rows and *m* columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:
1. Initially Ivan's score is 0; 1. In each column, Ivan will find the topmost 1 (that is, if the current column is *j*, then he will find minimum *i* such that *a**i*,<=*j*<==<=1). If there are no 1's in the column, this column is skipped; 1. Ivan will look at the next *min*(*k*,<=*n*<=-<=*i*<=+<=1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score.
Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score.
Input Specification:
The first line contains three integer numbers *n*, *m* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100).
Then *n* lines follow, *i*-th of them contains *m* integer numbers — the elements of *i*-th row of matrix *a*. Each number is either 0 or 1.
Output Specification:
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
Demo Input:
['4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1\n', '3 2 1\n1 0\n0 1\n0 0\n']
Demo Output:
['4 1\n', '2 0\n']
Note:
In the first example Ivan will replace the element *a*<sub class="lower-index">1, 2</sub>. | ```python
import bisect
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0, 0]
for j in range(m):
x = []
for i in range(n):
if a[i][j] == 1:
x.append(i)
m, c = 0, 0
for i in range(len(x)):
j = bisect.bisect_left(x, x[i] + k - 0.5)
if m < j - i:
m = j - i
c = i
ans[0] += m
ans[1] += c
print(*ans)
``` | 3 |
|
678 | C | Joty and Chocolate | PROGRAMMING | 1,600 | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get. | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | 0 | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
},
{
"input": "4 1 5 4 3",
"output": "16"
},
{
"input": "8 8 1 1 1",
"output": "8"
},
{
"input": "15 14 32 65 28",
"output": "65"
},
{
"input": "894 197 325 232 902",
"output": "2732"
},
{
"input": "8581 6058 3019 2151 4140",
"output": "10431"
},
{
"input": "41764 97259 54586 18013 75415",
"output": "0"
},
{
"input": "333625 453145 800800 907251 446081",
"output": "0"
},
{
"input": "4394826 2233224 609367 3364334 898489",
"output": "9653757"
},
{
"input": "13350712 76770926 61331309 8735000 9057368",
"output": "0"
},
{
"input": "142098087 687355301 987788392 75187408 868856364",
"output": "0"
},
{
"input": "1000000000 1 3 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "6 6 2 8 2",
"output": "12"
},
{
"input": "500 8 4 4 5",
"output": "625"
},
{
"input": "20 4 6 2 3",
"output": "17"
},
{
"input": "10 3 9 1 2",
"output": "4"
},
{
"input": "120 18 6 3 5",
"output": "100"
},
{
"input": "30 4 6 2 2",
"output": "20"
},
{
"input": "1000000000 7171 2727 191 272",
"output": "125391842"
},
{
"input": "5 2 2 4 1",
"output": "8"
},
{
"input": "1000000000 2 2 3 3",
"output": "1500000000"
},
{
"input": "24 4 6 5 7",
"output": "48"
},
{
"input": "216 6 36 10 100",
"output": "900"
},
{
"input": "100 12 6 1 10",
"output": "160"
},
{
"input": "1000 4 8 3 5",
"output": "1000"
},
{
"input": "10 2 4 3 6",
"output": "21"
},
{
"input": "1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 5 10 2 3",
"output": "5"
},
{
"input": "100000 3 9 1 2",
"output": "44444"
},
{
"input": "10 2 4 1 100",
"output": "203"
},
{
"input": "20 6 4 2 3",
"output": "19"
},
{
"input": "1200 4 16 2 3",
"output": "675"
},
{
"input": "7 2 4 7 9",
"output": "23"
},
{
"input": "24 6 4 15 10",
"output": "100"
},
{
"input": "50 2 8 15 13",
"output": "375"
},
{
"input": "100 4 6 12 15",
"output": "444"
},
{
"input": "56756 9 18 56 78",
"output": "422502"
},
{
"input": "10000 4 6 10 12",
"output": "36662"
},
{
"input": "20 2 4 3 5",
"output": "40"
},
{
"input": "24 4 6 10 100",
"output": "440"
},
{
"input": "12 2 4 5 6",
"output": "33"
},
{
"input": "100 2 4 1 100",
"output": "2525"
},
{
"input": "1000 4 6 50 50",
"output": "16650"
},
{
"input": "60 12 6 12 15",
"output": "150"
},
{
"input": "1000 2 4 5 6",
"output": "2750"
},
{
"input": "1000000000 1 1 9999 5555",
"output": "9999000000000"
},
{
"input": "50 2 2 4 5",
"output": "125"
},
{
"input": "14 4 2 2 3",
"output": "21"
},
{
"input": "100 3 9 1 2",
"output": "44"
},
{
"input": "1000000000 4 6 1 1000000000",
"output": "166666666166666667"
},
{
"input": "12 3 3 45 4",
"output": "180"
},
{
"input": "12 2 4 5 9",
"output": "42"
},
{
"input": "1000000000 2 2 1000000000 1000000000",
"output": "500000000000000000"
},
{
"input": "50 4 8 5 6",
"output": "66"
},
{
"input": "32 4 16 6 3",
"output": "48"
},
{
"input": "10000 2 4 1 1",
"output": "5000"
},
{
"input": "8 2 4 100 1",
"output": "400"
},
{
"input": "20 4 2 10 1",
"output": "55"
},
{
"input": "5 2 2 12 15",
"output": "30"
},
{
"input": "20 2 12 5 6",
"output": "51"
},
{
"input": "10 2 4 1 2",
"output": "7"
},
{
"input": "32 4 16 3 6",
"output": "30"
},
{
"input": "50 2 8 13 15",
"output": "337"
},
{
"input": "12 6 4 10 9",
"output": "38"
},
{
"input": "1000000000 999999998 999999999 999999998 999999999",
"output": "1999999997"
},
{
"input": "20 2 4 10 20",
"output": "150"
},
{
"input": "13 4 6 12 15",
"output": "54"
},
{
"input": "30 3 6 5 7",
"output": "60"
},
{
"input": "7 2 4 2 1",
"output": "6"
},
{
"input": "100000 32 16 2 3",
"output": "18750"
},
{
"input": "6 2 6 1 1",
"output": "3"
},
{
"input": "999999999 180 192 46642017 28801397",
"output": "399129078526502"
},
{
"input": "12 4 6 1 1",
"output": "4"
},
{
"input": "10 2 4 10 5",
"output": "50"
},
{
"input": "1000000 4 6 12 14",
"output": "4333328"
},
{
"input": "2000 20 30 3 5",
"output": "531"
},
{
"input": "1000000000 1 2 1 1",
"output": "1000000000"
},
{
"input": "30 3 15 10 3",
"output": "100"
},
{
"input": "1000 2 4 1 100",
"output": "25250"
},
{
"input": "6 3 3 12 15",
"output": "30"
},
{
"input": "24 4 6 1 1",
"output": "8"
},
{
"input": "20 2 12 4 5",
"output": "41"
},
{
"input": "1000000000 9 15 10 10",
"output": "1555555550"
},
{
"input": "16 2 4 1 2",
"output": "12"
},
{
"input": "100000 4 6 12 14",
"output": "433328"
},
{
"input": "24 6 4 1 1",
"output": "8"
},
{
"input": "1000000 4 6 12 15",
"output": "4499994"
},
{
"input": "100 2 4 5 6",
"output": "275"
},
{
"input": "10 3 9 12 15",
"output": "39"
},
{
"input": "1000000000 1 1 999999999 999999999",
"output": "999999999000000000"
},
{
"input": "6 2 4 2 3",
"output": "7"
},
{
"input": "2 2 2 2 2",
"output": "2"
},
{
"input": "6 6 2 1 1",
"output": "3"
},
{
"input": "100 2 4 3 7",
"output": "250"
},
{
"input": "1000000 32 16 2 5",
"output": "312500"
},
{
"input": "100 20 15 50 25",
"output": "375"
},
{
"input": "1000000000 100000007 100000013 10 3",
"output": "117"
},
{
"input": "1000000000 9999999 99999998 3 3",
"output": "330"
},
{
"input": "10077696 24 36 10 100",
"output": "30792960"
},
{
"input": "392852503 148746166 420198270 517065752 906699795",
"output": "1034131504"
},
{
"input": "536870912 60000 72000 271828 314159",
"output": "4369119072"
},
{
"input": "730114139 21550542 204644733 680083361 11353255",
"output": "22476810678"
},
{
"input": "538228881 766493289 791886544 468896052 600136703",
"output": "0"
},
{
"input": "190 20 50 84 172",
"output": "1188"
},
{
"input": "1000 5 10 80 90",
"output": "17000"
},
{
"input": "99999999 999999998 1 271828 314159",
"output": "31415899685841"
},
{
"input": "22 3 6 1243 1",
"output": "8701"
},
{
"input": "15 10 5 2 2",
"output": "6"
},
{
"input": "1000000000 1000000000 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "62 62 42 78 124",
"output": "202"
},
{
"input": "2 2 2 2 1",
"output": "2"
},
{
"input": "864351351 351 313 531 11",
"output": "1337898227"
},
{
"input": "26 3 6 1244 1",
"output": "9952"
},
{
"input": "1000 4 6 7 3",
"output": "1999"
},
{
"input": "134312 3 6 33333 1",
"output": "1492318410"
},
{
"input": "100 4 6 17 18",
"output": "577"
},
{
"input": "6 2 4 5 6",
"output": "16"
},
{
"input": "8 2 4 10 1",
"output": "40"
},
{
"input": "10 2 4 3 3",
"output": "15"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "1000"
},
{
"input": "123123 3 6 34312 2",
"output": "1408198792"
},
{
"input": "1000000000 25 5 999 999",
"output": "199800000000"
},
{
"input": "100 4 2 5 12",
"output": "600"
},
{
"input": "50 2 4 4 5",
"output": "112"
},
{
"input": "24 4 6 100 333",
"output": "1732"
},
{
"input": "216 24 36 10 100",
"output": "660"
},
{
"input": "50 6 4 3 8",
"output": "108"
},
{
"input": "146 76 2 178 192",
"output": "14016"
},
{
"input": "55 8 6 11 20",
"output": "224"
},
{
"input": "5 2 4 6 16",
"output": "22"
},
{
"input": "54 2 52 50 188",
"output": "1488"
},
{
"input": "536870912 60000000 72000000 271828 314159",
"output": "4101909"
},
{
"input": "1000000000 1000000000 1 1 100",
"output": "100000000000"
},
{
"input": "50 4 2 4 5",
"output": "125"
},
{
"input": "198 56 56 122 118",
"output": "366"
},
{
"input": "5 1000000000 1 12 15",
"output": "75"
},
{
"input": "1000 6 12 5 6",
"output": "913"
},
{
"input": "50 3 6 12 15",
"output": "216"
},
{
"input": "333 300 300 300 300",
"output": "300"
},
{
"input": "1 1000000000 1 1 2",
"output": "2"
},
{
"input": "188 110 110 200 78",
"output": "200"
},
{
"input": "100000 20 10 3 2",
"output": "25000"
},
{
"input": "100 2 4 1 10",
"output": "275"
},
{
"input": "1000000000 2 1000000000 1 1000000",
"output": "500999999"
},
{
"input": "20 3 6 5 7",
"output": "36"
},
{
"input": "50 4 6 4 5",
"output": "72"
},
{
"input": "96 46 4 174 156",
"output": "3936"
},
{
"input": "5 2 4 12 15",
"output": "27"
},
{
"input": "12 3 6 100 1",
"output": "400"
},
{
"input": "100 4 2 10 32",
"output": "1600"
},
{
"input": "1232 3 6 30000 3",
"output": "12300000"
},
{
"input": "20 3 6 5 4",
"output": "30"
},
{
"input": "100 6 15 11 29",
"output": "317"
},
{
"input": "10000000 4 8 100 200",
"output": "375000000"
},
{
"input": "1000000000 12 24 2 4",
"output": "249999998"
},
{
"input": "123 3 6 3000 1",
"output": "123000"
},
{
"input": "401523968 1536 2664 271828 314159",
"output": "117768531682"
},
{
"input": "9 2 4 3 5",
"output": "16"
},
{
"input": "999999999 724362018 772432019 46201854 20017479",
"output": "66219333"
},
{
"input": "100 2 4 1 1000",
"output": "25025"
},
{
"input": "50 2 4 1 1000",
"output": "12013"
},
{
"input": "1000000000 2 1 2 1",
"output": "1500000000"
},
{
"input": "1000000000 2005034 2005046 15 12",
"output": "13446"
},
{
"input": "1000000000 999999999 1000000000 1 1",
"output": "2"
},
{
"input": "999999999 500000000 1 100 1000",
"output": "999999999000"
},
{
"input": "50 8 6 3 4",
"output": "44"
},
{
"input": "1000000000 1 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000000 999999862 999999818 15 12",
"output": "27"
},
{
"input": "1000000000 10000019 10000019 21 17",
"output": "2079"
},
{
"input": "20 6 4 8 2",
"output": "32"
},
{
"input": "1000000000 1000000000 1 1 1",
"output": "1000000000"
},
{
"input": "1000000000 12345678 123456789 1000000000 999999999",
"output": "88999999992"
},
{
"input": "1000000000 2 999999937 100000000 100000000",
"output": "50000000100000000"
},
{
"input": "1000000000 1 1 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "1000000000 50001 100003 10 10",
"output": "299980"
},
{
"input": "1000000000 1000000000 3 1 1",
"output": "333333334"
},
{
"input": "10000 44 49 114 514",
"output": "130278"
},
{
"input": "30 5 15 2 1",
"output": "12"
},
{
"input": "20 2 4 1 1",
"output": "10"
},
{
"input": "100 8 12 5 6",
"output": "88"
}
] | 1,571,582,028 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 1,740,800 | n, a, b, p, q = list(map(int,input().split()))
k = 0
for i in range(a,n + 1,a):
if i % a == 0 and i % b == 0:
k += max(p,q)
else:
k += p
for j in range(b,n + 1,b):
if j % a != 0:
k += q
print(k)
| Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
Input Specification:
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Output Specification:
Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['5 2 3 12 15\n', '20 2 3 3 5\n']
Demo Output:
['39\n', '51\n']
Note:
none | ```python
n, a, b, p, q = list(map(int,input().split()))
k = 0
for i in range(a,n + 1,a):
if i % a == 0 and i % b == 0:
k += max(p,q)
else:
k += p
for j in range(b,n + 1,b):
if j % a != 0:
k += q
print(k)
``` | 0 |
|
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends. | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters. | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 1 1 1 1",
"output": "6.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 2 2 2 2",
"output": "12.0000000000"
},
{
"input": "4 1\n3 3 3 3 4 4 4 4",
"output": "1.0000000000"
},
{
"input": "2 19\n3 3 5 5",
"output": "15.0000000000"
},
{
"input": "3 31\n3 3 3 5 5 5",
"output": "22.5000000000"
},
{
"input": "5 15\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "5 14\n2 3 4 1 2 4 5 3 5 10",
"output": "14.0000000000"
},
{
"input": "5 16\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "1 100\n1 200",
"output": "3.0000000000"
},
{
"input": "1 1\n1 1",
"output": "1.0000000000"
},
{
"input": "2 1000000000\n1 1 1 100",
"output": "3.0000000000"
},
{
"input": "4 30\n3 3 3 3 4 5 6 7",
"output": "24.0000000000"
},
{
"input": "2 100\n1 1 1 10",
"output": "3.0000000000"
},
{
"input": "3 18\n1 1 1 1 1 5",
"output": "4.5000000000"
}
] | 1,436,315,611 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 404 | 20,480,000 | l2 = input().split()
n = int(l2[0])
w = int(l2[1])
l = map(int, input().split())
l = sorted(l, reverse=True)
minB = 2000000000
minG = 2000000000
for i in range(n):
minB = min(minB, l[i])
minG = min(minB, l[i+n])
x = min(minB/2, minG)
print(min(w,n*x*3))
| Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.
Input Specification:
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters.
Output Specification:
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['2 4\n1 1 1 1\n', '3 18\n4 4 4 2 2 2\n', '1 5\n2 3\n']
Demo Output:
['3', '18', '4.5']
Note:
Pasha also has candies that he is going to give to girls but that is another task... | ```python
l2 = input().split()
n = int(l2[0])
w = int(l2[1])
l = map(int, input().split())
l = sorted(l, reverse=True)
minB = 2000000000
minG = 2000000000
for i in range(n):
minB = min(minB, l[i])
minG = min(minB, l[i+n])
x = min(minB/2, minG)
print(min(w,n*x*3))
``` | 3 |
|
351 | A | Jeff and Rounding | PROGRAMMING | 1,800 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as follows:
- choose indexes *i* and *j* (*i*<=≠<=*j*) that haven't been chosen yet; - round element *a**i* to the nearest integer that isn't more than *a**i* (assign to *a**i*: ⌊ *a**i* ⌋); - round element *a**j* to the nearest integer that isn't less than *a**j* (assign to *a**j*: ⌈ *a**j* ⌉).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains 2*n* real numbers *a*1, *a*2, ..., *a*2*n* (0<=≤<=*a**i*<=≤<=10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | [
"3\n0.000 0.500 0.750 1.000 2.000 3.000\n",
"3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\n"
] | [
"0.250\n",
"0.279\n"
] | In the first test case you need to perform the operations as follows: (*i* = 1, *j* = 4), (*i* = 2, *j* = 3), (*i* = 5, *j* = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | 1,000 | [
{
"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000",
"output": "0.250"
},
{
"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896",
"output": "0.279"
},
{
"input": "3\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000",
"output": "0.184"
},
{
"input": "3\n6470.649 8295.000 8486.000 9855.000 223.000 579.549",
"output": "0.198"
},
{
"input": "7\n2341.538 9232.119 6646.930 9316.834 5684.000 9078.705 7773.000 3823.674 6357.022 9866.925 310.271 6554.778 8341.098 8407.987",
"output": "0.119"
},
{
"input": "9\n5528.000 205.031 5245.169 8832.592 385.656 7126.360 3988.000 9542.000 3044.042 5288.351 9342.000 9979.021 7096.000 5159.200 9400.000 4996.735 1698.000 5403.939",
"output": "0.096"
},
{
"input": "5\n4103.000 6413.459 1796.000 3486.000 9011.000 5564.000 9044.000 5922.539 3350.039 3746.000",
"output": "0.037"
},
{
"input": "7\n223.999 322.000 677.000 3852.477 2568.390 2410.000 3202.511 2122.870 1566.000 8841.000 8176.424 74.586 3834.000 6847.427",
"output": "0.316"
},
{
"input": "10\n8003.867 4368.000 2243.000 3340.287 5384.000 1036.456 3506.000 4463.000 1477.000 2420.314 9391.000 1696.000 5857.833 244.000 8220.000 5879.000 5424.482 2631.197 7111.000 9157.536",
"output": "0.028"
},
{
"input": "1\n6418.000 157.986",
"output": "0.014"
},
{
"input": "2\n950.000 8019.170 3179.479 9482.963",
"output": "0.388"
},
{
"input": "3\n4469.437 6526.605 4864.154 9356.383 7490.717 995.896",
"output": "0.192"
},
{
"input": "3\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000",
"output": "0.184"
},
{
"input": "3\n6470.649 8295.806 8486.730 9855.351 223.102 579.000",
"output": "0.362"
},
{
"input": "7\n2341.538 9232.119 6646.930 9316.834 5684.640 9078.705 7773.000 3823.674 6357.022 9866.925 310.271 6554.778 8341.098 8407.000",
"output": "0.466"
},
{
"input": "9\n5528.947 205.031 5245.169 8832.592 385.656 7126.360 3988.000 9542.000 3044.042 5288.000 9342.837 9979.021 7096.022 5159.200 9400.485 4996.735 1698.000 5403.939",
"output": "0.036"
},
{
"input": "5\n4103.000 6413.459 1796.000 3486.799 9011.590 5564.000 9044.473 5922.000 3350.039 3746.000",
"output": "0.360"
},
{
"input": "7\n223.000 322.652 677.700 3852.000 2568.390 2410.713 3202.511 2122.870 1566.689 8841.790 8176.424 74.586 3834.000 6847.000",
"output": "0.325"
},
{
"input": "10\n8003.867 4368.000 2243.298 3340.000 5384.489 1036.000 3506.115 4463.317 1477.000 2420.314 9391.186 1696.000 5857.833 244.314 8220.000 5879.647 5424.482 2631.000 7111.130 9157.536",
"output": "0.472"
},
{
"input": "1\n6418.669 157.986",
"output": "0.655"
},
{
"input": "2\n950.335 8019.000 3179.000 9482.000",
"output": "0.335"
},
{
"input": "3\n4469.000 6526.000 4864.000 9356.000 7490.000 995.000",
"output": "0.000"
},
{
"input": "3\n673.000 9263.000 6780.254 9801.548 4640.663 8244.038",
"output": "0.497"
},
{
"input": "3\n6470.000 8295.000 8486.000 9855.000 223.000 579.549",
"output": "0.451"
},
{
"input": "7\n2341.000 9232.000 6646.000 9316.000 5684.000 9078.000 7773.978 3823.000 6357.000 9866.000 310.000 6554.000 8341.000 8407.987",
"output": "0.035"
},
{
"input": "9\n5528.000 205.000 5245.000 8832.000 385.000 7126.000 3988.538 9542.484 3044.000 5288.351 9342.000 9979.000 7096.000 5159.000 9400.000 4996.000 1698.000 5403.000",
"output": "0.373"
},
{
"input": "5\n4103.449 6413.000 1796.581 3486.000 9011.000 5564.010 9044.000 5922.539 3350.000 3746.191",
"output": "0.230"
},
{
"input": "7\n223.999 322.000 677.000 3852.477 2568.000 2410.000 3202.000 2122.000 1566.000 8841.000 8176.000 74.000 3834.286 6847.427",
"output": "0.189"
},
{
"input": "10\n8003.000 4368.194 2243.000 3340.287 5384.000 1036.456 3506.000 4463.000 1477.787 2420.000 9391.000 1696.913 5857.000 244.000 8220.322 5879.000 5424.000 2631.197 7111.000 9157.000",
"output": "0.156"
},
{
"input": "1\n6418.000 157.000",
"output": "0.000"
},
{
"input": "4\n0.999 0.999 0.999 0.999 0.999 0.999 0.000 0.000",
"output": "1.994"
},
{
"input": "1\n0.001 0.001",
"output": "0.998"
},
{
"input": "1\n0.900 0.900",
"output": "0.800"
},
{
"input": "2\n0.999 0.999 0.999 0.999",
"output": "1.996"
},
{
"input": "2\n0.001 0.001 0.001 0.001",
"output": "1.996"
},
{
"input": "1\n1.100 1.200",
"output": "0.700"
},
{
"input": "10\n0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900 0.900",
"output": "8.000"
},
{
"input": "2\n0.200 0.200 0.200 0.200",
"output": "1.200"
},
{
"input": "3\n0.900 0.900 0.900 0.900 0.900 0.000",
"output": "1.500"
},
{
"input": "1\n0.061 0.330",
"output": "0.609"
},
{
"input": "2\n0.100 0.100 0.100 0.100",
"output": "1.600"
},
{
"input": "5\n0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001",
"output": "4.990"
}
] | 1,380,902,742 | 2,142 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 218 | 5,222,400 | from fractions import Fraction
n = int(input())
ans = list(sorted(Fraction(int(x[-3:]), 1000) for x in input().split()))
while len(ans) > 0 and ans[1] == 0:
del ans[:2]
ans = sum(ans) - len(ans) // 2
print("0.{:03d}".format(abs(ans.numerator * 1000 // ans.denominator)))
| Title: Jeff and Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as follows:
- choose indexes *i* and *j* (*i*<=≠<=*j*) that haven't been chosen yet; - round element *a**i* to the nearest integer that isn't more than *a**i* (assign to *a**i*: ⌊ *a**i* ⌋); - round element *a**j* to the nearest integer that isn't less than *a**j* (assign to *a**j*: ⌈ *a**j* ⌉).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains 2*n* real numbers *a*1, *a*2, ..., *a*2*n* (0<=≤<=*a**i*<=≤<=10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output Specification:
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
Demo Input:
['3\n0.000 0.500 0.750 1.000 2.000 3.000\n', '3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\n']
Demo Output:
['0.250\n', '0.279\n']
Note:
In the first test case you need to perform the operations as follows: (*i* = 1, *j* = 4), (*i* = 2, *j* = 3), (*i* = 5, *j* = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | ```python
from fractions import Fraction
n = int(input())
ans = list(sorted(Fraction(int(x[-3:]), 1000) for x in input().split()))
while len(ans) > 0 and ans[1] == 0:
del ans[:2]
ans = sum(ans) - len(ans) // 2
print("0.{:03d}".format(abs(ans.numerator * 1000 // ans.denominator)))
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,686,865,912 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def calculate_maximum_dominoes(M, N):
total_squares = M * N
maximum_dominoes = total_squares // 2
return maximum_dominoes
# Example usage
M = 3
N = 4
maximum_dominoes = calculate_maximum_dominoes(M, N)
print("Maximum number of dominoes:", maximum_dominoes)
| 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
def calculate_maximum_dominoes(M, N):
total_squares = M * N
maximum_dominoes = total_squares // 2
return maximum_dominoes
# Example usage
M = 3
N = 4
maximum_dominoes = calculate_maximum_dominoes(M, N)
print("Maximum number of dominoes:", maximum_dominoes)
``` | 0 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,580,437,575 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | s=input()
t=list(reversed(list(input())))
for letter_s,letter_t in zip(s,t):
if letter_s!=letter_t:
print("NO")
break
else:
print("YES") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
s=input()
t=list(reversed(list(input())))
for letter_s,letter_t in zip(s,t):
if letter_s!=letter_t:
print("NO")
break
else:
print("YES")
``` | 3.9455 |
603 | B | Moodular Arithmetic | PROGRAMMING | 1,800 | [
"combinatorics",
"dfs and similar",
"dsu",
"math",
"number theory"
] | null | null | As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers *k* and *p*, where *p* is an odd prime number, the functional equation states that
for some function . (This equation should hold for any integer *x* in the range 0 to *p*<=-<=1, inclusive.)
It turns out that *f* can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions *f* that satisfy this equation. Since the answer may be very large, you should print your result modulo 109<=+<=7. | The input consists of two space-separated integers *p* and *k* (3<=≤<=*p*<=≤<=1<=000<=000, 0<=≤<=*k*<=≤<=*p*<=-<=1) on a single line. It is guaranteed that *p* is an odd prime number. | Print a single integer, the number of distinct functions *f* modulo 109<=+<=7. | [
"3 2\n",
"5 4\n"
] | [
"3\n",
"25\n"
] | In the first sample, *p* = 3 and *k* = 2. The following functions work:
1. *f*(0) = 0, *f*(1) = 1, *f*(2) = 2. 1. *f*(0) = 0, *f*(1) = 2, *f*(2) = 1. 1. *f*(0) = *f*(1) = *f*(2) = 0. | 1,000 | [
{
"input": "3 2",
"output": "3"
},
{
"input": "5 4",
"output": "25"
},
{
"input": "7 2",
"output": "49"
},
{
"input": "7 6",
"output": "343"
},
{
"input": "10007 25",
"output": "100140049"
},
{
"input": "40037 4",
"output": "602961362"
},
{
"input": "5 0",
"output": "625"
},
{
"input": "5 3",
"output": "5"
},
{
"input": "7 1",
"output": "823543"
},
{
"input": "13 5",
"output": "2197"
},
{
"input": "13 4",
"output": "169"
},
{
"input": "5 2",
"output": "5"
},
{
"input": "11 1",
"output": "311668616"
},
{
"input": "11 10",
"output": "161051"
},
{
"input": "6907 2590",
"output": "543643888"
},
{
"input": "3229 153",
"output": "552691282"
},
{
"input": "727 282",
"output": "471521101"
},
{
"input": "7621 6195",
"output": "501036626"
},
{
"input": "4649 4648",
"output": "460009811"
},
{
"input": "5527 1711",
"output": "837297007"
},
{
"input": "1901 633",
"output": "557576188"
},
{
"input": "463 408",
"output": "853558215"
},
{
"input": "6871 5566",
"output": "742783884"
},
{
"input": "4177 556",
"output": "594173514"
},
{
"input": "65213 29960",
"output": "65213"
},
{
"input": "375103 52131",
"output": "947042280"
},
{
"input": "990037 453792",
"output": "654009570"
},
{
"input": "95531 94787",
"output": "95531"
},
{
"input": "498653 116674",
"output": "625264514"
},
{
"input": "561389 213181",
"output": "10668315"
},
{
"input": "649849 339573",
"output": "649849"
},
{
"input": "512287 359783",
"output": "542484357"
},
{
"input": "337411 146419",
"output": "532279245"
},
{
"input": "717887 1",
"output": "559281518"
},
{
"input": "586189 189159",
"output": "168174057"
},
{
"input": "613463 269592",
"output": "336849737"
},
{
"input": "873781 51595",
"output": "226847774"
},
{
"input": "203317 12108",
"output": "374893480"
},
{
"input": "51419 21829",
"output": "643913547"
},
{
"input": "115237 90311",
"output": "355904974"
},
{
"input": "437071 24705",
"output": "743969711"
},
{
"input": "278917 84398",
"output": "727771018"
},
{
"input": "40867 37466",
"output": "560078799"
},
{
"input": "274783 98997",
"output": "505696564"
},
{
"input": "450431 344107",
"output": "450431"
},
{
"input": "288179 113623",
"output": "124681010"
},
{
"input": "807689 9869",
"output": "636680820"
},
{
"input": "69833 569",
"output": "69833"
},
{
"input": "805711 702149",
"output": "759894252"
},
{
"input": "999983 999982",
"output": "794678399"
},
{
"input": "999983 0",
"output": "416606930"
},
{
"input": "999983 1",
"output": "844765997"
},
{
"input": "823457 2",
"output": "203355139"
},
{
"input": "999983 239239",
"output": "965993296"
}
] | 1,481,717,275 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 139 | 307,200 | MOD=int(1e9+7)
n,k=map(int,input().split())
if k<2:p=n-(1-k)
else:
t=1
a=k
while a!=1:
a=a*k%n
t+=1
p=(n-1)//t
print(pow(n,p,MOD))
| Title: Moodular Arithmetic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers *k* and *p*, where *p* is an odd prime number, the functional equation states that
for some function . (This equation should hold for any integer *x* in the range 0 to *p*<=-<=1, inclusive.)
It turns out that *f* can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions *f* that satisfy this equation. Since the answer may be very large, you should print your result modulo 109<=+<=7.
Input Specification:
The input consists of two space-separated integers *p* and *k* (3<=≤<=*p*<=≤<=1<=000<=000, 0<=≤<=*k*<=≤<=*p*<=-<=1) on a single line. It is guaranteed that *p* is an odd prime number.
Output Specification:
Print a single integer, the number of distinct functions *f* modulo 109<=+<=7.
Demo Input:
['3 2\n', '5 4\n']
Demo Output:
['3\n', '25\n']
Note:
In the first sample, *p* = 3 and *k* = 2. The following functions work:
1. *f*(0) = 0, *f*(1) = 1, *f*(2) = 2. 1. *f*(0) = 0, *f*(1) = 2, *f*(2) = 1. 1. *f*(0) = *f*(1) = *f*(2) = 0. | ```python
MOD=int(1e9+7)
n,k=map(int,input().split())
if k<2:p=n-(1-k)
else:
t=1
a=k
while a!=1:
a=a*k%n
t+=1
p=(n-1)//t
print(pow(n,p,MOD))
``` | 3 |
|
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 1,524,061,650 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 78 | 7,065,600 | n=int(input())
v=[int(i) for i in input().split()]
mx=0
for i in range(1,len(v)):
mx=max(mx,v[i]-v[i-1])
mn=int(1e9)
for i in range(1,len(v)-1):
mn=min(mn,max(mx,v[i+1]-v[i-1]))
print(mn) | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
Input Specification:
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output Specification:
Print a single number — the minimum difficulty of the track after removing a single hold.
Demo Input:
['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n']
Demo Output:
['5\n', '2\n', '4\n']
Note:
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | ```python
n=int(input())
v=[int(i) for i in input().split()]
mx=0
for i in range(1,len(v)):
mx=max(mx,v[i]-v[i-1])
mn=int(1e9)
for i in range(1,len(v)-1):
mn=min(mn,max(mx,v[i+1]-v[i-1]))
print(mn)
``` | 3 |
|
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices. | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,686,140,202 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 280 | 34,304,000 | from heapq import heappop, heappush
from math import inf
from sys import stdin
def dijkstra(graph, start):
dist = [inf] * len(graph)
dist[start] = 0
parent = [-1] * len(graph)
q = [(0, start)]
while q:
d, u = heappop(q)
if d > dist[u]:
continue
for v, w in graph[u]:
if d + w < dist[v]:
dist[v] = d + w
parent[v] = u
heappush(q, (dist[v], v))
return parent
def solve():
n, m = map(int, stdin.readline().split())
if n == 1:
print(1)
return
graph = [[] for _ in range(n + 1)]
for _ in range(m):
u, v, w = map(int, stdin.readline().split())
graph[u].append((v, w))
graph[v].append((u, w))
parent = dijkstra(graph, 1)
if parent[n] == -1:
print(-1)
return
res = [n]
while parent[res[-1]] != -1:
res.append(parent[res[-1]])
print(*res[::-1])
solve()
| Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none | ```python
from heapq import heappop, heappush
from math import inf
from sys import stdin
def dijkstra(graph, start):
dist = [inf] * len(graph)
dist[start] = 0
parent = [-1] * len(graph)
q = [(0, start)]
while q:
d, u = heappop(q)
if d > dist[u]:
continue
for v, w in graph[u]:
if d + w < dist[v]:
dist[v] = d + w
parent[v] = u
heappush(q, (dist[v], v))
return parent
def solve():
n, m = map(int, stdin.readline().split())
if n == 1:
print(1)
return
graph = [[] for _ in range(n + 1)]
for _ in range(m):
u, v, w = map(int, stdin.readline().split())
graph[u].append((v, w))
graph[v].append((u, w))
parent = dijkstra(graph, 1)
if parent[n] == -1:
print(-1)
return
res = [n]
while parent[res[-1]] != -1:
res.append(parent[res[-1]])
print(*res[::-1])
solve()
``` | 3.604415 |
Subsets and Splits