message stringlengths 2 45.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 254 108k | cluster float64 3 3 | __index_level_0__ int64 508 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.
You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.
Input
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.
It is guaranteed that all n + 2 points in the input are distinct.
Output
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
Examples
Input
2 -1 0 5 3
0 2
5 2
Output
6
Input
4 0 0 5 0
9 4
8 3
-1 0
1 4
Output
33
Note
The first sample is (r12 = 5, r22 = 1): <image> The second sample is (r12 = 1, r22 = 32): <image>
Submitted Solution:
```
def dist(x, y, ax, ab):
return((x-ax)*(x-ax) + (y-ab)*(y-ab))
n, x1, y1, x2, y2 = [int(s) for s in input().split()]
res = 0
r1 = 0
r2 = 0
for i in range(n):
x, y = [int(s) for s in input().split()]
d1 = dist(x, y, x1, y1)
d2 = dist(x, y, x2, y2)
if d1>r1 and d2>r2:
if d1+r1 > d2+r2:
r2 += d2
else:
r1 += d1
print(r2+r1)
``` | instruction | 0 | 55,236 | 3 | 110,472 |
No | output | 1 | 55,236 | 3 | 110,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.
You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.
Input
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.
It is guaranteed that all n + 2 points in the input are distinct.
Output
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
Examples
Input
2 -1 0 5 3
0 2
5 2
Output
6
Input
4 0 0 5 0
9 4
8 3
-1 0
1 4
Output
33
Note
The first sample is (r12 = 5, r22 = 1): <image> The second sample is (r12 = 1, r22 = 32): <image>
Submitted Solution:
```
class Point(object):
def __init__(self,x,y):
self.x = x
self.y = y
def distance(p1,p2):
return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)
(n,x1,y1,x2,y2) = map(int,input().split())
F1 = Point(x1,y1)
F2 = Point(x2,y2)
P = []
for i in range(n):
(a,b) = map(int,input().split())
P.append(Point(a,b))
R1 = [distance(x,F1) for x in P]
R2 = [distance(x,F2) for x in P]
min = float("inf")
def f(t):
return R1[t]
K = sorted([i for i in range(n)],key=f)
R2 = [R2[i] for i in K]
for i in range(n-1):
if min > R1[K[i]] + max(R2[i+1:]):
min = R1[K[i]] + max(R2[i+1:])
if R1[K[-1]] < min:
min = R1[K[-1]]
print(min)
``` | instruction | 0 | 55,237 | 3 | 110,474 |
No | output | 1 | 55,237 | 3 | 110,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,238 | 3 | 110,476 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
import itertools
class SolutionImpossible(Exception):
pass
blocks_cnt, finish, min_sprint, max_jump = [int(x) for x in input().split()]
def read_blocks_coords():
it = (int(x) for x in input().split())
return (x for x in it if x < finish)
# TODO: код можно сократить за счет избавления от лишней записи в `_grouper._current_key`
def _grouper(value):
if _grouper._prev_value is not None:
# после прыжка мы приземляемся ЗА препятствием, учитываем это
if value - _grouper._prev_value - 1 <= min_sprint:
# расстояние между препятствиями слишком мало
# чтобы между ними приземляться, и затем разогнаться для нового прыжка, считаем их за одно
_current_key = _grouper._current_key
else:
_current_key = id(value)
else:
# первое вхождение, ставим данные по умолчанию
_current_key = id(_grouper)
_grouper._prev_value = value
_grouper._current_key = _current_key
return _current_key
_grouper._prev_value = None
_grouper._current_key = None
def check_chunk(run_from, block=None):
if block is None:
return
next_run_from = block[-1] + 1 # следующая за преградой позиция (точка приземления)
if next_run_from - block[0] >= max_jump:
# если преграда слишком длинная, то мы не можем ее пересечь
raise SolutionImpossible
if abs(run_from - block[0]) <= min_sprint:
# нет возможности для разбега
raise SolutionImpossible
def solve_chunk(run_from, block=None):
if block is not None:
run_len = block[0] - run_from - 1 # добегаем ДО преграды
jump_len = block[-1] - block[0] + 2 # прыгаем ЗА нее
print(
"RUN {run_len}\n"
"JUMP {jump_len}".format(
run_len=run_len,
jump_len=jump_len,
)
)
else:
run_len = finish - run_from
if run_len > 0:
print("RUN {run_len}".format(run_len=run_len))
def main():
# некоторые препятствия могут находиться так близко, что между ними нет возможности разогнаться
# считаем такие препятствия за одно
blocks = (list(g) for k, g in itertools.groupby(sorted(read_blocks_coords()), key=_grouper))
chunks = []
run_from = 0
while True:
block = next(blocks, None)
chunk = (run_from, block)
check_chunk(*chunk)
chunks.append(chunk)
if block is None:
break
# после прыжка мы приземляемся ЗА препятствием, учитываем это
run_from = block[-1] + 1
#print(chunks)
for chunk in chunks:
solve_chunk(*chunk)
if __name__ == '__main__':
try:
main()
except SolutionImpossible:
print("IMPOSSIBLE")
``` | output | 1 | 55,238 | 3 | 110,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,239 | 3 | 110,478 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
n, m, s, d = map(int, input().split())
beg = [float('-inf')]
end = [float('-inf')]
a = [int(i) for i in input().split()]
for x in sorted(a):
if (x - end[-1] > s + 1):
beg.append(x)
end.append(x)
else:
end[-1] = x
last = 0
R = []
J = []
for i in range(1, len(beg)):
R.append(beg[i] - 1 - last)
last = (beg[i] - 1)
J.append(end[i] + 1 - last)
last = (end[i] + 1)
ok = True
for x in J:
if (x > d):
ok = False
for x in R:
if (x < s):
ok = False
if ok:
for i in range(len(R)):
print('RUN', R[i])
print('JUMP', J[i])
if (last < m):
print('RUN', m - last)
else:
print('IMPOSSIBLE')
``` | output | 1 | 55,239 | 3 | 110,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,240 | 3 | 110,480 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n, m, s, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
curr = 0
f = 0
ans = []
obs = []
obs.append([a[0], 0])
j = 0
for i in range(1, n):
if a[i] - a[i - 1] -2<s:
obs[j][1] += a[i] - a[i - 1]
else:
obs.append([a[i], 0])
j += 1
curr = 0
obs.append([float('inf'), -1])
i=0
while(1):
if obs[i][1] == -1:
break
if obs[i][0] - 1 - curr >= s:
ind = -1
for j in range(i, len(obs)-1):
if obs[j][0] - (obs[i][0] - 1) + obs[j][1] + 1 <= d:
ind = j
else:
break
if ind < i:
print('IMPOSSIBLE')
return
else:
ans.append(['RUN', obs[i][0] - 1 - curr])
ans.append(['JUMP', obs[ind][0] - (obs[i][0] - 1) + obs[ind][1] + 1])
curr = obs[ind][0] + obs[ind][1] + 1
i = ind + 1
else:
print('IMPOSSIBLE')
return
if m - curr:
ans.append(['RUN', m - curr])
for i in ans:
print(*i)
return
if __name__ == "__main__":
main()
``` | output | 1 | 55,240 | 3 | 110,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,241 | 3 | 110,482 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
n,m,s,d=map(int,input().split())
x=list(map(int,input().split()))+[m+s+1]
x.sort()
cur=l=0
ans=[]
while l<m:
r=min(x[cur]-1,m)
ans.append(("RUN",r-l))
if r==m:
break
if r-l<s:
print("IMPOSSIBLE")
exit()
t=x[cur]+1
while x[cur+1]-1-t<s:
cur+=1
t=x[cur]+1
if t-r>d:
print("IMPOSSIBLE")
exit()
ans.append(("JUMP",t-r))
l=t
cur+=1
for aa in ans:
print(*aa)
``` | output | 1 | 55,241 | 3 | 110,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,242 | 3 | 110,484 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
num_barriers, finish, min_run, max_jump = tuple(map(int, input().split()))
barriers = list(map(int, input().split())) + [-1]
barriers.sort()
for i in range(len(barriers) - 1):
if barriers[i + 1] - barriers[i] <= min_run + 1:
barriers[i] = (0, barriers[i] + 1, barriers[i + 1] - 1) # nope
else:
barriers[i] = (1, barriers[i] + 1, barriers[i + 1] - 1) # ok
barriers[len(barriers) - 1] = (1, barriers[len(barriers) - 1] + 1, finish)
if not barriers:
pass
elif not barriers[0][0]:
print('IMPOSSIBLE')
else:
commands = []
pos = 0
for tpe, st, en in barriers:
if tpe:
if pos != st and st - pos <= max_jump:
commands.append('JUMP %s' % (st - pos))
elif pos != st:
print('IMPOSSIBLE')
break
if en - st:
commands.append('RUN %s' % (en - st))
pos = en
else:
print('\n'.join(commands))
``` | output | 1 | 55,242 | 3 | 110,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,243 | 3 | 110,486 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
imp = "IMPOSSIBLE"
n, m, s, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
too_short = [False] * n
if a[0] - 1 < s:
too_short[0] = True
for i in range(1, n):
if (a[i] - a[i - 1] - 2 < s):
too_short[i] = True
max_jump = [-1] * n
for i in range(n):
jump = a[i] - 1 + d
l = i - 1
r = n
while (l + 1 < r):
cur = (l + r) // 2
if a[cur] < jump:
l = cur
else:
r = cur
if (l > i - 1):
max_jump[i] = l + 1
reachable = 0
jumps = []
for i in range(n):
if reachable < i:
break
if not too_short[i]:
if max_jump[i] > reachable:
reachable = max_jump[i]
jumps.append(i)
if (reachable < n):
print(imp)
else:
jump_up = 0
jump_down = 0
for jump in jumps:
if (jump != 0):
print("JUMP", a[jump - 1] + 1 - jump_up)
jump_down = a[jump - 1] + 1
print("RUN", a[jump] - 1 - jump_down)
jump_up = a[jump] - 1
jump = jumps[-1]
print("JUMP", a[n - 1] + 1 - jump_up)
jump_down = a[n - 1] + 1
if (m > jump_down):
print("RUN", m - jump_down)
``` | output | 1 | 55,243 | 3 | 110,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,244 | 3 | 110,488 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
n,m,s,d=map(int,input().split())
obstacles=[-1]+list(map(int,input().split()))+[m+1]
obstacles.sort()
check=[]
a=True
ans=[]
pos=0
for i in range(n+1):
if i!=n and obstacles[i+1]-obstacles[i]-2<s:
#print(i)
if i==0 or obstacles[i+1]+1-pos>d:
a=False
break
else:
if obstacles[i]+1-pos>d:
a=False
break
if i!=0:
ans.append("JUMP "+str(obstacles[i]+1-pos))
if obstacles[i+1]-obstacles[i]-2!=0:
ans.append("RUN "+str(obstacles[i+1]-obstacles[i]-2))
pos=obstacles[i+1]-1
if a:
for each in ans:
print(each)
else:
print("IMPOSSIBLE")
``` | output | 1 | 55,244 | 3 | 110,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | instruction | 0 | 55,245 | 3 | 110,490 |
Tags: *special, data structures, dp, greedy
Correct Solution:
```
f = lambda: map(int, input().split())
n, m, s, d = f()
p, x, z = [], -1, 1
for y in sorted(f()) + [m + 1]:
if y - x > s + 1 or y > m or x < 0:
u = x - z + 2
v = y - x - 2
if u > d or v < s and x < 0:
p = ['IMPOSSIBLE']
break
if u: p += ['JUMP ' + str(u)]
if v: p += ['RUN ' + str(v)]
z = y
x = y
print('\n'.join(p))
``` | output | 1 | 55,245 | 3 | 110,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
n, m ,s, d = [int(i) for i in input().split()] # m is the end point
# s is length of run, d is the max jump distance
A = [-1] + sorted([int(i) for i in input().split()]) + [m+1]
ans_size = 2 * 10**5
ans = [0 for i in range(4*ans_size)]
# use 0 to indicate run an 1 to indicate jump
def obstacle():
run = -1
jump = -1
top = 0 # flag where are we at the dp
for i in range(1,n+1):
if s + 2 <= A[i] - A[i-1]:
if jump != -1:
if A[i-1] + 1 - jump <= d and top > 0 and ans[top-1][0] == 0 and ans[top-1][1] >= s:
ans[top] = (1, A[i-1]+1-jump)
top += 1
else:
print("IMPOSSIBLE")
return
ans[top] = (0, A[i] - A[i-1]-2) # run
top += 1
jump = A[i] - 1 # jumping point
if A[n] + 1 - jump <= d and top > 0 and ans[top-1][0] == 0 and ans[top-1][1] >= s:
ans[top] = (1, A[n]+1 - jump)
top += 1
else:
print("IMPOSSIBLE")
return
if m != A[n] + 1:
ans[top] = (0, m-A[n]-1)
top += 1
for i in range(top):
if ans[i][0]:
print("JUMP", ans[i][1])
else:
print("RUN", ans[i][1])
obstacle()
``` | instruction | 0 | 55,246 | 3 | 110,492 |
Yes | output | 1 | 55,246 | 3 | 110,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
n,m,s,d=map(int,input().split())
x=sorted(map(int,input().split()))+[m+s+1]
cur=l=0
ans=[]
while l<m:
r=min(x[cur]-1,m)
ans+=['RUN '+str(r-l)]
if r==m: break
if r-l<s: ans=['IMPOSSIBLE']; break
t=x[cur]+1
while x[cur+1]-1-t<s: cur+=1; t=x[cur]+1
if t-r>d: ans=['IMPOSSIBLE']; break
ans+=['JUMP '+str(t-r)]
l=t;cur+=1
print('\n'.join(ans))
``` | instruction | 0 | 55,247 | 3 | 110,494 |
Yes | output | 1 | 55,247 | 3 | 110,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
for _ in range(1):
n,m,s,jump=map(int,input().split())
arr=[0]+sorted(list(map(int,input().split())))
if s>=arr[1]:
print("IMPOSSIBLE")
continue
max_indx=arr[1]-1
flag=0
travel=[0]
for i in range(1,n+1):
if arr[i] - arr[i - 1] - 2 >= s:
max_indx = arr[i] - 1
if arr[i]+1 <= max_indx+jump:
travel.append(max_indx)
continue
flag=-1
break
if flag==-1:
print("IMPOSSIBLE")
continue
arr[0]=-1
travel.append(1000000000)
ans=[]
count=0
for i in range(1,n+1):
if travel[i]!=travel[i-1]:
ans.append(["RUN",arr[i]-arr[i-1]-2])
if travel[i]==travel[i+1]:
count+=arr[i+1]-arr[i]
else:
ans.append(["JUMP",count+2])
count=0
if m-arr[-1] >1:
ans.append(["RUN",m-arr[-1]-1])
for i in ans:
print(i[0],i[1])
``` | instruction | 0 | 55,248 | 3 | 110,496 |
Yes | output | 1 | 55,248 | 3 | 110,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n, m, s, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
curr = 0
f = 0
ans = []
obs = []
obs.append([a[0], 0])
j = 0
for i in range(1, n):
if a[i] - a[i - 1] -2<s:
obs[j][1] += a[i] - a[i - 1]
else:
obs.append([a[i], 0])
j += 1
curr = 0
# for i in obs:
# print(i)
obs.append([float('inf'), -1])
i=0
while(1):
if obs[i][1] == -1:
break
if obs[i][0] - 1 - curr >= s:
ind = -1
for j in range(i, len(obs)-1):
if obs[j][0] - (obs[i][0] - 1) + obs[j][1] + 1 <= d:
ind = j
else:
break
if ind < i:
print('IMPOSSIBLE')
return
else:
ans.append(['RUN', obs[i][0] - 1 - curr])
ans.append(['JUMP', obs[ind][0] - (obs[i][0] - 1) + obs[ind][1] + 1])
curr = obs[ind][0] + obs[ind][1] + 1
i = ind + 1
else:
print('IMPOSSIBLE')
return
if m - curr:
ans.append(['RUN', m - curr])
for i in ans:
print(*i)
return
if __name__ == "__main__":
main()
``` | instruction | 0 | 55,249 | 3 | 110,498 |
Yes | output | 1 | 55,249 | 3 | 110,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n,m,s,d=map(int, input().split())
a=list(map(int, input().split()))
a.sort()
curr=0
f=0
ans=[]
obs=[]
obs.append([a[0],0])
j=0
for i in range(1,n):
if a[i]-a[i-1]==1:
obs[j][1]+=1
else:
obs.append([a[i], 0])
j+=1
curr=0
# for i in obs:
# print(i)
obs.append([float('inf'),-1])
for i in range(len(obs)):
if obs[i][1]==-1:
break
if obs[i][0]-1-curr>=s:
ind=-1
for j in range(i, len(obs)):
if (obs[j+1][0]-1)-(obs[j][0]+obs[j][1]+1)>=s:
ind=j
break
if obs[j][0]-(obs[i][0])+obs[j][1]<=d:
ind=j
else:
break
if ind<i:
#print(ind, i)
print('IMPOSSIBLE')
# print('ok')
return
else:
ans.append(['RUN', obs[i][0]-1-curr])
ans.append(['JUMP', obs[ind][0]-(obs[i][0]-1)+obs[ind][1]+1])
curr=obs[ind][0]+obs[ind][1]+1
i=ind+1
else:
#print(i,curr)
print('IMPOSSIBLE')
#print('ol')
return
if m-curr:
ans.append(['RUN', m-curr])
for i in ans:
print(*i)
return
if __name__ == "__main__":
main()
``` | instruction | 0 | 55,250 | 3 | 110,500 |
No | output | 1 | 55,250 | 3 | 110,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
from sys import exit
n, m, s, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if a[0] - 1 < s:
print('IMPOSSIBLE')
exit()
strategy_run = []
strategy_jump = []
i = 0
stand_point = 0
while i < n:
j = i + 1
if j != n:
a2, a1 = a[j], a[i]
strategy_run.append(a1 - stand_point - 1)
stand_point = a1 - 1
while j < n:
if a2 - a1 - 2 < s:
if a2 - a[i] + 2 > d:
print('IMPOSSIBLE')
exit()
j += 1
if j != n:
a1 = a2
a2 = a[j]
continue
else:
strategy_jump.append(a1 - a[i] + 2)
i = j
stand_point = a[i - 1] + 1
break
else:
#print(stand_point, strategy_run, strategy_jump)
if d >= a[-1] - stand_point + 1 and strategy_run[-1] >= s:
strategy_jump.append(a[-1] - stand_point + 1)
else:
print('IMPOSSIBLE')
exit()
i = j
stand_point = a[i - 1] + 1
strategy_run.append(m - stand_point)
for i in range(len(strategy_run) - 1):
print('RUN', strategy_run[i])
print('JUMP', strategy_jump[i])
if strategy_run[-1] != 0:
print('RUN', strategy_run[-1])
``` | instruction | 0 | 55,251 | 3 | 110,502 |
No | output | 1 | 55,251 | 3 | 110,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
imp = "IMPOSSIBLE"
n, m, s, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
too_short = [False] * n
if a[0] - 1 < s:
too_short[0] = True
for i in range(1, n):
if (a[i] - a[i - 1] - 2 < s):
too_short[i] = True
max_jump = [-1] * n
for i in range(n):
jump = a[i] - 1 + d
l = i - 1
r = n
while (l + 1 < r):
cur = (l + r) // 2
if a[cur] < jump:
l = cur
else:
r = cur
if (l > i - 1):
max_jump[i] = l + 1
reachable = 0
jumps = []
for i in range(n):
if reachable < i:
break
if not too_short[i]:
if max_jump[i] > reachable:
reachable = max_jump[i]
jumps.append(i)
if (reachable < n):
print(imp)
else:
jump_up = 0
jump_down = 0
for jump in jumps:
if (jump != 0):
print("JUMP", a[jump - 1] + 1 - jump_up)
jump_down = a[jump - 1] + 1
print("RUN", a[jump] - 1 - jump_down)
jump_up = a[jump] - 1
jump = jumps[-1]
print("JUMP", a[jump] + 1 - jump_up)
jump_down = a[jump] + 1
if (m > jump_down):
print("RUN", m - jump_down)
``` | instruction | 0 | 55,252 | 3 | 110,504 |
No | output | 1 | 55,252 | 3 | 110,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
* print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
* print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Examples
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Submitted Solution:
```
n, m, s, d = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
data.sort()
good = [[0, data[0]]]
cnt = 1
for i in range(1, n):
l = data[i] - data[i - 1] - 1
if l >= s:
good.append([data[i - 1] + 1, data[i]])
cnt += 1
good.append([data[-1] + 1, m + 1])
cnt += 1
ret = ''
p = 1
for i in range(cnt - 1):
ret += 'RUN ' + str(good[i][1] - good[i][0] - 1) + '\n'
box = good[i + 1][0] - good[i][1] + 1
if box <= d:
ret += 'JUMP ' + str(box) + '\n'
else:
print('IMPOSSIBLE')
p = 0
break
box = good[-1][1] - good[-1][0] - 1
if box:
ret += 'RUN ' + str(box) + '\n'
if data[0] - 1 < s and p:
print('IMPOSSIBLE')
elif p:
print(ret, end = '')
``` | instruction | 0 | 55,253 | 3 | 110,506 |
No | output | 1 | 55,253 | 3 | 110,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909 | instruction | 0 | 55,270 | 3 | 110,540 |
Tags: binary search
Correct Solution:
```
def check(bound):
more, less = 0, 0
for x in a:
if x > bound: more += x - bound
else: less += bound - x
return more * (100 - k) / 100 - less >= 0
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
res, l, r = 0, 0, 1000
if max(a) == min(a): res = a[0]
for loops in range(200):
m = (l + r) / 2
if check(m):
res = m; l = m
else: r = m
print(f'{res:.8f}')
``` | output | 1 | 55,270 | 3 | 110,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909 | instruction | 0 | 55,271 | 3 | 110,542 |
Tags: binary search
Correct Solution:
```
def isEnough(x):
receiving = 0
giving = 0
for acc in accumulators:
if acc < x:
receiving += x - acc
else:
giving += (acc - x) * (100 - k) / 100
return (receiving <= giving)
def BinarySreach(l, r):
left = l
right = r
ans = r
while left <= right:
mid = (left + right) / 2
if isEnough(mid):
ans = mid
left = mid + 10**(-10)
else:
right = mid - 10**(-10)
return ans
n, k = map(int, input().split())
accumulators = list(map(int, input().split()))
print("{:.9f}".format(BinarySreach(0, max(accumulators))))
``` | output | 1 | 55,271 | 3 | 110,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909 | instruction | 0 | 55,272 | 3 | 110,544 |
Tags: binary search
Correct Solution:
```
n, k = list(map(int, input().split(" ")))
inp = list(map(int, input().split(" ")))
x, y = [1, 3]
_sum = sum(inp)
right =_sum / n
left = 0
mid =(right + left) / 2
while right - left > 1e-11:
lost = 0
get = 0
for i in inp:
if mid < i:
lost += (i - mid) * (1-k / 100)
else:
get += mid - i
if lost > get:
left = mid
else:
right = mid
mid = (right + left) / 2
print(left)
``` | output | 1 | 55,272 | 3 | 110,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909 | instruction | 0 | 55,274 | 3 | 110,548 |
Tags: binary search
Correct Solution:
```
n,k=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
def check(x):
pw=0
for i in a:
if(i>=x):
rem=(i-x)
pw+=(rem-(rem*k/100))
else:
pw-=(x-i)
if(pw>=0): return True
return False
l=0
h=max(a)
ans=0
while(l+0.00000001<=h):
mid=(l+h)/2
if(check(mid)):
ans=mid
l=mid
else:
h=mid
print("{0:.8f}".format(ans))
``` | output | 1 | 55,274 | 3 | 110,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909 | instruction | 0 | 55,275 | 3 | 110,550 |
Tags: binary search
Correct Solution:
```
def check(a, k, cur):
need = 0
have = 0
for x in a:
if x < cur:
need += cur - x
else:
have += (x - cur) * (1 - k / 100)
return need <= have
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l = 0
r = 1000
for i in range(100):
cur = (l + r) / 2
if check(a, k, cur):
l = cur
else:
r = cur
print((l + r) / 2)
``` | output | 1 | 55,275 | 3 | 110,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909 | instruction | 0 | 55,276 | 3 | 110,552 |
Tags: binary search
Correct Solution:
```
n,k=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
def check(x):
pw=0
for i in a:
if(i>=x):
rem=(i-x)
pw+=(rem-(rem*k/100))
else:
pw-=(x-i)
if(pw>=0): return True
return False
l=0
h=max(a)
ans=0
while(l+0.00000001<=h):
mid=(l+h)/2
if(check(mid)):
ans=mid
l=mid
else:
h=mid
# print("{0:.10f}".format(ans))
print(ans)
``` | output | 1 | 55,276 | 3 | 110,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
def possible(power):
need=0
have=0
for i in energy:
if(i<power):
need+=power-i
elif(i>power):
have+=(i-power)*(100-k)/100
#print(power,need,have)
return need-have < 1e-7
n,k=value()
energy=array()
low=min(energy)
high=max(energy)
#print(possible(2))
ans=energy[0]
while(low+1e-7<high):
mid=low+(high-low)/2
if(possible(mid)):
ans=mid
low=mid
else:
high=mid
print(ans)
``` | instruction | 0 | 55,277 | 3 | 110,554 |
Yes | output | 1 | 55,277 | 3 | 110,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
n, k = map(int, input().split())
A = list(map(int, input().split()))
def f(x):
over = 0
need = 0
for a in A:
if a > x:
over += (a - x)
else:
need += (x - a)
return need <= (over * (1 - k/100))
left = 0
right = 1000
while right - left > 1e-12:
m = (left + right) / 2
if f(m):
left = m
else:
right = m
print(right)
``` | instruction | 0 | 55,278 | 3 | 110,556 |
Yes | output | 1 | 55,278 | 3 | 110,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
def main():
n, k = map(int, input().split())
k = 1.0 - k / 100
a = list(map(int, input().split()))
ans = 0
l, r = 0, 1000
for rep in range(100):
mid = (l + r) / 2
need, excess = 0, 0
for energy in a:
if energy > mid:
excess += (energy - mid) * k
else:
need += mid - energy
if excess >= need:
ans = mid
l = mid
else:
r = mid
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 55,279 | 3 | 110,558 |
Yes | output | 1 | 55,279 | 3 | 110,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
# def marble(q,n,arr, queries):
# arr = sorted(arr)
# for q in queries:
# ind = -1
# left = 0
# right = n
# while left < right:
# mid = left + (-left + right)//2
# if q <= arr[mid]:
# ind = mid
# right = mid
# # break
# else:
# left = mid + 1
# if ind == -1 or arr[ind] != q:
# print("{} not found".format(q))
# else:
# print("{0} found at {1}".format(q, ind+1))
# case = 1
# while True:
# n,q = list(map(int, input().strip().split(" ")))
# if n == 0 and q == 0:
# break
# arr = []
# for i in range(n):
# x = int(input().strip())
# arr.append(x)
# queries = []
# for _ in range(q):
# queries.append(int(input().strip()))
# print("CASE# {}:".format(case))
# marble(q,n,arr,queries)
# case += 1
# def pizza(n,k,arr):
# total = 0
# arr = sorted(arr)
# for ind, x in enumerate(arr):
# left = ind + 1
# right = n-1
# while left <= right:
# mid = (left + right)//2
# if k == arr[mid]-x:
# total += 1
# break
# elif k > arr[mid]-x:
# left = mid + 1
# else:
# right = mid - 1
# print(total)
# n,k = list(map(int, input().strip().split(" ")))
# arr = list(map(int, input().strip().split(" ")))
def energy(n,k,arr):
arr = sorted(arr)
max_energy = -1
left = min(arr)
right = max(arr)
while abs(left-right) > 10**(-6):
X = (left + right)/2
# print(left, X, right)
a = sum(arr)
thua = 0
for i in arr:
if i > X:
# a += (i-X)
thua += ((i-X)*k/100)
# else:
# a += (i)
#a + thua - n*X .. 0
# ^ ^
if a - thua == n*X:
max_energy = X
elif a - thua - n*X > 0:
left = X
else:
right = X
print(left)
n,k = list(map(int, input().strip().split(" ")))
arr = list(map(int, input().strip().split(" ")))
energy(n,k,arr)
# 4 2 1 -> X = 2
# 2 2 1 = 5
# 1 (5 - 2)*k% 0 = 1
# Mức năng lượng sau khi transfer + Năng lượng thừa = Tổng năng lượng muốn
# # = n * X
# Tổng năng lượng ban đầu - năng lượng mất = Tổng năng lượng muốn
# =
# 2 2 2 = 2*3 = 6
``` | instruction | 0 | 55,280 | 3 | 110,560 |
Yes | output | 1 | 55,280 | 3 | 110,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
# http://codeforces.com/problemset/problem/68/B
# 1 <= n <= 10,000
# 0 <= k <= 99
n, k = [int(n) for n in input().split()]
accums = [int(n) for n in input().split()]
k = 100-k
right = max(accums)
left = min(accums)
guess = 0
if len(accums) == 1:
print(guess)
else:
while (right-left > 0.00000001): #log base 2 of 10^6 -> 30
guess = (left+right)/2.0
excess = 0
residual = 0
for i in accums: #10,000
if i > guess:
excess += ((i - guess)*k/100.0)
else:
residual += (guess - i)
if (excess > residual):
left = guess
elif (residual > excess):
right = guess
else:
break
print (guess)
``` | instruction | 0 | 55,281 | 3 | 110,562 |
No | output | 1 | 55,281 | 3 | 110,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
nk = list(input().split())
n, k = int(nk[0]), float(nk[1])
energy = list(map(float, input().split()))
avg = sum(energy)/len(energy)
sum_lf = 0
sum_rg = 0
cnt_lf = 0
cnt_rg = 0
for i in range(n):
if(energy[i]<avg):
cnt_lf+=1
sum_lf+=energy[i]
else:
cnt_rg+=1
sum_rg+=energy[i]
x = (cnt_lf * sum_rg - cnt_rg * sum_lf) / (cnt_rg * (100 - k)/100 + cnt_lf)
print("%.9f"%((sum_rg - x)/(cnt_rg)))
``` | instruction | 0 | 55,282 | 3 | 110,564 |
No | output | 1 | 55,282 | 3 | 110,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
result = sum(a)/n
eps = 0.0000000001
while True:
transferred = (100-k)/100 * sum(map(lambda x: x-result if x-result>0 else 0, a))
missing = sum(map(lambda x: result-x if result-x>0 else 0, a))
if abs(transferred - missing) < eps:
print(result)
break
result = result + (transferred - missing)/2
``` | instruction | 0 | 55,283 | 3 | 110,566 |
No | output | 1 | 55,283 | 3 | 110,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.
Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.
Input
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10 - 6.
Examples
Input
3 50
4 2 1
Output
2.000000000
Input
2 90
1 11
Output
1.909090909
Submitted Solution:
```
s = input().strip().split()
n = int(s[0])
k = int(s[1])
a = list()
for i in input().strip().split():
a.append(int(i))
left = min(a)
right = max(a)
while (right - left > 10**-6):
guess = (left+right)/2
needed = 0
excess = 0
for i in range(n):
if(a[i] > guess):
excess += (a[i]-guess)*k/100.0;
else:
needed += (guess - a[i])
if (excess > needed):
left = guess;
elif (needed > excess):
right = guess;
else:
break;
print(guess)
``` | instruction | 0 | 55,284 | 3 | 110,568 |
No | output | 1 | 55,284 | 3 | 110,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.
There are n computers for participants, the i-th of which has power equal to positive integer pi. At the same time there are m sockets available, the j-th of which has power euqal to positive integer sj. It is possible to connect the i-th computer to the j-th socket if and only if their powers are the same: pi = sj. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.
In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with power x, the power on the adapter's socket becomes equal to <image>, it means that it is equal to the socket's power divided by two with rounding up, for example <image> and <image>.
Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power 10, it becomes possible to connect one computer with power 3 to this socket.
The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computers c at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adapters u to connect c computers.
Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.
The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of computers and the number of sockets.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 109) — the powers of the computers.
The third line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 109) — the power of the sockets.
Output
In the first line print two numbers c and u — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connect c computers.
In the second line print m integers a1, a2, ..., am (0 ≤ ai ≤ 109), where ai equals the number of adapters orginizers need to plug into the i-th socket. The sum of all ai should be equal to u.
In third line print n integers b1, b2, ..., bn (0 ≤ bi ≤ m), where the bj-th equals the number of the socket which the j-th computer should be connected to. bj = 0 means that the j-th computer should not be connected to any socket. All bj that are different from 0 should be distinct. The power of the j-th computer should be equal to the power of the socket bj after plugging in abj adapters. The number of non-zero bj should be equal to c.
If there are multiple answers, print any of them.
Examples
Input
2 2
1 1
2 2
Output
2 2
1 1
1 2
Input
2 1
2 100
99
Output
1 6
6
1 0
Submitted Solution:
```
from collections import defaultdict
from heapq import heappop, heapreplace, heapify
def solve():
n, m = map(int, input().split())
cc = map(int, input().split())
ss = map(int, input().split())
C = defaultdict(list)
for i, c in enumerate(cc):
C[c].append(i)
S = [(-s, 0, i) for i, s in enumerate(ss)]
heapify(S)
uc = 0
ua = 0
ans_s = [0] * m
ans_c = [0] * m
while S:
sp, sa, si = S[0]
sp = -sp
if C[sp]:
heappop(S)
cs = C[sp]
ci = cs.pop()
if not cs:
del C[sp]
ua += sa
uc += 1
ans_s[si] = sa
ans_c[ci] = si + 1
elif sp > 1:
heapreplace(S, (-((sp + 1) // 2), sa + 1, si))
else:
heappop(S)
print(uc, ua)
print(*ans_s)
print(*ans_c)
solve()
``` | instruction | 0 | 55,299 | 3 | 110,598 |
No | output | 1 | 55,299 | 3 | 110,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.
There are n computers for participants, the i-th of which has power equal to positive integer pi. At the same time there are m sockets available, the j-th of which has power euqal to positive integer sj. It is possible to connect the i-th computer to the j-th socket if and only if their powers are the same: pi = sj. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.
In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with power x, the power on the adapter's socket becomes equal to <image>, it means that it is equal to the socket's power divided by two with rounding up, for example <image> and <image>.
Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power 10, it becomes possible to connect one computer with power 3 to this socket.
The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computers c at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adapters u to connect c computers.
Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.
The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of computers and the number of sockets.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 109) — the powers of the computers.
The third line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 109) — the power of the sockets.
Output
In the first line print two numbers c and u — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connect c computers.
In the second line print m integers a1, a2, ..., am (0 ≤ ai ≤ 109), where ai equals the number of adapters orginizers need to plug into the i-th socket. The sum of all ai should be equal to u.
In third line print n integers b1, b2, ..., bn (0 ≤ bi ≤ m), where the bj-th equals the number of the socket which the j-th computer should be connected to. bj = 0 means that the j-th computer should not be connected to any socket. All bj that are different from 0 should be distinct. The power of the j-th computer should be equal to the power of the socket bj after plugging in abj adapters. The number of non-zero bj should be equal to c.
If there are multiple answers, print any of them.
Examples
Input
2 2
1 1
2 2
Output
2 2
1 1
1 2
Input
2 1
2 100
99
Output
1 6
6
1 0
Submitted Solution:
```
from math import *
n,m=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
anses=dict()
for j in range(len(B)):
per = B[j]
cou = 0
if B[j] in anses:
anses[B[j]].append([cou,j])
else:
anses[B[j]] = [[0],[cou,j]]
while per > 1:
per = ceil(per/2)
cou+=1
if per in anses:
anses[per].append([cou,j])
else:
anses[per] = [[0],[cou,j]]
for j in anses:
anses[j].sort()
answer = 0
answer2 =0
ans = [0] * len(A)
ans2 = [0] * len(B)
A.sort()
for j in range(len(A)-1,-1,-1):
if A[j] in anses:
if len(anses[A[j]])-2 >= anses[A[j]][0][0]:
anses[A[j]][0][0] +=1
answer +=1
answer2+=anses[A[j]][anses[A[j]][0][0]][0]
ans2[anses[A[j]][anses[A[j]][0][0]][1]] = anses[A[j]][anses[A[j]][0][0]][0]
ans[len(A)-1-j] = anses[A[j]][anses[A[j]][0][0]][1]+1
print(answer, answer2)
print(' '.join(map(str, ans2)))
print(' '.join(map(str, ans)))
``` | instruction | 0 | 55,300 | 3 | 110,600 |
No | output | 1 | 55,300 | 3 | 110,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.
There are n computers for participants, the i-th of which has power equal to positive integer pi. At the same time there are m sockets available, the j-th of which has power euqal to positive integer sj. It is possible to connect the i-th computer to the j-th socket if and only if their powers are the same: pi = sj. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.
In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with power x, the power on the adapter's socket becomes equal to <image>, it means that it is equal to the socket's power divided by two with rounding up, for example <image> and <image>.
Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power 10, it becomes possible to connect one computer with power 3 to this socket.
The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computers c at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adapters u to connect c computers.
Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.
The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of computers and the number of sockets.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 109) — the powers of the computers.
The third line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 109) — the power of the sockets.
Output
In the first line print two numbers c and u — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connect c computers.
In the second line print m integers a1, a2, ..., am (0 ≤ ai ≤ 109), where ai equals the number of adapters orginizers need to plug into the i-th socket. The sum of all ai should be equal to u.
In third line print n integers b1, b2, ..., bn (0 ≤ bi ≤ m), where the bj-th equals the number of the socket which the j-th computer should be connected to. bj = 0 means that the j-th computer should not be connected to any socket. All bj that are different from 0 should be distinct. The power of the j-th computer should be equal to the power of the socket bj after plugging in abj adapters. The number of non-zero bj should be equal to c.
If there are multiple answers, print any of them.
Examples
Input
2 2
1 1
2 2
Output
2 2
1 1
1 2
Input
2 1
2 100
99
Output
1 6
6
1 0
Submitted Solution:
```
import heapq
def main():
n, m = map(int, input().split())
p = [(int(x), i) for i, x in enumerate(input().split())]
s = map(int, input().split())
pq = []
for i, v in enumerate(s):
heapq.heappush(pq, (v, 0, i))
p.sort()
pp = 0
adapters = [0] * m
match = [0] * n
matched = 0
ans = 0
while pp < n and pq:
if p[pp][0] == pq[0][0]:
cost = pq[0][1]
index = pq[0][2]
adapters[index] = cost
match[p[pp][1]] = index + 1
matched += 1
ans += cost
pp += 1
heapq.heappop(pq)
elif p[pp][0] < pq[0][0]:
socket = heapq.heappop(pq)
heapq.heappush(pq, ((socket[0] + 1) // 2, socket[1] + 1, socket[2]))
else:
pp += 1
print(matched, ans)
print(' '.join(map(str, adapters)))
print(' '.join(map(str, match)))
main()
``` | instruction | 0 | 55,301 | 3 | 110,602 |
No | output | 1 | 55,301 | 3 | 110,603 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.
Can you help Heidi estimate each village's population?
Input
Same as the easy version.
Output
Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.
Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers. | instruction | 0 | 55,316 | 3 | 110,632 |
Tags: math
Correct Solution:
```
def sampleVariance(V):
X = sum(V) / len(V)
S = 0.0
for x in V:
S += (X-x)**2
S /= (len(V)-1)
return (X, S)
#That awkward moment when you realized that variance is sigma^2 but you just took the stat course this semester
for i in range(int(input())):
V = list(map(int, input().split()))
X, S = sampleVariance(V)
v1 = X
v2 = (2*X) ** 2 / 12
if abs(v1-S) < abs(v2-S):
print(int(X))
else:
print((max(V)+min(V)) // 2)
``` | output | 1 | 55,316 | 3 | 110,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.
Can you help Heidi estimate each village's population?
Input
Same as the easy version.
Output
Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.
Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers. | instruction | 0 | 55,317 | 3 | 110,634 |
Tags: math
Correct Solution:
```
from statistics import mean
from math import factorial, log, ceil
_lf = []
def logfact(n):
global _lf
CALCLEN = 2200
if not _lf:
_lf = [0]*CALCLEN
for i in range(2, CALCLEN):
_lf[i] = _lf[i-1] + log(i)
return _lf[n]
def unif_ml(xs):
#p1 = mean(xs)
p2 = max(xs) / 2
pmle = p2 #max(p1, p2) # probably actually not mle and biased towards 0
loglh = len(xs) * log(2*pmle + 1)
return loglh, pmle
def poiss_ml(xs):
pml = mean(xs)
loglh = len(xs)*pml + sum([-x*log(pml) + logfact(x) for x in xs])
return loglh, pml
def solve(xs):
ul, Pu = unif_ml(xs)
pl, Pp = poiss_ml(xs)
#print('dbg:', ul, pl)
if ul < pl:
p = 1.01*Pu
else:
p = Pp
print(ceil(p))
if __name__ == '__main__':
v = int(input())
for i in range(v):
xs = [int(x) for x in input().split()]
solve(xs)
``` | output | 1 | 55,317 | 3 | 110,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.
Can you help Heidi estimate each village's population?
Input
Same as the easy version.
Output
Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.
Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.
Submitted Solution:
```
v = int(input())
eps = 170
def ans(a):
a.sort()
if len(a) % 2 == 0:
med = a[len(a)//2]
else:
med = (a[len(a)//2] + a[len(a)//2 - 1]) // 2
l = med - med // 2
r = med + med // 2
c1 = c2 = 0
for i in a:
if i >= l and i <= r:
c1 += 1
else:
c2 += 1
if abs(c1 - c2) <= eps:
return (med, "uniform")
else:
return (med, "poisson")
for i in range(v):
cur = [int(i) for i in input().split()]
b = ans(cur)
if b[1] == "poisson":
print(b[0])
else:
print(sum(cur) // (max(cur) - min(cur)))
``` | instruction | 0 | 55,319 | 3 | 110,638 |
No | output | 1 | 55,319 | 3 | 110,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.
Can you help Heidi estimate each village's population?
Input
Same as the easy version.
Output
Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.
Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.
Submitted Solution:
```
from statistics import mean
from math import factorial, log, ceil
_lf = []
def logfact(n):
global _lf
CALCLEN = 2200
if not _lf:
_lf = [0]*CALCLEN
for i in range(2, CALCLEN):
_lf[i] = _lf[i-1] + log(i)
return _lf[n]
def unif_ml(xs):
p1 = mean(xs)
p2 = max(xs) / 2
pmle = max(p1, p2) # probably actually not mle and biased towards 0
loglh = len(xs) * log(2*pmle + 1)
return loglh, pmle
def poiss_ml(xs):
pml = mean(xs)
loglh = len(xs)*pml + sum([-x*log(pml) + logfact(x) for x in xs])
return loglh, pml
def solve(xs):
ul, Pu = unif_ml(xs)
pl, Pp = poiss_ml(xs)
#print('dbg:', ul, pl)
if ul < pl:
p = 1.01*Pu
else:
p = Pp
print(ceil(p))
if __name__ == '__main__':
v = int(input())
for i in range(v):
xs = [int(x) for x in input().split()]
solve(xs)
``` | instruction | 0 | 55,320 | 3 | 110,640 |
No | output | 1 | 55,320 | 3 | 110,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.
Can you help Heidi estimate each village's population?
Input
Same as the easy version.
Output
Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.
Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.
Submitted Solution:
```
v = int(input())
eps = 170
def ans(a):
a.sort()
if len(a) % 2 == 0:
med = a[len(a)//2]
else:
med = (a[len(a)//2] + a[len(a)//2 - 1]) // 2
l = med - med // 2
r = med + med // 2
c1 = c2 = 0
for i in a:
if i >= l and i <= r:
c1 += 1
else:
c2 += 1
if abs(c1 - c2) <= eps:
return (med, "uniform")
else:
return (med, "poisson")
for i in range(v):
cur = [int(i) for i in input().split()]
b = ans(cur)
if b[1] == "poisson":
print(b[0])
else:
print(sum(cur) // len(cur))
``` | instruction | 0 | 55,321 | 3 | 110,642 |
No | output | 1 | 55,321 | 3 | 110,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.
Can you help Heidi estimate each village's population?
Input
Same as the easy version.
Output
Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.
Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.
Submitted Solution:
```
v = int(input())
def ans(a):
a.sort()
if len(a) % 2 == 0:
med = a[len(a)//2]
else:
med = (a[len(a)//2] + a[len(a)//2 - 1]) // 2
return med
for i in range(v):
cur = [int(i) for i in input().split()]
print(ans(cur))
``` | instruction | 0 | 55,322 | 3 | 110,644 |
No | output | 1 | 55,322 | 3 | 110,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
import sys
sys.setrecursionlimit(100000)
n = int(input())
s0 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
s1 = 'What are you doing while sending "'
s2 = '"? Are you busy? Will you send "'
s3 = '"?'
l1,l2,l3 = [len(x) for x in [s1,s2,s3]]
ans = ''
def len_of_string(m):
return (2 ** m) * 143 - 68
def find(i, k):
if i == 0:
if k > len(s0):
return '.'
else:
return s0[k-1]
else:
b = len_of_string(i-1)
if 1 <= k <= l1:
return s1[k-1]
elif l1+1 <= k <= l1+b:
return find(i-1,k-l1)
elif l1+b+1 <= k <= l1+l2+b:
return s2[k-(l1+b)-1]
elif l1+l2+b+1 <= k <= l1+l2+2*b:
return find(i-1,k-(l1+l2+b))
elif l1+l2+2*b+1 <= k <= l1+l2+l3+2*b:
return s3[k-(l1+l2+2*b)-1]
else:
return '.'
for _ in range(n):
n,k = [int(x) for x in input().split()]
if n>8698 and k>295726:
k -= (n-1000) * len(s1)
ans += find(1000,k)
else:
ans += find(n,k)
print(ans)
``` | instruction | 0 | 55,348 | 3 | 110,696 |
Yes | output | 1 | 55,348 | 3 | 110,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
q = int(input())
q1 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
q2 = 'What are you doing while sending ""? Are you busy? Will you send ""?'
q3 = 'What are you doing while sending "'
q4 = '"? Are you busy? Will you send "'
q5 = '"?'
lq1 = len(q1)
lq2 = len(q2)
lq3 = len(q3)
lq4 = len(q4)
lq5 = len(q5)
lengths = [75]
for i in range(100):
lengths.append(lengths[-1]*2+68)
#if lengths[-1]>1000000000000000000:
# break
#print(lengths[-1])
#print(len(lengths))
#print(lengths[53])
def recurse(x, y):
if y<1:
return q3[int(y%34)-1]
#return 'A'
if y>lengths[x]:
return '.'
if x==0:
return q1[int(y-1)]
if y<=34:
return q3[int(y)-1]
#if y<=int(lengths[x]/2):
if y<=lengths[x-1]+34:
return recurse(x-1, y-34)
#if y<=int(lengths[x]/2)+32:
if y<=lengths[x-1]+66:
return q4[y-lengths[x-1]-35]
#return q4[y-int(lengths[x]/2)-1]
if y<=lengths[x]-2:
return recurse(x-1, y-lengths[x-1]-66)
return recurse(x-1, y-int(lengths[x]/2)-32)
return q5[lengths[x]-y-1]
for i in range(q):
nk = [int(x) for x in input().split()]
n = nk[0]
k = nk[1]
#for j in range(1, lengths[n]+1):
# print(recurse(n, j), end='')
#break
'''
if n==999:
print("?", end='')
break
elif n==72939:
print("?usaglrnyh", end='')
break
elif n==74:
print("h... .. d.", end='')
break
elif k==873326525630182716:
print("o W rlot", end='')
break
elif n==100000:
print("o u lugW? ", end='')
break
elif n==94455:
print("youni iiee", end='')
break
elif n==50 and k==1:
print('W"W?""W?"?', end='')
break
elif n==52 and k==1:
print('W"W?""W?"?', end='')
break
elif n==54986 and k==859285936548585889:
print('oru A" de"', end='')
break
elif n>65:
factor = n-65
print(recurse(65, k-(factor*34)), end='')
#print(q3[k%34-1], end='')
'''
if n>65:
factor = n-65
print(recurse(65, k-(factor*34)), end='')
#print(q3[k%34-1], end='')
else:
print(recurse(n, k), end='')
``` | instruction | 0 | 55,349 | 3 | 110,698 |
Yes | output | 1 | 55,349 | 3 | 110,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
str0 = "What are you doing at the end of the world? Are you busy? Will you save us?"
str1 = "What are you doing while sending \""
str2 = "\"? Are you busy? Will you send \""
str3 = "\"?"
NMAX = 100010
LMAX = 1e18 + 69
def solve(n, k):
while(n > 0):
if(k > lg[n]):
return '.'
if(k <= len(str1)):
return str1[k - 1]
elif(k <= len(str1) + lg[n - 1]):
k -= len(str1)
elif(k <= len(str1) + lg[n - 1] + len(str2)):
return str2[k - len(str1) - lg[n - 1] - 1]
elif(k <= len(str1) + lg[n - 1] + len(str2) + lg[n - 1]):
k -= len(str1) + lg[n - 1] + len(str2)
else:
return str3[k - len(str1) - lg[n - 1] - len(str2) - lg[n - 1] - 1]
n -= 1
if(k <= len(str0)):
return str0[k - 1]
return '.'
lg = [0] * NMAX
lg[0] = len(str0)
for i in range(1, NMAX):
lg[i] = 2 * lg[i - 1] + len(str1) + len(str2) + len(str3)
if(lg[i] > LMAX):
lg[i] = LMAX
q = int(input())
while(q > 0):
n, k = map(int, input().split())
print(solve(n, k), end='')
q -= 1
``` | instruction | 0 | 55,350 | 3 | 110,700 |
Yes | output | 1 | 55,350 | 3 | 110,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
import sys
sys.setrecursionlimit(1500)
s1 = "What are you doing at the end of the world? Are you busy? Will you save us?"
a = "What are you doing while sending \""
b = "\"? Are you busy? Will you send \""
c = "\"?"
ans = ""
def solve(n, k):
if n == 0:
if k >= len(s1):
return "."
else:
return s1[k]
if k < len(a):
return a[k]
k -= len(a)
prev_len = (2 ** (n - 1) - 1) * (len(a) + len(b) + len(c)) + (2 ** (n - 1)) * len(s1)
if k < prev_len:
return solve(n - 1, k)
k -= prev_len
if k < len(b):
return b[k]
k -= len(b)
if k < prev_len:
return solve(n - 1, k)
k -= prev_len
if k < len(c):
return c[k]
else:
return "."
for _ in range(int(input())):
n, k = list(map(int, input().split()))
k -= 1
if n > 65:
m = n - 65
if k < len(a) * m:
ans += a[k % len(a)]
continue
k -= len(a) * m
n = n - m
ans += solve(n, k)
print(ans)
``` | instruction | 0 | 55,351 | 3 | 110,702 |
Yes | output | 1 | 55,351 | 3 | 110,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
q = int(input())
q1 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
q2 = 'What are you doing while sending ""? Are you busy? Will you send ""?'
q3 = 'What are you doing while sending "'
q4 = '"? Are you busy? Will you send "'
q5 = '"?'
lq1 = len(q1)
lq2 = len(q2)
lq3 = len(q3)
lq4 = len(q4)
lq5 = len(q5)
lengths = [75]
for i in range(60000):
lengths.append(lengths[-1]*2+68)
if lengths[-1]>1000000000000000000:
break
print(lengths[-1])
print(len(lengths))
def recurse(x, y):
if y>lengths[x]:
return '.'
if x==0:
return q1[int(y-1)]
if y<=34:
return q3[int(y-1)]
if y<=lengths[x]/2:
return recurse(x-1, y-34)
if y<lengths[x]/2+32:
return q4[int(y-lengths[int(x)]/2)-1]
if y<lengths[x]-2:
return recurse(x-1, y-lengths[int(x)]/2-32)
return q5[lengths[x]-y-1]
for i in range(q):
nk = [int(x) for x in input().split()]
n = nk[0]
k = nk[1]
if n>54:
print(q3[k%34], end='')
else:
print(recurse(n, k), end='')
``` | instruction | 0 | 55,352 | 3 | 110,704 |
No | output | 1 | 55,352 | 3 | 110,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
q = int(input())
q1 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
q2 = 'What are you doing while sending ""? Are you busy? Will you send ""?'
q3 = 'What are you doing while sending "'
q4 = '"? Are you busy? Will you send "'
q5 = '"?'
lq1 = len(q1)
lq2 = len(q2)
lq3 = len(q3)
lq4 = len(q4)
lq5 = len(q5)
lengths = [75]
for i in range(100):
lengths.append(lengths[-1]*2+68)
#if lengths[-1]>1000000000000000000:
# break
#print(lengths[-1])
#print(len(lengths))
#print(lengths[53])
def recurse(x, y):
if y<1:
return q3[int(y%34)-1]
if y>lengths[x]:
return '.'
if x==0:
return q1[int(y-1)]
if y<=34:
return q3[int(y)-1]
if y<=int(lengths[x]/2):
return recurse(x-1, y-34)
if y<=int(lengths[x]/2)+32:
return q4[y-int(lengths[x]/2)-1]
if y<=lengths[x]-2:
return recurse(x-1, y-int(lengths[x]/2)-32)
return q5[lengths[x]-y-1]
for i in range(q):
nk = [int(x) for x in input().split()]
n = nk[0]
k = nk[1]
if n==999:
print("?", end='')
break
elif n==72939:
print("?usaglrnyh", end='')
break
elif n==74:
print("h... .. d.", end='')
break
elif k==873326525630182716:
print("o W rlot", end='')
break
elif n==100000:
print("o u lugW? ", end='')
break
elif n==94455:
print("youni iiee", end='')
break
elif n==50 and k==1:
print('W"W?""W?"?', end='')
break
elif n==52 and k==1:
print('W"W?""W?"?', end='')
break
elif n>53:
factor = n-53
print(recurse(53, k-(factor*34)), end='')
else:
print(recurse(n, k), end='')
``` | instruction | 0 | 55,353 | 3 | 110,706 |
No | output | 1 | 55,353 | 3 | 110,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
q = int(input())
q1 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
q2 = 'What are you doing while sending ""? Are you busy? Will you send ""?'
q3 = 'What are you doing while sending "'
q4 = '"? Are you busy? Will you send "'
q5 = '"?'
lq1 = len(q1)
lq2 = len(q2)
lq3 = len(q3)
lq4 = len(q4)
lq5 = len(q5)
lengths = [75]
for i in range(100):
lengths.append(lengths[-1]*2+68)
#if lengths[-1]>1000000000000000000:
# break
#print(lengths[-1])
#print(len(lengths))
#print(lengths[53])
def recurse(x, y):
if y<1:
return q3[int(y%34)-1]
if y>lengths[x]:
return '.'
if x==0:
return q1[int(y-1)]
if y<=34:
return q3[int(y)-1]
if y<=int(lengths[x]/2):
return recurse(x-1, y-34)
if y<=int(lengths[x]/2)+32:
return q4[y-int(lengths[int(x)]/2)-1]
if y<=lengths[x]-2:
return recurse(x-1, y-int(lengths[int(x)]/2)-32)
return q5[lengths[int(x)]-y-1]
for i in range(q):
nk = [int(x) for x in input().split()]
n = nk[0]
k = nk[1]
if n==999:
print("?", end='')
break
elif n==72939:
print("?usaglrnyh", end='')
break
elif n==74:
print("h... .. d.", end='')
break
elif n==100000:
print("o u lugW? ", end='')
break
elif n==94455:
print("youni iiee", end='')
break
elif n>53:
factor = n-53
print(recurse(53, k-(factor*34)), end='')
else:
print(recurse(n, k), end='')
``` | instruction | 0 | 55,354 | 3 | 110,708 |
No | output | 1 | 55,354 | 3 | 110,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
Submitted Solution:
```
q = int(input())
q1 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
q2 = 'What are you doing while sending ""? Are you busy? Will you send ""?'
q3 = 'What are you doing while sending "'
q4 = '"? Are you busy? Will you send "'
q5 = '"?'
lq1 = len(q1)
lq2 = len(q2)
lq3 = len(q3)
lq4 = len(q4)
lq5 = len(q5)
lengths = [75]
for i in range(100):
lengths.append(lengths[-1]*2+68)
#if lengths[-1]>1000000000000000000:
# break
#print(lengths[-1])
#print(len(lengths))
#print(lengths[53])
def recurse(x, y):
if y<1:
#return q3[int(y%34)-1]
return 'A'
if y>lengths[x]:
return '.'
if x==0:
return q1[int(y-1)]
if y<=34:
return q3[int(y)-1]
#if y<=int(lengths[x]/2):
if y<=lengths[x-1]+34:
return recurse(x-1, y-34)
#if y<=int(lengths[x]/2)+32:
if y<=lengths[x-1]+66:
return q4[y-lengths[x-1]-35]
#return q4[y-int(lengths[x]/2)-1]
if y<=lengths[x]-2:
return recurse(x-1, y-lengths[x-1]-66)
return recurse(x-1, y-int(lengths[x]/2)-32)
return q5[lengths[x]-y-1]
for i in range(q):
nk = [int(x) for x in input().split()]
n = nk[0]
k = nk[1]
#for j in range(1, lengths[n]+1):
# print(recurse(n, j), end='')
#break
'''
if n==999:
print("?", end='')
break
elif n==72939:
print("?usaglrnyh", end='')
break
elif n==74:
print("h... .. d.", end='')
break
elif k==873326525630182716:
print("o W rlot", end='')
break
elif n==100000:
print("o u lugW? ", end='')
break
elif n==94455:
print("youni iiee", end='')
break
elif n==50 and k==1:
print('W"W?""W?"?', end='')
break
elif n==52 and k==1:
print('W"W?""W?"?', end='')
break
elif n==54986 and k==859285936548585889:
print('oru A" de"', end='')
break
elif n>65:
factor = n-65
print(recurse(65, k-(factor*34)), end='')
#print(q3[k%34-1], end='')
'''
if n>65:
factor = n-65
print(recurse(65, k-(factor*34)), end='')
#print(q3[k%34-1], end='')
else:
print(recurse(n, k), end='')
``` | instruction | 0 | 55,355 | 3 | 110,710 |
No | output | 1 | 55,355 | 3 | 110,711 |
Provide a correct Python 3 solution for this coding contest problem.
Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold bar has the same length and is placed parallel to one of the three orthogonal axes in a three dimensional space, i.e., x-axis, y-axis and z-axis.
The locking mechanism of the jewelry box is truly mysterious, but the shape of the key is known. To identify the key of the jewelry box, he gave a way to describe its shape.
The description indicates a list of connected paths that completely defines the shape of the key: the gold bars of the key are arranged along the paths and joined at their ends. Except for the first path, each path must start from an end point of a gold bar on a previously defined path. Each path is represented by a sequence of elements, each of which is one of six symbols (+x, -x, +y, -y, +z and -z) or a positive integer. Each symbol indicates the direction from an end point to the other end point of a gold bar along the path. Since each gold bar is parallel to one of the three orthogonal axes, the 6 symbols are enough to indicate the direction. Note that a description of a path has direction but the gold bars themselves have no direction.
An end point of a gold bar can have a label, which is a positive integer. The labeled point may be referred to as the beginnings of other paths. In a key description, the first occurrence of a positive integer defines a label of a point and each subsequent occurrence of the same positive integer indicates the beginning of a new path at the point.
An example of a key composed of 13 gold bars is depicted in Figure 1.
<image>
The following sequence of lines
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +z
2 +y
is a description of the key in Figure 1. Note that newlines have the same role as space characters in the description, so that `"19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y"` has the same meaning.
The meaning of this description is quite simple. The first integer "19" means the number of the following elements in this description. Each element is one of the 6 symbols or a positive integer.
The integer "1" at the head of the second line is a label attached to the starting point of the first path. Without loss of generality, it can be assumed that the starting point of the first path is the origin, i.e., (0,0,0), and that the length of each gold bar is 1. The next element "+x" indicates that the first gold bar is parallel to the x-axis, so that the other end point of the gold bar is at (1,0,0). These two elements "1" and "+x" indicates the first path consisting of only one gold bar. The third element of the second line in the description is the positive integer "1", meaning that the point with the label "1", i.e., the origin (0,0,0) is the beginning of a new path. The following elements "+y", "+z", "3", and "+z" indicate the second path consisting of three gold bars. Note that this "3" is its first occurrence so that the point with coordinates (0,1,1) is labeled "3". The head of the third line "3" indicates the beginning of the third path and so on. Consequently, there are four paths by which the shape of the key in Figure 1 is completely defined.
Note that there are various descriptions of the same key since there are various sets of paths that cover the shape of the key. For example, the following sequence of lines
19
1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y
3 +z
2 +z
is another description of the key in Figure 1, since the gold bars are placed in the same way.
Furthermore, the key may be turned 90-degrees around x-axis, y-axis or z-axis several times and may be moved parallelly. Since any combinations of rotations and parallel moves don't change the shape of the key, a description of a rotated and moved key also represent the same shape of the original key. For example, a sequence
17
+y 1 +y -z +x
1 +z +y +x +z +y -x -y 2 -y
2 +z
is a description of a key in Figure 2 that represents the same key as in Figure 1. Indeed, they are congruent under a rotation around x-axis and a parallel move.
<image>
Your job is to write a program to judge whether or not the given two descriptions define the same key.
Note that paths may make a cycle. For example, `"4 +x +y -x -y"` and `"6 1 +x 1 +y +x -y"` are valid descriptions. However, two or more gold bars must not be placed at the same position. For example, key descriptions `"2 +x -x"` and `"7 1 +x 1 +y +x -y -x"` are invalid.
Input
An input data is a list of pairs of key descriptions followed by a zero that indicates the end of the input. For p pairs of key descriptions, the input is given in the following format.
key-description1-a
key-description1-b
key-description2-a
key-description2-b
...
key-descriptionp-a
key-descriptionp-b
0
Each key description (key-description) has the following format.
n` ` e1 ` ` e2 ` ` ... ` ` ek ` ` ... ` ` en
The positive integer n indicates the number of the following elements e1, ..., en . They are separated by one or more space characters and/or newlines. Each element ek is one of the six symbols (`+x`, `-x`, `+y`, `-y`, `+z` and `-z`) or a positive integer.
You can assume that each label is a positive integer that is less than 51, the number of elements in a single key description is less than 301, and the number of characters in a line is less than 80. You can also assume that the given key descriptions are valid and contain at least one gold bar.
Output
The number of output lines should be equal to that of pairs of key descriptions given in the input. In each line, you should output one of two words "SAME", when the two key descriptions represent the same key, and "DIFFERENT", when they are different. Note that the letters should be in upper case.
Examples
Input
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +z
2 +y
19
1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y
3 +z
2 +z
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +y
2 +z
18
1 -y
1 +y -z +x
1 +z +y +x +z +y -x -y 2 -y
2 +z
3 +x +y +z
3 +y +z -x
0
Output
SAME
SAME
DIFFERENT
Input
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +z
2 +y
19
1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y
3 +z
2 +z
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +y
2 +z
18
1 -y
1 +y -z +x
1 +z +y +x +z +y -x -y 2 -y
2 +z
3 +x +y +z
3 +y +z -x
0
Output
SAME
SAME
DIFFERENT | instruction | 0 | 55,551 | 3 | 111,102 |
"Correct Solution:
```
def solve(sentence):
now = [0, 0, 0] # x,y,z
num_p = {}
positions = []
for s in sentence:
if s.isdecimal():
if s in num_p:
now = num_p[s]
else:
num_p[s] = now
else:
sign = 1 if s[0] == "+" else -1
if s[1] == "x":
positions.append([now.copy(), [now[0] + sign, now[1], now[2]]])
now = [now[0] + sign, now[1], now[2]]
if s[1] == "y":
positions.append([now.copy(), [now[0], now[1] + sign, now[2]]])
now = [now[0], now[1] + sign, now[2]]
if s[1] == "z":
positions.append([now.copy(), [now[0], now[1], now[2] + sign]])
now = [now[0], now[1], now[2] + sign]
return positions
def rotateX(positions):
miny = float("inf")
minz = float("inf")
for i in range(len(positions)):
for j in range(2):
positions[i][j][1], positions[i][j][2] = -positions[i][j][2], positions[i][j][1]
if positions[i][j][1] < miny:
miny = positions[i][j][1]
if positions[i][j][2] < minz:
minz = positions[i][j][2]
# シフト
for i in range(len(positions)):
for j in range(2):
positions[i][j][1] -= miny
positions[i][j][2] -= minz
positions[i].sort()
return positions
def rotateY(positions):
minx = float("inf")
minz = float("inf")
for i in range(len(positions)):
for j in range(2):
positions[i][j][0], positions[i][j][2] = -positions[i][j][2], positions[i][j][0]
if positions[i][j][0] < minx:
minx = positions[i][j][0]
if positions[i][j][2] < minz:
minz = positions[i][j][2]
# シフト
for i in range(len(positions)):
for j in range(2):
positions[i][j][0] -= minx
positions[i][j][2] -= minz
positions[i].sort()
return positions
def rotateZ(positions):
minx = float("inf")
miny = float("inf")
for i in range(len(positions)):
for j in range(2):
positions[i][j][0], positions[i][j][1] = -positions[i][j][1], positions[i][j][0]
if positions[i][j][0] < minx:
minx = positions[i][j][0]
if positions[i][j][1] < miny:
miny = positions[i][j][1]
# シフト
for i in range(len(positions)):
for j in range(2):
positions[i][j][0] -= minx
positions[i][j][1] -= miny
positions[i].sort()
return positions
def normal(positions):
minx = float("inf")
miny = float("inf")
minz = float("inf")
for i in range(len(positions)):
if positions[i][0][0] < minx:
minx = positions[i][0][0]
if positions[i][1][0] < minx:
minx = positions[i][1][0]
if positions[i][0][1] < miny:
miny = positions[i][0][1]
if positions[i][1][1] < miny:
miny = positions[i][1][1]
if positions[i][0][2] < minz:
minz = positions[i][0][2]
if positions[i][1][2] < minz:
minz = positions[i][1][2]
for i in range(len(positions)):
for j in range(2):
positions[i][j][0] -= minx
positions[i][j][1] -= miny
positions[i][j][2] -= minz
positions[i].sort()
return positions
def check(position1, position2):
if len(position1) != len(position2):
return False
position1.sort()
position2.sort()
for i in range(len(position1)):
if position1[i][0] not in position2[i] or position1[i][1] not in position2[i]:
return False
return True
while True:
string = input()
if string != "":
n, *S = string.split()
else:
continue
n = int(n)
if n == 0:
break
while len(S) < n:
S += input().split()
position1 = normal(solve(S))
n, *S = input().split()
n = int(n)
while len(S) < n:
S += input().split()
position2 = normal(solve(S))
# 入力ここまで
end = False
for z in range(4):
for y in range(4):
for x in range(4):
if check(position1, position2):
end = True
break
position2 = rotateX(position2)
if end:
break
position2 = rotateY(position2)
if end:
break
position2 = rotateZ(position2)
if end:
print("SAME")
else:
print("DIFFERENT")
``` | output | 1 | 55,551 | 3 | 111,103 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.