message stringlengths 2 22.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 16 109k | cluster float64 1 1 | __index_level_0__ int64 32 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,072 | 1 | 22,144 |
Tags: implementation
Correct Solution:
```
"""
def cf31B():
#print("Hello World")
from sys import stdin,stdout
inp = list(stdin.readline().strip().split('@'))
flag = True
if len(inp)>=2:
if len(inp[0])==0 or len(inp[-1])==0:
flag = False
if flag:
for i in range(1,len(inp)-1):
if len(inp[i]) < 2:
flag = False
break
else:
flag = False
answer = ""
if flag:
for i , j in enumerate(inp):
if i==0:
answer+=j
elif i==len(inp)-1:
answer+='@'+j
else:
answer+='@'+j[:-1]+','+j[-1]
else:
answer = "No solution"
stdout.write(answer+"\n")
def cf75B():
from sys import stdin, stdout
myname = stdin.readline().strip()
points = {}
for _ in range(int(stdin.readline())):
inp = stdin.readline().strip().split()
a = inp[0]
b = inp[-2][:-2]
p = 0
if inp[1][0] == 'p':
p=15
elif inp[1][0] == 'c':
p=10
else:
p = 5
if a==myname:
if b in points:
points[b] += p
else:
points[b] = p
elif b==myname:
if a in points:
points[a] += p
else:
points[a] = p
else:
if a not in points:
points[a] = 0
if b not in points:
points[b] = 0
revpoints = {}
mylist = []
for key in points:
if points[key] in revpoints:
revpoints[points[key]].append(key)
else:
revpoints[points[key]]=[key,]
for key in revpoints:
revpoints[key].sort()
for key in revpoints:
mylist.append((key,revpoints[key]))
mylist.sort(reverse=True)
for i,j in enumerate(mylist):
for name in j[1]:
stdout.write(name+'\n')
def cf340B():
from sys import stdin, stdout
maxim = -1e9
permutation = []
chosen = [False for x in range(300)]
def search():
if len(permutation)==4:
maxim = max(maxim,calculate_area(permutation))
else:
for i in range(len(colist)):
if chosen[i]:
continue
chosen[i]=True
permutation.append(colist[i])
search()
chosen[i]=False
permutation = permutation[:-1]
def calculate_area(arr):
others = []
leftmost = arr[0]
rightmost = arr[0]
for i in arr:
if i[0]<leftmost[0]:
leftmost = i
elif i[0]>rightmost[0]:
rightmost = i
for i in arr:
if i!=leftmost and i!=rightmost:
others.append(i)
base_length = ((leftmost[0]-rightmost[0])**2 + (leftmost[1]-rightmost[1])**2)**0.5
#print(base_length)
if base_length == 0:
return 0
m = (rightmost[1] - leftmost[1])/(rightmost[0]-leftmost[0])
k = leftmost[1] + (-1)*leftmost[0]*m
#print(m)
#print(k)
t1 = abs(k+m*others[0][0]-others[0][1])/((1+m*m)**0.5)*base_length*0.5
t2 = abs(k+m*others[1][0]-others[1][1])/((1+m*m)**0.5)*base_length*0.5
#print(t1)
#print(t2)
return t1+t2
colist = []
for _ in range(int(stdin.readline())):
x,y = map(int,stdin.readline().split())
colist.append((x,y))
#print(colist)
#ans = calculate_area((0,0),(0,4),(4,0),(4,4))
#print(ans)
search()
stdout.write(str(maxim)+'\n')
"""
def cf29B():
from sys import stdin,stdout
l,d,v,g,r=map(int,stdin.readline().split())
t=0
t+=d/v
cycle=g+r
rem = t
while rem > cycle:
rem -= cycle
if rem >= g:
rem -=g
t+=(r-rem)
t+=(l-d)/v
stdout.write("{0:.6f}\n".format(t))
if __name__=='__main__':
cf29B()
``` | output | 1 | 11,072 | 1 | 22,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,073 | 1 | 22,146 |
Tags: implementation
Correct Solution:
```
import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1e9)+7
l, d, v, g, r = rinput()
time = (d/v)%(g+r)
ans = l/v
if time<g:
print(ans)
else:
ans += r + g - time
print(ans)
``` | output | 1 | 11,073 | 1 | 22,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,074 | 1 | 22,148 |
Tags: implementation
Correct Solution:
```
l,d,v,g,r=map(int,input().split())
t=d/v
c=0
i1=0
i2=g
while(not(i1<=t and i2>=t)):
c+=1
if(c%2!=0):
i1=i2
i2=i2+r
else:
i1=i2
i2=i2+g
if(i1==t or i2==t):
c+=1
if(c%2!=0 and (i1==t or i2==t)):
t=i2+r
elif(c%2!=0):
t=i2
t+=(l-d)/v
print(t)
``` | output | 1 | 11,074 | 1 | 22,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,075 | 1 | 22,150 |
Tags: implementation
Correct Solution:
```
l, d, v, g, r = map(int, input().split())
t = d/v
ft = t%(g+r)
if ft >= g:
t += r-(ft-g)
t += (l-d)/v
print(t)
``` | output | 1 | 11,075 | 1 | 22,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,076 | 1 | 22,152 |
Tags: implementation
Correct Solution:
```
# n=int(input())
l,d,v,g,r=map(int,input().split())
z=d/v
y=(l-d)/v
temp=z
light=True
x=0
# print(z,y)
while(1):
if(x%2==0):
if(temp>=g):
temp-=g
light=False
else:
break
else:
if(temp>=r):
temp-=r
light=True
else:
break
x+=1
if(light):
print("{0:.8f}".format(z+y))
else:
print("{0:.8f}".format(z+(r-temp)+y))
``` | output | 1 | 11,076 | 1 | 22,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,077 | 1 | 22,154 |
Tags: implementation
Correct Solution:
```
l,d,v,g,r=list(map(int,input().split()))
t1=(d/v)%(g+r)-g
if t1<0:
print(l/v)
else:
print(l/v+r-t1)
``` | output | 1 | 11,077 | 1 | 22,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,078 | 1 | 22,156 |
Tags: implementation
Correct Solution:
```
l, d, v, g, r = map(int, input().split())
x = (d / v) % (g + r)
if x < g:
print(l / v)
else:
print(d / v + abs(x - (g + r)) + ((l - d) / v))
``` | output | 1 | 11,078 | 1 | 22,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333 | instruction | 0 | 11,079 | 1 | 22,158 |
Tags: implementation
Correct Solution:
```
l,d,v,g,r=map(int,input().split())
t=l/v
test = d/v
n=0
while test >= 0:
if n%2 == 0:
test -= g
else:
test -= r
n+=1
if n%2==0:
t+=abs(test)
print(t)
``` | output | 1 | 11,079 | 1 | 22,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
l, d, v, g, r = map(int, input().split())
b = d / v
t = b % (g + r)
if t < g:
print(b + (l - d) / v)
else:
print(b - t + g + r + (l - d) / v)
``` | instruction | 0 | 11,080 | 1 | 22,160 |
Yes | output | 1 | 11,080 | 1 | 22,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
def solve():
l, d, v, g, r = [int(x) for x in input().split(' ')]
#Get to Traffic Lights
t = d / v
#Stop at lights if necessary
x = t % (g + r)
if x >= g:
t += (g + r) - x
#Continue to complete journey
t += (l - d) / v
#Return total time
return t
print(solve())
``` | instruction | 0 | 11,081 | 1 | 22,162 |
Yes | output | 1 | 11,081 | 1 | 22,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
dist, toLight, maxSpeed, green, red = map(int, input().split())
f = toLight // maxSpeed
t = 0
for i in range(1010):
if i % 2 == 0:
if t <= f < t + green:
print(toLight * 1.0 / maxSpeed + (dist - toLight) * 1.0 / maxSpeed)
break
t += green
else:
if t <= f < t + red:
tm = toLight * 1.0 / maxSpeed
print(t + red + (dist - toLight) * 1.0 / maxSpeed)
break
t += red
``` | instruction | 0 | 11,082 | 1 | 22,164 |
Yes | output | 1 | 11,082 | 1 | 22,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
dt,pd,sp,g,r = map(int,input().split())
it = pd/sp
if(it<g):
ntt = dt/sp
print("%.8f" %ntt )
elif it>(g+r):
tr = it+(g+r)
if(it%(g+r)):print("%.8f"%tr)
else:
nt = r+g+((dt-pd)/sp)
print("%.8f" % nt)
``` | instruction | 0 | 11,083 | 1 | 22,166 |
Yes | output | 1 | 11,083 | 1 | 22,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
#l distance A to B
#d distance A to traffic light
#v car speed
#g duration of green light
#r duration of red light
sets=[int(e) for e in input().split()]
l=sets[0]
d=sets[1]
v=sets[2]
g=sets[3]
r=sets[4]
timebeforelight=d/v
restofdistance=l-d
totaltime=0
if timebeforelight>=g:
totaltime=totaltime+timebeforelight+r
elif timebeforelight<g:
totaltime=totaltime+timebeforelight
print('%.8f'%totaltime)
``` | instruction | 0 | 11,084 | 1 | 22,168 |
No | output | 1 | 11,084 | 1 | 22,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
dist, toLight, maxSpeed, green, red = map(int, input().split())
g = gcd(toLight, maxSpeed)
toLight //= g
maxSpeed //= g
f = dist // maxSpeed
t = 0
for i in range(1010):
if i % 2 == 0:
if t <= f < t + green:
print(toLight * 1.0 / maxSpeed + (dist - toLight) * 1.0 / maxSpeed)
break
t += green
else:
if t <= f < t + red:
tm = toLight * 1.0 / maxSpeed
print(t + red + (dist - toLight) * 1.0 / maxSpeed)
break
t += red
``` | instruction | 0 | 11,085 | 1 | 22,170 |
No | output | 1 | 11,085 | 1 | 22,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
l,d,v,g,r=map(int,input().split())
t=d/v
y=t%(g+r)
if y<=g and y!=0:
wt=0
if y==0:
wt+=1
else:
wt=g+r-y
tt=t+wt+(l-d)/v
print(tt)
``` | instruction | 0 | 11,086 | 1 | 22,172 |
No | output | 1 | 11,086 | 1 | 22,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.
The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input
The first line contains integers l, d, v, g, r (1 β€ l, d, v, g, r β€ 1000, d < l) β the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output
Output a single number β the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10 - 6.
Examples
Input
2 1 3 4 5
Output
0.66666667
Input
5 4 3 1 1
Output
2.33333333
Submitted Solution:
```
l,d,v,g,r=map(int, input().split())
t=0
p=0
total=r+g
x=[i for i in range(d,l,d)]
for i in x:
t+=((i-p)/v)
p+=i
a=t%total
if a<g:
continue
else:
t+=(total-a)
t+=((l-p)/v)
print(t)
``` | instruction | 0 | 11,087 | 1 | 22,174 |
No | output | 1 | 11,087 | 1 | 22,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cities in Cyberland, numbered from 1 to n, connected by m bidirectional roads. The j-th road connects city aj and bj.
For tourists, souvenirs are sold in every city of Cyberland. In particular, city i sell it at a price of wi.
Now there are q queries for you to handle. There are two types of queries:
* "C a w": The price in city a is changed to w.
* "A a b": Now a tourist will travel from city a to b. He will choose a route, he also doesn't want to visit a city twice. He will buy souvenirs at the city where the souvenirs are the cheapest (possibly exactly at city a or b). You should output the minimum possible price that he can buy the souvenirs during his travel.
More formally, we can define routes as follow:
* A route is a sequence of cities [x1, x2, ..., xk], where k is a certain positive integer.
* For any 1 β€ i < j β€ k, xi β xj.
* For any 1 β€ i < k, there is a road connecting xi and xi + 1.
* The minimum price of the route is min(wx1, wx2, ..., wxk).
* The required answer is the minimum value of the minimum prices of all valid routes from a to b.
Input
The first line of input contains three integers n, m, q (1 β€ n, m, q β€ 105), separated by a single space.
Next n lines contain integers wi (1 β€ wi β€ 109).
Next m lines contain pairs of space-separated integers aj and bj (1 β€ aj, bj β€ n, aj β bj).
It is guaranteed that there is at most one road connecting the same pair of cities. There is always at least one valid route between any two cities.
Next q lines each describe a query. The format is "C a w" or "A a b" (1 β€ a, b β€ n, 1 β€ w β€ 109).
Output
For each query of type "A", output the corresponding answer.
Examples
Input
3 3 3
1
2
3
1 2
2 3
1 3
A 2 3
C 1 5
A 2 3
Output
1
2
Input
7 9 4
1
2
3
4
5
6
7
1 2
2 5
1 5
2 3
3 4
2 4
5 6
6 7
5 7
A 2 3
A 6 4
A 6 7
A 3 3
Output
2
1
5
3
Note
For the second sample, an optimal routes are:
From 2 to 3 it is [2, 3].
From 6 to 4 it is [6, 5, 1, 2, 4].
From 6 to 7 it is [6, 5, 7].
From 3 to 3 it is [3].
<image>
Submitted Solution:
```
def dfs(u,mark,e):
mark[u] = True
a[u].sort()
for i in range(len(a[u])):
if (mark[a[u][i][1]] == False):
if (e[u] < e[a[u][i][1]]):
e[a[u][i][1]] = e[u]
dfs(a[u][i][1],mark,e)
n,m,x = map(int,input().split())
w = [0] * (n+1)
a = [ [] for i in range(n+1) ]
def turists(n,m,x,a,w):
for i in range(1,n+1):
w[i] = int(input())
for i in range(m):
b,f = map(int,input().split())
a[b].append([w[f],f])
a[f].append([w[b],b])
for i in range(x):
s = list(map(str,input().split()))
if (s[0] == 'C'):
w[int(s[1])] = int(s[2])
for j in range(len(a)):
for r in range(len(a[j])):
if (a[j][r][1] == int(s[1])):
a[j][r][0] = int(s[2])
elif (s[0] == 'A'):
parent = -1
e = [0] * (n+1)
mark = [False] * (n+1)
for j in range(len(w)):
e[j] = w[j]
dfs(int(s[1]),mark,e)
print(e[int(s[2])])
z = turists(n,m,x,a,w)
``` | instruction | 0 | 11,157 | 1 | 22,314 |
No | output | 1 | 11,157 | 1 | 22,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cities in Cyberland, numbered from 1 to n, connected by m bidirectional roads. The j-th road connects city aj and bj.
For tourists, souvenirs are sold in every city of Cyberland. In particular, city i sell it at a price of wi.
Now there are q queries for you to handle. There are two types of queries:
* "C a w": The price in city a is changed to w.
* "A a b": Now a tourist will travel from city a to b. He will choose a route, he also doesn't want to visit a city twice. He will buy souvenirs at the city where the souvenirs are the cheapest (possibly exactly at city a or b). You should output the minimum possible price that he can buy the souvenirs during his travel.
More formally, we can define routes as follow:
* A route is a sequence of cities [x1, x2, ..., xk], where k is a certain positive integer.
* For any 1 β€ i < j β€ k, xi β xj.
* For any 1 β€ i < k, there is a road connecting xi and xi + 1.
* The minimum price of the route is min(wx1, wx2, ..., wxk).
* The required answer is the minimum value of the minimum prices of all valid routes from a to b.
Input
The first line of input contains three integers n, m, q (1 β€ n, m, q β€ 105), separated by a single space.
Next n lines contain integers wi (1 β€ wi β€ 109).
Next m lines contain pairs of space-separated integers aj and bj (1 β€ aj, bj β€ n, aj β bj).
It is guaranteed that there is at most one road connecting the same pair of cities. There is always at least one valid route between any two cities.
Next q lines each describe a query. The format is "C a w" or "A a b" (1 β€ a, b β€ n, 1 β€ w β€ 109).
Output
For each query of type "A", output the corresponding answer.
Examples
Input
3 3 3
1
2
3
1 2
2 3
1 3
A 2 3
C 1 5
A 2 3
Output
1
2
Input
7 9 4
1
2
3
4
5
6
7
1 2
2 5
1 5
2 3
3 4
2 4
5 6
6 7
5 7
A 2 3
A 6 4
A 6 7
A 3 3
Output
2
1
5
3
Note
For the second sample, an optimal routes are:
From 2 to 3 it is [2, 3].
From 6 to 4 it is [6, 5, 1, 2, 4].
From 6 to 7 it is [6, 5, 7].
From 3 to 3 it is [3].
<image>
Submitted Solution:
```
def dfs(u,mark,e):
mark[u] = True
a[u].sort()
for i in range(len(a[u])):
if (mark[a[u][i][1]] == False):
if (e[u] < e[a[u][i][1]]):
e[a[u][i][1]] = e[u]
dfs(a[u][i][1],mark,e)
n,m,x = map(int,input().split())
w = [0] * (n+1)
a = [ [] for i in range(n+1) ]
def turists(n,m,x,a,w):
for i in range(1,n+1):
w[i] = int(input())
for i in range(m):
b,f = map(int,input().split())
a[b].append([w[f],f])
a[f].append([w[b],b])
for i in range(x):
s = list(map(str,input().split()))
if (s[0] == 'C'):
w[int(s[1])] = int(s[2])
elif (s[0] == 'A'):
parent = -1
e = [0] * (n+1)
mark = [False] * (n+1)
for j in range(len(w)):
e[j] = w[j]
dfs(int(s[1]),mark,e)
print(e[int(s[2])])
z = turists(n,m,x,a,w)
``` | instruction | 0 | 11,158 | 1 | 22,316 |
No | output | 1 | 11,158 | 1 | 22,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cities in Cyberland, numbered from 1 to n, connected by m bidirectional roads. The j-th road connects city aj and bj.
For tourists, souvenirs are sold in every city of Cyberland. In particular, city i sell it at a price of wi.
Now there are q queries for you to handle. There are two types of queries:
* "C a w": The price in city a is changed to w.
* "A a b": Now a tourist will travel from city a to b. He will choose a route, he also doesn't want to visit a city twice. He will buy souvenirs at the city where the souvenirs are the cheapest (possibly exactly at city a or b). You should output the minimum possible price that he can buy the souvenirs during his travel.
More formally, we can define routes as follow:
* A route is a sequence of cities [x1, x2, ..., xk], where k is a certain positive integer.
* For any 1 β€ i < j β€ k, xi β xj.
* For any 1 β€ i < k, there is a road connecting xi and xi + 1.
* The minimum price of the route is min(wx1, wx2, ..., wxk).
* The required answer is the minimum value of the minimum prices of all valid routes from a to b.
Input
The first line of input contains three integers n, m, q (1 β€ n, m, q β€ 105), separated by a single space.
Next n lines contain integers wi (1 β€ wi β€ 109).
Next m lines contain pairs of space-separated integers aj and bj (1 β€ aj, bj β€ n, aj β bj).
It is guaranteed that there is at most one road connecting the same pair of cities. There is always at least one valid route between any two cities.
Next q lines each describe a query. The format is "C a w" or "A a b" (1 β€ a, b β€ n, 1 β€ w β€ 109).
Output
For each query of type "A", output the corresponding answer.
Examples
Input
3 3 3
1
2
3
1 2
2 3
1 3
A 2 3
C 1 5
A 2 3
Output
1
2
Input
7 9 4
1
2
3
4
5
6
7
1 2
2 5
1 5
2 3
3 4
2 4
5 6
6 7
5 7
A 2 3
A 6 4
A 6 7
A 3 3
Output
2
1
5
3
Note
For the second sample, an optimal routes are:
From 2 to 3 it is [2, 3].
From 6 to 4 it is [6, 5, 1, 2, 4].
From 6 to 7 it is [6, 5, 7].
From 3 to 3 it is [3].
<image>
Submitted Solution:
```
# inp = open("input.txt", "r"); input = readline; out = open("output.txt", "w"); print = write
TN = 1
def road(x, y):
global lsm, w
if x == y:
return w[x]
else:
rtrn = []
def solution():
global lsm, w
n, m, q = map(int, input().split())
w = []
lsm = [[] for i in range(n+1)]
for i in range(n):
w.append(int(input()))
for i in range(m):
x, y = map(int, input().split())
lsm[x].append(y)
lsm[y].append(x)
print(lsm)
for i in range(q):
s = input()
x, y = map(int, s[2:].split())
if s[0] == "A":
ans = road(x-1, y-1)
print(ans)
else:
w[x-1] = y
i = 0
while i < TN:
solution()
i += 1
# inp.close()
# out.close()
``` | instruction | 0 | 11,159 | 1 | 22,318 |
No | output | 1 | 11,159 | 1 | 22,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cities in Cyberland, numbered from 1 to n, connected by m bidirectional roads. The j-th road connects city aj and bj.
For tourists, souvenirs are sold in every city of Cyberland. In particular, city i sell it at a price of wi.
Now there are q queries for you to handle. There are two types of queries:
* "C a w": The price in city a is changed to w.
* "A a b": Now a tourist will travel from city a to b. He will choose a route, he also doesn't want to visit a city twice. He will buy souvenirs at the city where the souvenirs are the cheapest (possibly exactly at city a or b). You should output the minimum possible price that he can buy the souvenirs during his travel.
More formally, we can define routes as follow:
* A route is a sequence of cities [x1, x2, ..., xk], where k is a certain positive integer.
* For any 1 β€ i < j β€ k, xi β xj.
* For any 1 β€ i < k, there is a road connecting xi and xi + 1.
* The minimum price of the route is min(wx1, wx2, ..., wxk).
* The required answer is the minimum value of the minimum prices of all valid routes from a to b.
Input
The first line of input contains three integers n, m, q (1 β€ n, m, q β€ 105), separated by a single space.
Next n lines contain integers wi (1 β€ wi β€ 109).
Next m lines contain pairs of space-separated integers aj and bj (1 β€ aj, bj β€ n, aj β bj).
It is guaranteed that there is at most one road connecting the same pair of cities. There is always at least one valid route between any two cities.
Next q lines each describe a query. The format is "C a w" or "A a b" (1 β€ a, b β€ n, 1 β€ w β€ 109).
Output
For each query of type "A", output the corresponding answer.
Examples
Input
3 3 3
1
2
3
1 2
2 3
1 3
A 2 3
C 1 5
A 2 3
Output
1
2
Input
7 9 4
1
2
3
4
5
6
7
1 2
2 5
1 5
2 3
3 4
2 4
5 6
6 7
5 7
A 2 3
A 6 4
A 6 7
A 3 3
Output
2
1
5
3
Note
For the second sample, an optimal routes are:
From 2 to 3 it is [2, 3].
From 6 to 4 it is [6, 5, 1, 2, 4].
From 6 to 7 it is [6, 5, 7].
From 3 to 3 it is [3].
<image>
Submitted Solution:
```
class Node():
def __init__(self,num,wei):
self.num=num
self.wei=wei
self.edges=[]
def add_edges(self,l):
self.edges.append(l)
def change_wei(self,wei):
self.wei=wei
def calc_paths(a,b,l,min,nodes,min_va):
find=0
if a.num==b.num:
find=1
if min> a.wei:
return a.wei, find
else:
return min, find
else:
if len(a.edges)>0:
l.append(a.num)
if a.wei<min:
min=a.wei
for i in a.edges:
if i not in l:
#l.append(i)
li=l.copy()
mi, fi=calc_paths(nodes[i],b,li,min,nodes,min_va)
if fi==1:
find=1
if mi==min_va:
min=mi
break
elif mi<min:
min=mi
if find==1:
return min,find
else:
return 10000000000,find
result=[]
find=0
nodes={}
n=input()
n=n.split()
equals=1
min_val=10000000000
for i in range (1,int(n[0])+1):
nodes[i]=Node(i,int(input()))
if i>1:
if nodes[i].wei != nodes[i-1].wei:
equals=0
if nodes[i].wei<min_val:
min_val=nodes[i].wei
for _ in range (0,int(n[1])):
p=input()
p=p.split()
nodes[int(p[0])].add_edges(int(p[1]))
nodes[int(p[1])].add_edges(int(p[0]))
for _ in range (0,int(n[2])):
q=input()
q=q.split()
if q[0]=='C':
nodes[int(q[1])].change_wei(int(q[2]))
else:
if equals==0:
resul,find=calc_paths(nodes[int(q[1])],nodes[int(q[2])],[],10000000000,nodes,min_val)
result.append(resul)
else:
result.append(nodes[1].wei)
for i in result:
print(i)
``` | instruction | 0 | 11,160 | 1 | 22,320 |
No | output | 1 | 11,160 | 1 | 22,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,273 | 1 | 22,546 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
M = lambda: map(int, input().split())
s, x1, x2 = M()
t1, t2 = M()
p, d = M()
v1, v2 = 1/t1, 1/t2
if p <= x1 <= x2 and d > 0:
path_by_tram = x2 - p
elif p <= x2 <= x1 and d > 0:
path_by_tram = s - p + s - x2
elif x1 <= p <= x2 and d > 0:
path_by_tram = 2 * s + x2 - p
elif x1 <= x2 <= p and d > 0:
path_by_tram = 2 * s - (p - x2)
elif x2 <= x1 <= p and d > 0:
path_by_tram = 2 * (s - p) + p - x2
elif x2 <= p <= x1 and d > 0:
path_by_tram = 2 * (s - p) + p - x2
elif p <= x1 <= x2 and d < 0:
path_by_tram = 2 * p + x2 - p
elif p <= x2 <= x1 and d < 0:
path_by_tram = 2 * s
elif x1 <= p <= x2 and d< 0:
path_by_tram = 2 * p + x2 - p
elif x1 <= x2 <= p and d < 0:
path_by_tram = p + x2
elif x2 <= x1 <= p and d < 0:
path_by_tram = p - x2
elif x2 <= p <= x1 and d< 0:
path_by_tram = 2 * s + p - x2
on_foot = abs(x2 - x1) / v2
print(int(min(round(path_by_tram/v1), on_foot)))
``` | output | 1 | 11,273 | 1 | 22,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,274 | 1 | 22,548 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
#!/usr/bin/python
from sys import argv,exit
def rstr():
return input()
def rint():
return int(input())
def rints():
return [int(i) for i in input().split(' ')]
def prnt(*args):
if '-v' in argv:
print(*args)
l1 = rints()
s = l1[0]
igor = l1[1]
dest = l1[2]
l2 = rints()
tspeed = l2[0]
ispeed = l2[1]
l3 = rints()
tpos = l3[0]
tdir = l3[1]
diff = abs(dest-igor)
itime = ispeed*diff
if tdir > 0:
tdir *= -1
igor = s-igor
dest = s-dest
tpos = s-tpos
if igor <= tpos and dest < igor:
prnt('1')
ttime = tspeed*abs(dest-tpos)
elif igor < tpos and dest > igor:
prnt('2')
ttime = tspeed*tpos + dest*tspeed
elif igor > tpos and dest > igor:
prnt('3')
ttime = tpos*tspeed + dest*tspeed
elif igor > tpos and dest < igor:
prnt('3')
ttime = tpos*tspeed + s*tspeed + (s-dest)*tspeed
elif igor >= tpos and dest > igor:
ttime = tspeed*tpos + tspeed*dest
else:
print('something has gone terribly wrong')
exit(0)
prnt('itime', itime, 'ttime', ttime)
print(min([itime, ttime]))
``` | output | 1 | 11,274 | 1 | 22,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,275 | 1 | 22,550 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
s,x1,x2 = map(int,input().split())
t1,t2 = map(int,input().split())
p,d = map(int,input().split())
paidal = abs(x2 - x1) * t2
if(t2 <= t1):
print(paidal)
else:
ans = 0
busAayi = 0
if(x1 > p):
if(d == 1):
ans += abs(x1 - p) * t1
else:
ans += abs(2*p + abs(p - x1)) * t1
d = 1
elif(x1 == p):
pass
else:
if(d == 1):
ans += abs(2*(s - p) + abs(p - x1)) * t1
d = -1
else:
ans += abs(x1 - p) * t1
if(x2 > x1):
if(d == 1):
ans += (x2 - x1) * t1
else:
ans += abs(2*x1 + abs(x1 - x2)) * t1
elif(x2 == x1):
pass
else:
if(d == 1):
ans += abs(2 * (s - x1) + abs(x1 - x2)) * t1
else:
ans += abs(x2 - x1) * t1
print(min(paidal, ans))
``` | output | 1 | 11,275 | 1 | 22,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,276 | 1 | 22,552 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
ans = abs(x1 - x2) * t2
if x1 == x2:
print(0)
elif x1 < x2:
if (d == 1 and p <= x1) or p == 0:
ans = min(ans, abs(x2 - p) * t1)
elif d == -1 or p == s:
ans = min(ans, (p + x2) * t1)
elif d == 1 and p > x1:
ans = min(ans, (s - p + s + x2) * t1)
else:
if (d == -1 and p >= x1) or p == s:
ans = min(ans, abs(p - x2) * t1)
elif d == 1 or p == 0:
ans = min(ans, (s - p + s - x2) * t1)
elif d == -1 and p < x1:
ans = min(ans, (p + s + s - x2) * t1)
print(ans)
``` | output | 1 | 11,276 | 1 | 22,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,277 | 1 | 22,554 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
s,x1,x2=input().split(' ')
s=int(s)
x1=int(x1)
x2=int(x2)
v1,v2=input().split(' ')
v1=int(v1)
v2=int(v2)
v1=1/v1
v2=1/v2
p,d=input().split(' ')
p=int(p)
d=int(d)
if x1>x2 :
x1=s-x1
x2=s-x2
d=-d
p=s-p
if p<=x1:
if d==-1:
x=p+x1
else:
x=x1-p
t=x/(v1-v2)
if x1+t*v2<=x2:
t=t+(x2-x1-t*v2)/v1
else:
t=(x2-x1)/v2
else:
if d==-1:
x=p-x1
else:
x=2*s-p-x1
t=x/(v1+v2)
if x1+t*v2<=x2:
t=min(t+(x2+x1+t*v2)/v1,(x2-x1)/v2)
else:
t=(x2-x1)/v2
print(int(t+0.5))
``` | output | 1 | 11,277 | 1 | 22,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,278 | 1 | 22,556 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
s, x1, x2 = map(int, input().split(' '))
t1, t2 = map(int, input().split(' '))
p, d = map(int, input().split(' '))
if x2 < x1:
x1 = s-x1
x2 = s-x2
p = s-p
d *= -1
t_walk = (x2-x1) * t2
extra = 0
if p > x1 and d == 1:
extra = 2*(s-p)
d = -1
p *= d
t_tram = (x2-p+extra) * t1
print(min(t_tram, t_walk))
``` | output | 1 | 11,278 | 1 | 22,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,279 | 1 | 22,558 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
tp = abs(x1 - x2) * t2
if p != x1:
v = False
else:
v = True
tt = 0
while 1:
if p == s:
d = -1
if p == 0:
d = 1
p += d
tt += t1
if p == x1:
v = True
if v and p == x2:
break
print(min(tp, tt))
``` | output | 1 | 11,279 | 1 | 22,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total. | instruction | 0 | 11,280 | 1 | 22,560 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
ans = abs(x1 - x2) * t2
if (x2 > x1):
d *= -1
p = s - p
x1 = s - x1
x2 = s - x2
if (d == -1):
if (p < x1):
ans = min(ans, (p + s + s - x2) * t1)
else:
ans = min(ans, (p - x2) * t1)
else:
ans = min(ans, (s - p + s - x2) * t1)
print(ans)
``` | output | 1 | 11,280 | 1 | 22,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
if x2 < x1:
x1 = (s - x1)
x2 = (s - x2)
p = (s - p)
d = -d
vt = 1.0 / t1
vi = 1.0 / t2
xt0 = 0.0
if d == -1:
xt0 = -p
elif p <= x1:
xt0 = p
else:
xt0 = -(s - p) - s
def solve(vt, xt0, vi, x1, x2):
t1 = (x1 - xt0) / (vt - vi)
t2 = (x2 - vi*t1 - x1) / vt
t3 = (x1 - xt0) / (vt + vi)
t4 = (x2 + vi*t3 - x1) / vt
return min((x2-x1) / vi, min(t1 + t2, t3 + t4))
if t2 <= t1:
print("%.0f" % ((x2 - x1) / vi))
else:
print("%.0f" % solve(vt, xt0, vi, x1, x2))
``` | instruction | 0 | 11,281 | 1 | 22,562 |
Yes | output | 1 | 11,281 | 1 | 22,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
res1 = t2 * abs(x2 - x1)
if d < 0:
x1, x2, p = s-x1, s-x2, s-p
if x2 < x1:
res2 = t1 * (2*s - p - x2)
elif x1 < p:
res2 = t1 * (x2 - p + 2*s)
else:
res2 = t1 * (x2 - p)
print(min(res1, res2))
``` | instruction | 0 | 11,282 | 1 | 22,564 |
Yes | output | 1 | 11,282 | 1 | 22,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
s,x1,x2 = map(int,input().split())
t1,t2 = map(int,input().split())
p,d = map(int,input().split())
if x1>x2:
d*=-1
p = s - p
x1 = s - x1
x2 = s - x2
ans = (x2-x1)*t2
if d==1 and x1<p:
ans = min(ans, (2*s - p + x2) * t1)
elif d==-1:
ans = min(ans, (p + x2) * t1);
else:
ans = min(ans, abs(p - x2) * t1);
print (ans)
``` | instruction | 0 | 11,283 | 1 | 22,566 |
Yes | output | 1 | 11,283 | 1 | 22,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
s, x1, x2 = [int(x) for x in input().split()]
t1, t2 = [int(x) for x in input().split()]
p, d = [int(x) for x in input().split()]
di = (x2 - x1 > 0) * 2 - 1
ti = abs(x2 - x1) * t2
if (d == di):
if ((p - x1) * d <= 0):
tt = (x2 - p) * d * t1
else:
tt = (2*s + (x2 - p)*d) * t1
else:
if (d == 1):
tt = (2*s - (p + x2)) * t1
else:
tt = (p + x2) * t1
T = min(ti, tt)
print(T)
``` | instruction | 0 | 11,284 | 1 | 22,568 |
Yes | output | 1 | 11,284 | 1 | 22,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
#/usr/bin/env python3
import sys
def tram(inp):
inp = list(map(int, inp.split()))
s = inp[0]
x1 = inp[1]
x2 = inp[2]
t1 = inp[3]
t2 = inp[4]
p = inp[5]
d = inp[6]
if d < 0:
x1 = s-x1
x2 = s-x2
p = s - p
walktime = abs(x1-x2)*t2
if (x2 > x1):
if (p > x1):
tramtime = (s-p + s + s-x2) * t1
else:
tramtime = (x2 - p) *t1
else:
tramtime = ((s-p) + s -x2) * t1
return min(walktime, tramtime)
if __name__ == "__main__":
inp = sys.stdin.read()
inp = inp.strip()
print(tram(inp))
``` | instruction | 0 | 11,285 | 1 | 22,570 |
No | output | 1 | 11,285 | 1 | 22,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
s, x1, x2 = [int(i) for i in input().split()]
t1, t2 = [int(i) for i in input().split()]
s1 = 1/t1
s2 = 1/t2
p, d = [int(i) for i in input().split()]
direct = abs(x1-x2)/s2
# if d * (x2-x1) < 0 :
if (d == 1 and p < x1 and x2-x1 < 0) or (d == 1 and p > x1 and x2 - x1 > 0):
# print('reversing')
p = p + abs(p-s)*2
t_meet = abs((p-x1)/(s2-s1))
# print(p, t_meet)
dist = s2 * t_meet
# print('distance is ', dist)
if x1 > x2:
pos = x1 - dist
else:
pos = x1 + dist
# print('pos is ', pos)
t_arrive = t_meet + abs(pos-x2) * s1
print(int(min(t_arrive, direct)))
# print(direct)
``` | instruction | 0 | 11,286 | 1 | 22,572 |
No | output | 1 | 11,286 | 1 | 22,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
import math
s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
T1 = t2 * abs(x2 - x1)
if d < -1:
x1, x2, p = s-x1, s-x2, s-p
d = 1
if x2 < x1:
T2 = t1 * (2*s - p - x2)
else:
T2 = t1 * (x2 - p + 2*s*(x1 < p))
print(min(T1, T2))
``` | instruction | 0 | 11,287 | 1 | 22,574 |
No | output | 1 | 11,287 | 1 | 22,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
Input
The first line contains three integers s, x1 and x2 (2 β€ s β€ 1000, 0 β€ x1, x2 β€ s, x1 β x2) β the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 β€ t1, t2 β€ 1000) β the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 β€ p β€ s - 1, d is either 1 or <image>) β the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Output
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
Examples
Input
4 2 4
3 4
1 1
Output
8
Input
5 4 0
1 2
3 1
Output
7
Note
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
Submitted Solution:
```
s, x1, x2 = map(int,input().split())
t1, t2 = map(int,input().split())
p, d = map(int,input().split())
ti = abs(x2 - x1) * t2
if d == 1:
if p > x2:
tp = (s - p + s - x2) * t1
else:
tp = (x2 - p) * t2
else:
if p > x2:
tp = (p - x2) * t1
else:
tp = (p + x2) *t1
if ti < tp:
print(ti)
else:
print(tp)
``` | instruction | 0 | 11,288 | 1 | 22,576 |
No | output | 1 | 11,288 | 1 | 22,577 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,041 | 1 | 24,082 |
Tags: greedy, implementation
Correct Solution:
```
n=int(input());x=list(map(int,input().split()))
for i in range(n):t=x[i];print(min(abs(t-x[i-1]),abs(x[i-n+1]-t)),max(t-x[0],x[n-1]-t))
``` | output | 1 | 12,041 | 1 | 24,083 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,042 | 1 | 24,084 |
Tags: greedy, implementation
Correct Solution:
```
n= int(input())
dis = list(map(int, input().split(" ")))
result = [0]*n
for i in range(n):
if i == 0:
minimum = abs(dis[0]-dis[1])
maximam = abs(dis[i] - dis[n-1])
elif i == n -1:
minimum = abs(dis[i]-dis[i-1])
maximam= abs(dis[i] - dis[0])
else:
maximam = max(abs(dis[i] - dis[n-1]),abs(dis[i]-dis[0]))
minimum = min(abs(dis[i]- dis[i+1]), abs(dis[i]-dis[i-1]))
result[i] = str(minimum)+' ' +str(maximam)+'\n'
print(''.join(result),end = '')
``` | output | 1 | 12,042 | 1 | 24,085 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,043 | 1 | 24,086 |
Tags: greedy, implementation
Correct Solution:
```
n = input()
locations = list(map(int, input().split()))
for idx, loc in enumerate(locations):
if idx == 0:
minimum = locations[1] - loc
maximum = locations[-1] - loc
elif idx == len(locations) - 1 :
minimum = loc - locations[-2]
maximum = loc - locations[0]
else:
minimum = min(abs(loc - locations[idx + 1]), abs(loc - locations[idx - 1]))
maximum = max(abs(loc - locations[-1]), abs(loc - locations[0]))
print(minimum, maximum)
``` | output | 1 | 12,043 | 1 | 24,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,044 | 1 | 24,088 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
lista = [int(x) for x in input().split()]
ult = n -1
for x in range(n):
if(x == 0):
min = lista[1] - lista[0]
max = lista[ult] - lista[0]
elif(x == ult):
min = lista[ult] - lista[ult - 1]
max = lista[ult] - lista[0]
else:
min = lista[x] - lista[x -1]
if (lista[x + 1] - lista[x] < min):
min = lista[x + 1] - lista[x]
max = lista[ult] - lista[x]
if (lista[x] - lista[0] > max):
max = lista[x] - lista[0]
print(min, " ", max)
``` | output | 1 | 12,044 | 1 | 24,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,045 | 1 | 24,090 |
Tags: greedy, implementation
Correct Solution:
```
x = int(input())
coord = list(map(int, input().split()))
for i in range(x):
max, min = 0,0
if(i == 0):
min = abs(coord[i] - coord[i+1])
max = abs(coord[i] - coord[x-1])
elif( i == x-1):
min = abs(coord[i] - coord[i-1])
max = abs(coord[i] - coord[0])
else:
min = abs(coord[i] - coord[i-1])
if(abs(coord[i] - coord[i+1] )< min):
min = abs(coord[i] - coord[i+1])
max = abs(coord[i] - coord[0])
if(abs(coord[i] - coord[x-1]) > max):
max = abs(coord[i] - coord[x-1])
print (min, "", max)
``` | output | 1 | 12,045 | 1 | 24,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,046 | 1 | 24,092 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
cities = list(map(int, input().split()))
ans = []
for i in range(n):
if i == 0:
maxi = abs(cities[-1] - cities[0])
mini = abs(cities[1] - cities[0])
elif i == n-1:
maxi = abs(cities[-1] - cities[0])
mini = abs(cities[-1] - cities[-2])
else:
min1 = abs(cities[i] - cities[i-1])
min2 = abs(cities[i] - cities[i+1])
if min1 < min2:
mini = min1
else:
mini = min2
max1 = abs(cities[i] - cities[0])
max2 = abs(cities[i] - cities[-1])
if max1 > max2:
maxi = max1
else:
maxi = max2
ans.append(mini)
ans.append(maxi)
for i in range(0, 2*n, 2):
print(str(ans[i]) + ' ' + str(ans[i+1]))
``` | output | 1 | 12,046 | 1 | 24,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,047 | 1 | 24,094 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
x = list(map(int, input().split()))
mincost = []
maxcost = []
mincost.append(x[1] - x[0])
maxcost.append(x[n - 1] - x[0])
for i in range(1, n - 1):
mincost.append(min(x[i] - x[i - 1], x[i + 1] - x[i]))
maxcost.append(max(x[i] - x[0], x[n - 1] - x[i]))
mincost.append(x[n - 1] - x[n - 2])
maxcost.append(x[n - 1] - x[0])
for i in range(0, n):
print (mincost[i], maxcost[i])
``` | output | 1 | 12,047 | 1 | 24,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2 | instruction | 0 | 12,048 | 1 | 24,096 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
c = list(map(int,input().split()))
for i in range(n):
c_max = max(abs(c[-1]-c[i]),abs(c[i]-c[0]))
c_min = 10**15
if (i != 0):
c_min = min(abs(c[i]-c[i-1]),c_min)
if (i != (n-1)):
c_min = min(abs(c[i+1]-c[i]),c_min)
print("%d %d"%(c_min,c_max))
``` | output | 1 | 12,048 | 1 | 24,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
def mail(n, lst):
b = list()
for i in range(n):
if i == 0:
b.append([lst[1] - lst[0], lst[n - 1] - lst[0]])
elif i == n - 1:
b.append([lst[n - 1] - lst[n - 2], lst[n - 1] - lst[0]])
else:
b.append([min(lst[i + 1] - lst[i], lst[i] - lst[i - 1]), max(lst[i] - lst[0], lst[n - 1] - lst[i])])
return b
m = int(input())
a = [int(j) for j in input().split()]
for elem in mail(m, a):
print(*elem)
``` | instruction | 0 | 12,049 | 1 | 24,098 |
Yes | output | 1 | 12,049 | 1 | 24,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n = int(input())
x = [int(i) for i in input().split()]
print(str(abs(x[0]-x[1]))+' '+str(abs(x[0]-x[n-1])))
for i in range(1, n-1):
mini = min(abs(x[i]-x[i-1]), abs(x[i]-x[i+1]))
maxi = max(abs(x[i]-x[0]), abs(x[i]-x[n-1]))
print(str(mini)+' '+str(maxi))
print(str(abs(x[n-1]-x[n-2]))+' '+str(abs(x[n-1]-x[0])))
``` | instruction | 0 | 12,050 | 1 | 24,100 |
Yes | output | 1 | 12,050 | 1 | 24,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n=int(input())
list1=list(map(int,input().strip().split(' ')))
print(list1[1]-list1[0],list1[-1]-list1[0])
for i in range(1,n-1):
print(min(list1[i+1]-list1[i],list1[i]-list1[i-1]),max(list1[i]-list1[0],list1[-1]-list1[i]))
print(list1[-1]-list1[-2],list1[-1]-list1[0])
``` | instruction | 0 | 12,051 | 1 | 24,102 |
Yes | output | 1 | 12,051 | 1 | 24,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n= int(input())
mas = list(map(int,input().split(" ")))
for i in range(len(mas)):
if i==0:
print(abs(mas[i]-mas[i+1]), abs(mas[i]-mas[-1]))
elif i==len(mas)-1:
print(abs(mas[i]-mas[i-1]), abs(mas[i]-mas[0]))
else:
print(min(abs(mas[i]-mas[i+1]),abs(mas[i]-mas[i-1]))
, max(abs(mas[i]-mas[-1]),abs(mas[i]-mas[0])))
``` | instruction | 0 | 12,052 | 1 | 24,104 |
Yes | output | 1 | 12,052 | 1 | 24,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
import math
def distance(a, b):
return int(math.fabs(a - b))
n = int(input())
line = [int(i) for i in input().split()]
for i in range(len(line)):
if(i == 0):
print(distance(line[i], line[i+1]), distance(line[i], line[-1]))
elif(i == n - 1):
print(distance(line[i], line[i-1]), distance(line[i], line[0]))
else:
previousElement = line[i-1]
current = line[i]
nextElement = line[i+1]
minimum = distance(previousElement, line[i])
if(distance(current, nextElement) < minimum):
minimum = line[i+1]
maximum = distance(current, line[0])
if(distance(current, line[-1]) > maximum):
maximum = distance(current, line[-1])
print(minimum, maximum)
``` | instruction | 0 | 12,053 | 1 | 24,106 |
No | output | 1 | 12,053 | 1 | 24,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n=int(input())
list1=list(map(int,input().split(" ")))
for i in range(0,n):
maxi=10**-9-1
mini=10**9+1
for j in range(0,n):
if i!=j:
maxi=max(maxi,abs(list1[i]-list1[j]))
mini=min(mini,abs(list1[i]-list1[j]))
print(mini,maxi)
``` | instruction | 0 | 12,054 | 1 | 24,108 |
No | output | 1 | 12,054 | 1 | 24,109 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.