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. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,915
1
189,830
Tags: binary search Correct Solution: ``` n=int(input()) x=[int(x) for x in input().split()] v=[int(x) for x in input().split()] def fin(h): return max(abs(h-x[i])/v[i] for i in range(n)) l,r=1.0,1e9 while r-l>5e-7: mid=(l+r)/2 if (fin(mid-4e-7)<fin(mid+4e-7)): r=mid else: l=mid print(fin(l)) ```
output
1
94,915
1
189,831
Provide tags and a correct Python 3 solution for this coding contest problem. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,916
1
189,832
Tags: binary search Correct Solution: ``` def f(t): a = (x[0] - v[0] * t) * 1.0 b = (x[n - 1] + v[n - 1] * t) * 1.0 for i in range(n): if x[i] - v[i] * t > a: a = x[i] - v[i] * t if x[i] + v[i] * t < b: b = x[i] + v[i] * t #print(a, b) return a <= b n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) inf = 1000000000.0 l = 0 r = inf while r - l > 1e-6: m = (l + r) / 2 if f(m): r = m else: l = m print(r) ```
output
1
94,916
1
189,833
Provide tags and a correct Python 3 solution for this coding contest problem. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,917
1
189,834
Tags: binary search Correct Solution: ``` from math import isclose n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) xx = list((x[i], v[i]) for i in range(n)) xx.sort() l, h = xx[0][0], xx[-1][0] m = (h + l) / 2 while not isclose(l, h): m = (h + l) / 2 t = abs(m - xx[0][0]) / xx[0][1] a, b = True, t for i in range(1, n): t2 = abs(m - xx[i][0]) / xx[i][1] if not isclose(t, t2): s = False if t2 > b: b = t2 a = bool(xx[i][0] < m) if a: h = m else: l = m print(max(abs(m - xx[i][0]) / xx[i][1] for i in range(n))) ```
output
1
94,917
1
189,835
Provide tags and a correct Python 3 solution for this coding contest problem. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,918
1
189,836
Tags: binary search Correct Solution: ``` from sys import stdin inp=stdin.readline n=int(inp()) d=[int(x) for x in inp().split()] v,big,small,t=[int(x) for x in inp().split()],max(d),min(d),0 while(big-small>10**-6): t=-1 mid=(big+small)/2 for i in range(n): if abs(d[i]-mid)/v[i]>t: t=abs(d[i]-mid)/v[i] x=d[i] if x>mid:small=mid else:big=mid print(t) ```
output
1
94,918
1
189,837
Provide tags and a correct Python 3 solution for this coding contest problem. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,919
1
189,838
Tags: binary search Correct Solution: ``` def main(n, x, v): eps = 1e-7 def f(p): nonlocal n, x, v t = 0.0 for i in range(n): t = max(t, abs(x[i] - p) / v[i]) return t low = 0 high = 1e9 while low + eps < high: mid = (high + low) / 2 midd = (mid + high) / 2 if f(mid) < f(midd): high = midd else: low = mid return f(low) print(main(int(input()), list(map(int, input().split(' '))), list(map(int, input().split(' '))))) ```
output
1
94,919
1
189,839
Provide tags and a correct Python 3 solution for this coding contest problem. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,920
1
189,840
Tags: binary search Correct Solution: ``` def check(f, speed, t): inter = (f[0] - speed[0] * t, f[0] + speed[0] * t) for i in range(1, len(f)): cur = (f[i] - speed[i] * t, f[i] + speed[i] * t) if cur[0] > inter[1] or inter[0] > cur[1]: return False else: inter = (max(cur[0], inter[0]), min(cur[1], inter[1])) return True def binsearch(fr, sp): inf = 0 sup = 10 ** 10 while sup - inf > 10 ** (-6): if check(fr, sp, (sup + inf) / 2): sup = (sup + inf) / 2 else: inf = (sup + inf) / 2 return inf if check(fr, sp, inf) else sup n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) print(binsearch(x, v)) ```
output
1
94,920
1
189,841
Provide tags and a correct Python 3 solution for this coding contest problem. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
instruction
0
94,921
1
189,842
Tags: binary search Correct Solution: ``` def inputIntegerArray(): return list( map( int, input().split(" ") ) ) def time( t, pos, speed ): maxleft = 0 minright = 1000000000 for i in range(0,len(pos)): distance = speed[i]*t left = pos[i]-distance right = pos[i]+distance maxleft = max( maxleft, left ) minright = min( minright, right ) if ( maxleft <= minright ): return True else: return False (n) = inputIntegerArray() pos = inputIntegerArray() speed = inputIntegerArray() left = 0.0 right = 1000000000.0 for i in range(0,64): m = left + ( right - left )/2; if ( time( m, pos, speed ) ): right = m else: left = m print ( left ) ```
output
1
94,921
1
189,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) l, r = 0, 10 ** 10 t = (l + r) / 2 while r - l >= 10 ** -6: t = (l + r) / 2 max_l = -float('inf') min_r = float('inf') for i in range(n): left = x[i] - v[i] * t right = x[i] + v[i] * t max_l = max(max_l, left) min_r = min(min_r, right) if max_l <= min_r: r = t else: l = t print(t) ```
instruction
0
94,922
1
189,844
Yes
output
1
94,922
1
189,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` import sys input = sys.stdin.readline def judge(t): L, R = -10**18, 10**18 for xi, vi in zip(x, v): L = max(L, xi-t*vi) R = min(R, xi+t*vi) return L<=R def binary_search(): l, r = 0, 10**10 while r-l>=1e-7: mid = (l+r)/2 if judge(mid): r = mid else: l = mid return l n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) print(binary_search()) ```
instruction
0
94,923
1
189,846
Yes
output
1
94,923
1
189,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` from sys import stdin inp=stdin.readline n=int(inp()) d=[int(x) for x in inp().split()] v,big,small,t,c=[int(x) for x in inp().split()],max(d),min(d),0,40 while(c): mid,c,t=(big+small)/2,c-1,-1 for i in range(n): if abs(d[i]-mid)/v[i]>t: t=abs(d[i]-mid)/v[i] x=d[i] if x>mid:small=mid else:big=mid print(t) ```
instruction
0
94,924
1
189,848
Yes
output
1
94,924
1
189,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) l = 0; r = 1e9 + 1 for _ in range(1000): m = (l + r) * 0.5 L = -2e9; R = 2e9 for i in range(n): L = max(L, x[i] - v[i] * m) R = min(R, x[i] + v[i] * m) if R >= L: r = m else: l = m print(round((l + r) / 2, 10)) ```
instruction
0
94,925
1
189,850
Yes
output
1
94,925
1
189,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` def solve(t,x,v): l=[x[i]-v[i]*t for i in range(len(x))] r=[x[i]+v[i]*t for i in range(len(x))] return 1 if max(l)<=min(r) else 0 n=int(input()) x=list(map(int,input().split())) v=list(map(int,input().split())) l=0 h=10**9 cnt=0 while l<h and cnt<100: mid=l+(h-l)/2 print(mid) cnt+=1 if solve(mid,x,v): h=mid else: l=mid print(l) ```
instruction
0
94,926
1
189,852
No
output
1
94,926
1
189,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` n, x, v = int(input()), list(map(int, input().split())), list(map(int, input().split())) def f(pos): res = 0 for i in range(n): res = max(res, abs(pos - x[i]) / v[i]) return res l, r, m1, m2 = 1, 1e9, 0, 0 for _ in range(60): ln = r - l m1 = l + ln / 3 m2 = r - ln / 3 if f(m1) < f(m2): r = m2 else: l = m1 print("%.12f" % f(l)) ```
instruction
0
94,927
1
189,854
No
output
1
94,927
1
189,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` n = int(input()) x = list(map(float, input().split())) v = list(map(float, input().split())) def f(x0): global x global v global n d = 0 for i in range(n): d = max(d, abs(x0 - x[i]) / v[i]) return d l = 0 r = max(x) for i in range(70): m1 = (l + l + r) / 3 m2 = (l + r + r) / 3 if (f(m1) >= f(m2)): l = m1 else: r = m2 print(f(l)) ```
instruction
0
94,928
1
189,856
No
output
1
94,928
1
189,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input The first line contains single integer n (2 ≀ n ≀ 60 000) β€” the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 109) β€” the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≀ vi ≀ 109) β€” the maximum speeds of the friends, in meters per second. Output Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if <image> holds. Examples Input 3 7 1 3 1 2 1 Output 2.000000000000 Input 4 5 10 3 2 2 3 2 4 Output 1.400000000000 Note In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. Submitted Solution: ``` # n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): from collections import Counter #from fractions import Fraction import math n=int(input()) dis=list(map(int,input().split())) v=list(map(int,input().split())) l=0 r=10**9+100 while r-l>=10**-7: t=(l+r)/2 l2=0 r2=10**9 for i in range(n): x,y=dis[i]-v[i]*t,dis[i]+v[i]*t l2=max(x,l2) r2=min(y,l2) if l2<=r2: r=t else: l=t print(l) ```
instruction
0
94,929
1
189,858
No
output
1
94,929
1
189,859
Provide tags and a correct Python 3 solution for this coding contest problem. You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest. The track's map is represented by a rectangle n Γ— m in size divided into squares. Each square is marked with a lowercase Latin letter (which means the type of the plot), with the exception of the starting square (it is marked with a capital Latin letters S) and the terminating square (it is marked with a capital Latin letter T). The time of movement from one square to another is equal to 1 minute. The time of movement within the cell can be neglected. We can move from the cell only to side-adjacent ones, but it is forbidden to go beyond the map edges. Also the following restriction is imposed on the path: it is not allowed to visit more than k different types of squares (squares of one type can be visited an infinite number of times). Squares marked with S and T have no type, so they are not counted. But S must be visited exactly once β€” at the very beginning, and T must be visited exactly once β€” at the very end. Your task is to find the path from the square S to the square T that takes minimum time. Among all shortest paths you should choose the lexicographically minimal one. When comparing paths you should lexicographically represent them as a sequence of characters, that is, of plot types. Input The first input line contains three integers n, m and k (1 ≀ n, m ≀ 50, nΒ·m β‰₯ 2, 1 ≀ k ≀ 4). Then n lines contain the map. Each line has the length of exactly m characters and consists of lowercase Latin letters and characters S and T. It is guaranteed that the map contains exactly one character S and exactly one character T. Pretest 12 is one of the maximal tests for this problem. Output If there is a path that satisfies the condition, print it as a sequence of letters β€” the plot types. Otherwise, print "-1" (without quotes). You shouldn't print the character S in the beginning and T in the end. Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted. Examples Input 5 3 2 Sba ccc aac ccc abT Output bcccc Input 3 4 1 Sxyy yxxx yyyT Output xxxx Input 1 3 3 TyS Output y Input 1 4 1 SxyT Output -1
instruction
0
94,958
1
189,916
Tags: graphs, greedy, shortest paths Correct Solution: ``` import sys from array import array # noqa: F401 from itertools import combinations from collections import deque def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, k = map(int, input().split()) chars = ( ['}' * (m + 2)] + ['}' + ''.join('{' if c == 'S' else '|' if c == 'T' else c for c in input().rstrip()) + '}' for _ in range(n)] + ['}' * (m + 2)] ) cbit = [[1 << (ord(c) - 97) for c in chars[i]] for i in range(n + 2)] si, sj, ti, tj = 0, 0, 0, 0 for i in range(1, n + 1): for j in range(1, m + 1): if chars[i][j] == '{': si, sj = i, j cbit[i][j] = 0 if chars[i][j] == '|': ti, tj = i, j ans = inf = '*' * (n * m) for comb in combinations([1 << i for i in range(26)], r=k): enabled = sum(comb) dp = [[inf] * (m + 2) for _ in range(n + 2)] dp[ti][tj] = '' dq = deque([(ti, tj, '')]) while dq: i, j, s = dq.popleft() if dp[i][j] < s: continue for di, dj in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)): if (cbit[di][dj] & enabled) != cbit[di][dj]: continue pre = chars[di][dj] if cbit[di][dj] else '' l = 1 if cbit[di][dj] else 0 if (len(dp[di][dj]) > len(s) + l or len(dp[di][dj]) == len(s) + l and dp[di][dj] > pre + s): dp[di][dj] = pre + s if l: dq.append((di, dj, pre + s)) if len(ans) > len(dp[si][sj]) or len(ans) == len(dp[si][sj]) and ans > dp[si][sj]: ans = dp[si][sj] print(ans if ans != inf else -1) ```
output
1
94,958
1
189,917
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,469
1
190,938
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` from heapq import heappop, heappush nodes, edges, capitalIndex = map(int, input().split()) adj = [dict() for i in range(nodes + 1)] visited = [False] * (nodes + 1) costList = [float("inf")] * (nodes + 1) costList[capitalIndex] = 0 for i in range(edges): start, end, dist = map(int, input().split()) adj[start][end] = min(adj[start].get(end, float("inf")), dist) adj[end][start] = adj[start][end] distanceToCapital = int(input()) # dijkstra pq = [] counter = 0 heappush(pq, (0, counter, capitalIndex)) counter += 1 while pq: cost, count, index = heappop(pq) if not visited[index]: visited[index] = True for nextIndex, nextCost in adj[index].items(): totalCost = cost + nextCost if not visited[nextIndex] and totalCost < costList[nextIndex]: costList[nextIndex] = totalCost heappush(pq, (totalCost, counter, nextIndex)) counter += 1 # is there a silo on the city? silos = costList.count(distanceToCapital) # is there an edge containing a silo? for start in range(len(adj)): costStart = costList[start] for end, costEdge in adj[start].items(): totalCost = costStart + costEdge # make sure capitalDistance is between road if(costStart < distanceToCapital < totalCost): roadTraveled = distanceToCapital - costStart roadLeft = totalCost - distanceToCapital # make sure path from end to road isn't shorter so this is indeed shortest path if distanceToCapital <= costList[end] + roadLeft: silos += 1 # make sure we aren't double counting silos in the middle if distanceToCapital == costList[end] + roadLeft: silos -= start > end print(silos) ```
output
1
95,469
1
190,939
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,470
1
190,940
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` n, m, s = map(int, input().split()) p = [[] for i in range(n + 1)] for i in range(m): u, v, w = map(int, input().split()) p[u].append((v, w)) p[v].append((u, w)) l = int(input()) t = [l + 1] * (n + 1) t[s], q = 0, {s} while q: u = q.pop() r = t[u] for v, w in p[u]: if r + w < t[v]: q.add(v) t[v] = r + w s, r = 0, 2 * l for u in range(1, n + 1): d = t[u] if d < l: for v, w in p[u]: if d + w > l and (t[v] + d + w > r or (u < v and t[v] + d + w == r)): s += 1 elif d == l: s += 1 print(s) # Made By Mostafa_Khaled ```
output
1
95,470
1
190,941
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,471
1
190,942
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` from heapq import heappush, heappop def iin(): return (map(int, input().split())) nodes, edges, start = iin() start -= 1 graph = [[] for x in range(nodes)] edge_list = [] shortpath = [float('inf') for x in range(nodes)] for x in range(edges): left, right, cost = iin() left -= 1; right -= 1 graph[left].append((right, cost)) graph[right].append((left, cost)) edge_list.append((left, right, cost)) l, = iin() pq = [(0, start)] while pq: path_cost, node = heappop(pq) if shortpath[node] < path_cost: continue shortpath[node] = path_cost for adj, cost in graph[node]: if path_cost + cost < shortpath[adj]: heappush(pq, (path_cost + cost, adj)) silos = 0 for p in shortpath: silos += 0 if p != l else 1 for left, right, cost in edge_list: if shortpath[left] < l and shortpath[left] + cost > l: silos += 1 if shortpath[right] + (cost - (l-shortpath[left])) >= shortpath[left] + (l-shortpath[left]) else 0 if shortpath[right] < l and shortpath[right] + cost > l: silos += 1 if shortpath[left] + (cost - (l-shortpath[right])) > shortpath[right] + (l-shortpath[right]) else 0 print(silos) ```
output
1
95,471
1
190,943
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,472
1
190,944
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` from heapq import heappush, heappop def i_in(): return (map(int, input().split())) nodes, edges, start = i_in() start -= 1 graph = [[] for x in range(nodes)] edge_list = [] shortest_path = [float('inf') for x in range(nodes)] for x in range(edges): left, right, cost = i_in() left -= 1; right -= 1 graph[left].append((right, cost)) graph[right].append((left, cost)) edge_list.append((left, right, cost)) l, = i_in() pq = [(0, start)] while pq: path_cost, node = heappop(pq) if shortest_path[node] < path_cost: continue shortest_path[node] = path_cost for adj, cost in graph[node]: if cost + path_cost < shortest_path[adj]: shortest_path[adj] = cost + path_cost heappush(pq, (shortest_path[adj], adj)) silos = 0 for p in shortest_path: silos += 1 if p == l else 0 for left, right, cost in edge_list: if shortest_path[left] < l and shortest_path[left] + cost > l: silo_dist = l - shortest_path[left] silos += 1 if shortest_path[right] + (cost - silo_dist) >= shortest_path[left] + silo_dist else 0 if shortest_path[right] < l and shortest_path[right] + cost > l: silo_dist = l - shortest_path[right] silos += 1 if shortest_path[left] + (cost - silo_dist) > shortest_path[right] + silo_dist else 0 print(silos) ```
output
1
95,472
1
190,945
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,473
1
190,946
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` import sys n,m,s=map(int,sys.stdin.readline().split()) p=[[] for i in range(n+1)] for i in range(m): u, v, w = map(int, input().split()) p[u].append((v, w)) p[v].append((u, w)) l = int(input()) t = [l + 1] * (n + 1) t[s], q = 0, {s} while q: u = q.pop() r = t[u] for v, w in p[u]: if r + w < t[v]: q.add(v) t[v] = r + w s, r = 0, 2 * l for u in range(1,n+1): d=t[u] if d < l: for v, w in p[u]: if d + w > l and (t[v] + d + w > r or (u < v and t[v] + d + w == r)): s += 1 elif d == l: s += 1 print(s) ```
output
1
95,473
1
190,947
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,474
1
190,948
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` import sys n,m,s=map(int,sys.stdin.readline().split()) p=[[] for i in range(n+1)] for i in range(m): u, v, w = map(int, input().split()) p[u].append((v, w)) p[v].append((u, w)) l = int(sys.stdin.readline()) t = [l + 1] * (n + 1) t[s], q = 0, {s} while q: u = q.pop() r = t[u] for v, w in p[u]: if r + w < t[v]: q.add(v) t[v] = r + w s, r = 0, 2 * l for u in range(1,n+1): d=t[u] if d < l: for v, w in p[u]: if d + w > l and (t[v] + d + w > r or (u < v and t[v] + d + w == r)): s += 1 elif d == l: s += 1 print(s) ```
output
1
95,474
1
190,949
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,475
1
190,950
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` from sys import stdin from heapq import heappush, heappop INF = 2 * 10 ** 9 def dijkstra(graph, n, s): d = [INF] * n d[s] = 0 # class VertexIndex(int): # def __cmp__(self, other): # return cmp(d[self], d[other]) q = [] heappush(q, (0, s)) while q: tmp_d, v = heappop(q) dv = d[v] if tmp_d != dv: continue for to, w in graph[v]: if dv + w < d[to]: d[to] = dv + w heappush(q, (d[to], to)) return d def main(): next_line = stdin.readline n, m, s = map(int, next_line().split()) s -= 1 graph = [[] for _ in range(n)] def init(i): line = next_line().split() v = int(line[0]) - 1 u = int(line[1]) - 1 w = int(line[2]) graph[v].append([u, w]) graph[u].append([v, w]) return v, u, w edges = list(map(init, range(m))) # for i in range(m): # line = next_line().split() # v = int(line[0]) - 1 # u = int(line[1]) - 1 # w = int(line[2]) # graph[v].append([u, w]) # graph[u].append([v, w]) # edges[i] = (v, u, w) l = int(next_line()) ds = dijkstra(graph, n, s) def calc(edge): v, u, w = edge dv = ds[v] du = ds[u] res = 0 if dv < l < dv + w and du + w - (l - dv) > l: res += 1 if du < l < du + w and dv + w - (l - du) > l: res += 1 if dv < l and du < l and dv + du + w == 2 * l: res += 1 return res res = sum(d == l for d in ds) + sum(map(calc, edges)) print(res) if __name__ == '__main__': main() ```
output
1
95,475
1
190,951
Provide tags and a correct Python 3 solution for this coding contest problem. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
instruction
0
95,476
1
190,952
Tags: data structures, dfs and similar, graphs, shortest paths Correct Solution: ``` from heapq import heappush, heappop def i_in(): return (map(int, input().split())) nodes, edges, start = i_in() start -= 1 graph = [[] for x in range(nodes)] edge_list = [] shortest_path = [float('inf') for x in range(nodes)] for x in range(edges): left, right, cost = i_in() left -= 1; right -= 1 graph[left].append((right, cost)) graph[right].append((left, cost)) edge_list.append((left, right, cost)) l, = i_in() pq = [(0, start)] while pq: path_cost, node = heappop(pq) if shortest_path[node] < path_cost: continue shortest_path[node] = path_cost for adj, cost in graph[node]: if cost + path_cost < shortest_path[adj]: shortest_path[adj] = cost + path_cost heappush(pq, (shortest_path[adj], adj)) silos = 0 for p in shortest_path: silos += 1 if p == l else 0 for left, right, cost in edge_list: if shortest_path[left] < l and shortest_path[left] + cost > l: silo_dist = l - shortest_path[left] silos += 1 if shortest_path[right] + (cost - silo_dist) >= l else 0 if shortest_path[right] < l and shortest_path[right] + cost > l: silo_dist = l - shortest_path[right] silos += 1 if shortest_path[left] + (cost - silo_dist) > l else 0 print(silos) ```
output
1
95,476
1
190,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from sys import stdin from heapq import heappush, heappop INF = 2 * 10 ** 9 def dijkstra(graph, n, s): d = [INF] * n d[s] = 0 # class VertexIndex(int): # def __cmp__(self, other): # return cmp(d[self], d[other]) q = [] heappush(q, (0, s)) while q: tmp_d, v = heappop(q) dv = d[v] if tmp_d != dv: continue for to, w in graph[v]: if dv + w < d[to]: d[to] = dv + w heappush(q, (d[to], to)) return d def main(): next_line = stdin.readline n, m, s = map(int, next_line().split()) s -= 1 edges = [None] * m graph = [[] for _ in range(n)] for i in range(m): line = next_line().split() v = int(line[0]) - 1 u = int(line[1]) - 1 w = int(line[2]) graph[v].append([u, w]) graph[u].append([v, w]) edges[i] = (v, u, w) l = int(next_line()) ds = dijkstra(graph, n, s) # res = 0 # for v, u, w in edges: # dv = ds[v] # du = ds[u] # if dv < l < dv + w and du + w - (l - dv) > l: # res += 1 # if du < l < du + w and dv + w - (l - du) > l: # res += 1 # if dv < l and du < l and dv + du + w == 2 * l: # res += 1 def is_satisfies(edge): v, u, w = edge dv = ds[v] du = ds[u] res = 0 if dv < l < dv + w and du + w - (l - dv) > l: res += 1 if du < l < du + w and dv + w - (l - du) > l: res += 1 if dv < l and du < l and dv + du + w == 2 * l: res += 1 return res res = sum(d == l for d in ds) + sum(map(is_satisfies, edges)) print(res) if __name__ == '__main__': main() ```
instruction
0
95,477
1
190,954
Yes
output
1
95,477
1
190,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from heapq import heappush, heappop def get_graph_from_input(m): G = {} for _ in range(m): u, v, w = input().split() w = int(w) if not u in G: G[u] = {} if not v in G: G[v] = {} G[u][v] = w G[v][u] = w return G def get_num_missile_silos(G, l, s): min_distance = {} road_nodes = {} q = [(0, s)] while(q): dist, node = heappop(q) if not node in min_distance: min_distance[node] = dist else: continue if not '.' in node: for neighbor in G[node]: w = G[node][neighbor] new_dist = dist + w if dist < l and new_dist > l: dist_to_silo = l - dist min_node, max_node = min(neighbor, node), max(neighbor, node) if min_node != node: dist_to_silo = w - dist_to_silo road_silo = (min_node, max_node) if not road_silo in min_distance: min_distance[road_silo] = set([]) min_distance[road_silo].add(dist_to_silo) if new_dist <= l and not neighbor in min_distance: heappush(q, (dist + w, neighbor)) silos = 0 for node in min_distance: if type(node) is tuple: u, v = node if not u in min_distance or not v in min_distance or ((min_distance[u] + min_distance[v] + G[u][v]) >= 2 * l): silos += len(min_distance[node]) else: if min_distance[node] == l: silos += 1 return silos if __name__ == "__main__": n, m, s = map(int, input().split()) G = get_graph_from_input(m) l = int(input()) print(get_num_missile_silos(G, l, str(s))) ```
instruction
0
95,478
1
190,956
Yes
output
1
95,478
1
190,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from heapq import * from sys import stdin if __name__ == '__main__': V, E, start = map(int, stdin.readline().rstrip().split()) start -= 1 adj_list = [] for v in range(0, V): adj_list.append({}) shortest_dist = [] for e in range(0, E): v1, v2, length = map(int, stdin.readline().rstrip().split()) adj_list[v1 - 1][v2 - 1] = length adj_list[v2 - 1][v1 - 1] = length goal_dist = int(stdin.readline().rstrip()) heapq = [] shortest_dist = [100000000] * V shortest_dist[start] = 0 seen = [False] * V heappush(heapq, (0, start)) while heapq: (dist, v1) = heappop(heapq) if not seen[v1]: seen[v1] = True neighbors = adj_list[v1] to_change = [] for v2, length in neighbors.items(): if not seen[v2]: new_dist = length + dist if dist < goal_dist < new_dist: length1 = goal_dist - dist to_change.append((V, v2, length1)) length2 = new_dist - goal_dist neighbors2 = adj_list[v2] neighbors2[V] = length2 del neighbors2[v1] adj_list.append({v1: length1, v2: length2}) seen.append(False) shortest_dist.append(100000000) v2 = V new_dist = goal_dist V += 1 if shortest_dist[v2] > new_dist: shortest_dist[v2] = new_dist heappush(heapq, (new_dist, v2)) for (v_add, v_remove, length) in to_change: del neighbors[v_remove] neighbors[v_add] = length # print(shortest_dist) count = 0 for sd in shortest_dist: if sd == goal_dist: count += 1 print(count) # print(adj_list) ```
instruction
0
95,479
1
190,958
Yes
output
1
95,479
1
190,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from sys import stdin from heapq import heappush, heappop INF = 2 * 10 ** 9 def dijkstra(graph, n, s): d = [INF] * n d[s] = 0 # class VertexIndex(int): # def __cmp__(self, other): # return cmp(d[self], d[other]) q = [] heappush(q, (0, s)) while q: tmp_d, v = heappop(q) dv = d[v] if tmp_d != dv: continue graph_v = graph[v] for to, w in graph_v: if dv + w < d[to]: d[to] = dv + w heappush(q, (d[to], to)) return d def main(): next_line = stdin.readline n, m, s = map(int, next_line().split()) s -= 1 graph = [[] for _ in range(n)] def init(i): line = next_line().split() v = int(line[0]) - 1 u = int(line[1]) - 1 w = int(line[2]) graph[v].append([u, w]) graph[u].append([v, w]) return v, u, w edges = list(map(init, range(m))) # for i in range(m): # line = next_line().split() # v = int(line[0]) - 1 # u = int(line[1]) - 1 # w = int(line[2]) # graph[v].append([u, w]) # graph[u].append([v, w]) # edges[i] = (v, u, w) l = int(next_line()) ds = dijkstra(graph, n, s) def calc(edge): v, u, w = edge dv = ds[v] du = ds[u] res = 0 if dv < l < dv + w and du + w - (l - dv) > l: res += 1 if du < l < du + w and dv + w - (l - du) > l: res += 1 if dv < l and du < l and dv + du + w == 2 * l: res += 1 return res res = sum(d == l for d in ds) + sum(map(calc, edges)) print(res) if __name__ == '__main__': main() ```
instruction
0
95,480
1
190,960
Yes
output
1
95,480
1
190,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from sys import stdin from heapq import heappush, heappop INF = 2 * 10 ** 9 def dijkstra(graph, n, s): d = [INF] * n d[s] = 0 class VertexIndex(int): def __lt__(self, other): return d[self] < d[other] q = [] heappush(q, VertexIndex(s)) used = [False] * n while q: v = heappop(q) dv = d[v] if used[v]: continue used[v] = True graph_v = graph[v] for to, w in graph_v: if dv + w < d[to]: d[to] = dv + w heappush(q, VertexIndex(to)) return d def main(): next_line = stdin.readline n, m, s = map(int, next_line().split()) s -= 1 graph = [[] for _ in range(n)] def init(i): line = next_line().split() v = int(line[0]) - 1 u = int(line[1]) - 1 w = int(line[2]) graph[v].append([u, w]) graph[u].append([v, w]) return v, u, w edges = list(map(init, range(m))) l = int(next_line()) ds = dijkstra(graph, n, s) def calc(edge): v, u, w = edge dv = ds[v] du = ds[u] res = 0 if dv < l < dv + w and du + w - (l - dv) > l: res += 1 if du < l < du + w and dv + w - (l - du) > l: res += 1 if dv < l and du < l and dv + du + w == 2 * l: res += 1 return res res = sum(d == l for d in ds) + sum(map(calc, edges)) print(res) if __name__ == '__main__': main() ```
instruction
0
95,481
1
190,962
No
output
1
95,481
1
190,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` import sys import heapq from sys import stdin, stdout n, m, inizio = [int(x) for x in (stdin.readline().split())] inizio = inizio - 1 grafo = [] dist = [] for i in range(n): grafo.append([]) dist.append(sys.maxsize) for i in range(m): da, a, peso = [int(x) for x in (stdin.readline().split())] da = da - 1 a = a - 1 grafo[da].append([peso,a, False]) grafo[a].append([peso,da, False]) for i in range(n): grafo[i].sort() dist[inizio] = 0 h = [] count = 1 heapq.heappush(h, (0, inizio, -1, -1)) l = int(stdin.readline()) tot = 0 while count != 0: gianni = heapq.heappop(h) count = count - 1 if gianni[2]!=-1 and grafo[gianni[3]][gianni[2]][2] == False: grafo[gianni[3]][gianni[2]][2] = True if gianni[0] >= l: tot = tot + 1 if gianni[0] == dist[gianni[1]]: for i in range(len(grafo[gianni[1]])): adj = grafo[gianni[1]][i] if adj[0]+gianni[0] < dist[adj[1]]: dist[adj[1]] = adj[0]+gianni[0] heapq.heappush(h, (dist[adj[1]], adj[1], i, gianni[1])) count = count + 1 stdout.write(str(tot)) ```
instruction
0
95,482
1
190,964
No
output
1
95,482
1
190,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from heapq import heappush, heappop def get_graph_from_input(m): G = {} for _ in range(m): u, v, w = input().split() w = int(w) if not u in G: G[u] = {} if not v in G: G[v] = {} G[u][v] = w G[v][u] = w return G def get_num_missile_silos(G, l, s): min_distance = {} q = [(0, s)] while(q): dist, node = heappop(q) if not node in min_distance: min_distance[node] = dist else: continue if not '.' in node: for neighbor in G[node]: w = G[node][neighbor] new_dist = dist + w if dist < l and new_dist > l: dist_to_silo = l - dist min_node, max_node = min(neighbor, node), max(neighbor, node) if min_node != node: dist_to_silo = w - dist_to_silo road_silo = f"{min_node}.{max_node}.{dist_to_silo}" if not road_silo in min_distance: min_distance[road_silo] = l if new_dist <= l and not neighbor in min_distance: heappush(q, (dist + w, neighbor)) return sum(min_distance[k] == l for k in min_distance) if __name__ == "__main__": n, m, s = map(int, input().split()) G = get_graph_from_input(m) l = int(input()) print(get_num_missile_silos(G, l, str(s))) ```
instruction
0
95,483
1
190,966
No
output
1
95,483
1
190,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s. The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l. Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob. Input The first line contains three integers n, m and s (2 ≀ n ≀ 105, <image>, 1 ≀ s ≀ n) β€” the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≀ vi, ui ≀ n, vi β‰  ui, 1 ≀ wi ≀ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≀ l ≀ 109) β€” the distance from the capital to the missile silos. It is guaranteed that: * between any two cities no more than one road exists; * each road connects two different cities; * from each city there is at least one way to any other city by the roads. Output Print the single number β€” the number of Super Duper Secret Missile Silos that are located in Berland. Examples Input 4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2 Output 3 Input 5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4 Output 3 Note In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3). In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4. Submitted Solution: ``` from heapq import heappush, heappop def get_graph_from_input(m): G = {} for _ in range(m): u, v, w = input().split() w = int(w) if not u in G: G[u] = {} if not v in G: G[v] = {} G[u][v] = w G[v][u] = w return G def get_num_missile_silos(G, l, s): min_distance = {} q = [(0, s)] while(q): dist, node = heappop(q) if not node in min_distance: min_distance[node] = dist if not '.' in node: for neighbor in G[node]: w = G[node][neighbor] new_dist = dist + w if dist < l and new_dist > l: dist_to_silo = l - dist if min(neighbor, node) != node: dist_to_silo = w - dist_to_silo road_silo = f"{min(int(neighbor), int(node))}.{max(int(neighbor), int(node))}.{dist_to_silo}" if not road_silo in min_distance: min_distance[road_silo] = l if new_dist <= l and not neighbor in min_distance: heappush(q, (dist + w, neighbor)) return sum(min_distance[k] == l for k in min_distance) if __name__ == "__main__": n, m, s = map(int, input().split()) G = get_graph_from_input(m) l = int(input()) print(get_num_missile_silos(G, l, str(s))) ```
instruction
0
95,484
1
190,968
No
output
1
95,484
1
190,969
Provide tags and a correct Python 3 solution for this coding contest problem. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
instruction
0
95,785
1
191,570
Tags: greedy Correct Solution: ``` """ Author - Satwik Tiwari . 15th Dec , 2020 - Tuesday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from functools import cmp_to_key # from itertools import * from heapq import * from math import gcd, factorial,floor,ceil,sqrt from copy import deepcopy from collections import deque from bisect import bisect_left as bl from bisect import bisect_right as br from bisect import bisect #============================================================================================== #fast I/O region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) # def graph(vertex): return [[] for i in range(0,vertex+1)] def testcase(t): for pp in range(t): solve(pp) def google(p): print('Case #'+str(p)+': ',end='') def lcm(a,b): return (a*b)//gcd(a,b) def power(x, y, p) : y%=(p-1) #not so sure about this. used when y>p-1. if p is prime. res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True inf = pow(10,20) mod = 10**9+7 #=============================================================================================== # code here ;)) def safe(x,y): global n,m return (0<=x<n and 0<=y<m) def solve(case): n,k = sep() a = lis() if(k >= n): h = [] ans = 0 order = [0]*n for i in range(n): ans += (k-i)*a[i] # print(ans) h = [] for i in range(n): heappush(h,(-a[i],i)) temp = heappop(h) order[temp[1]] = k for i in range(n-1): temp,j = heappop(h) temp*=-1 ans += (i+1)*temp order[j] = k+i+1 print(ans) print(' '.join(str(order[i]+1) for i in range(len(order)))) else: ans = 0 for i in range(k+1): ans += (k-i)*a[i] h = [] sum = 0 for i in range(k+1): heappush(h,(-a[i],i)) sum += a[i] order = [0]*n for i in range(k,k+n): temp,j = heappop(h) sum+=temp ans += sum order[j] = i if(i+1 < n): heappush(h,(-a[i+1],i+1)) sum += a[i+1] print(ans) print(' '.join(str(order[i]+1) for i in range(len(order)))) # chck = 0 # for i in range(n): # chck += (order[i]-i)*a[i] # # print(chck) # print(chck) n,m = 0,0 testcase(1) # testcase(int(inp())) ```
output
1
95,785
1
191,571
Provide tags and a correct Python 3 solution for this coding contest problem. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
instruction
0
95,786
1
191,572
Tags: greedy Correct Solution: ``` import heapq n,k = map(int,input().split()) l = list(map(int,input().split())) ans = [0]*n h = [] for i in range(k): h.append((-1*l[i],i)) heapq.heapify(h) som = 0 for i in range(k,n+k): if i < n: heapq.heappush(h, (-1 * l[i], i)) x = heapq.heappop(h) s = -1*x[0]*(i-x[1]) som += s ans[x[1]] = i+1 print(som) print(*ans) ```
output
1
95,786
1
191,573
Provide tags and a correct Python 3 solution for this coding contest problem. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
instruction
0
95,787
1
191,574
Tags: greedy Correct Solution: ``` from heapq import heappush, heappop, heapify n, k = map(int, input().split()) a = list(map(int, input().split())) q = [(-a[i], i) for i in range(k)] heapify(q) res, s = [0] * n, 0 for i in range(k, n): heappush(q, (-a[i], i)) x, j = heappop(q) s -= x * (i-j) res[j] = i+1 for i in range(n, n+k): x, j = heappop(q) s -= x * (i-j) res[j] = i+1 print(s) print(*res) ```
output
1
95,787
1
191,575
Provide tags and a correct Python 3 solution for this coding contest problem. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
instruction
0
95,788
1
191,576
Tags: greedy Correct Solution: ``` from heapq import heappush,heappop,heapify n,k=map(int,input().split()) *l,=map(int,input().split()) q=[(-l[i],i)for i in range(k)] heapify(q) a=[0]*n s=0 for i in range(k,n) : heappush(q,(-l[i],i)) x,j=heappop(q) s-=x*(i-j) a[j]=i+1 for i in range(n,n+k) : x,j=heappop(q) s-=x*(i-j) a[j]=i+1 print(s) print(' '.join(map(str,a))) ```
output
1
95,788
1
191,577
Provide tags and a correct Python 3 solution for this coding contest problem. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
instruction
0
95,789
1
191,578
Tags: greedy Correct Solution: ``` from heapq import heappush,heappop,heapify n,k=map(int,input().split()) *l,=map(int,input().split()) q=[(-l[i],i)for i in range(k)];heapify(q) a=[0]*n s=0 for i in range(k,n): heappush(q,(-l[i],i)) x,j=heappop(q) s-=x*(i-j) a[j]=i+1 for i in range(n,n+k): x,j=heappop(q) s-=x*(i-j) a[j]=i+1 print(s) print(' '.join(map(str,a))) ```
output
1
95,789
1
191,579
Provide tags and a correct Python 3 solution for this coding contest problem. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
instruction
0
95,790
1
191,580
Tags: greedy Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- from heapq import heappush, heappop, heapify n, k = map(int, input().split()) a = list(map(int, input().split())) q = [(-a[i], i) for i in range(k)] heapify(q) res, s = [0] * n, 0 for i in range(k, n): heappush(q, (-a[i], i)) x, j = heappop(q) s -= x * (i-j) res[j] = i+1 for i in range(n, n+k): x, j = heappop(q) s -= x * (i-j) res[j] = i+1 print(s) print(*res) ```
output
1
95,790
1
191,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 107), here ci is the cost of delaying the i-th flight for one minute. Output The first line must contain the minimum possible total cost of delaying the flights. The second line must contain n different integers t1, t2, ..., tn (k + 1 ≀ ti ≀ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them. Example Input 5 2 4 2 1 10 2 Output 20 3 6 7 4 5 Note Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles. Submitted Solution: ``` import sys n,m=map(int,input().split()) l=list(map(int,sys.stdin.readline()[:-1].split())) out=[0 for i in range(n)] l1=[[l[i],i+1] for i in range(n)] l1=sorted(l1,key=lambda x:x[0]) p=0 d=set() for i in range(n-1,-1,-1) : v=max(1+m,l1[i][1]) if v not in d : out[l1[i][1]-1]=v d.add(v) p=max(p,v) else : p+=1 out[l1[i][1]-1]=p d.add(p) k=0 for i in range(n) : k+=l[i]*(out[i]-i-1) print(k) sys.stdout.write(' '.join(map(str,out))) ```
instruction
0
95,791
1
191,582
No
output
1
95,791
1
191,583
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,041
1
192,082
"Correct Solution: ``` a,b,c = map(int,input().split()) lst = [] ans = 0 cnt = 0 while True: s = (60*cnt+c) % (a+b) if s in lst: ans = -1 break lst.append(s) if 0 <= s <= a: ans = 60 * cnt + c break cnt += 1 print(ans) ```
output
1
96,041
1
192,083
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,042
1
192,084
"Correct Solution: ``` a, b, c = map(int, input().split()) now = 0 used = [False] * 60 while True: sleep_start = now + a if now % 60 < sleep_start % 60: if now % 60 <= c <= sleep_start % 60: print(now // 60 * 60 + c) break now = sleep_start + b else: if now % 60 <= c < 60 or 0 < c <= sleep_start % 60: print(now // 60 * 60 + c) break now = sleep_start + b if now % 60 == 0: print(-1) break ```
output
1
96,042
1
192,085
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,043
1
192,086
"Correct Solution: ``` def solve(a, b, c): l = 0; r = a; for t in range(514): t = l // 60 p = 60*t + c if l <= p <= r: print(p) exit() l = r + b r = l + a print(-1) a, b, c = map(int, input().split()) solve(a,b,c) ```
output
1
96,043
1
192,087
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,044
1
192,088
"Correct Solution: ``` a, b, c = map(int, input().split()) passed = set() time = 0 while True: if time % 60 <= c <= time % 60 + a: print(c + time // 60 * 60) break else: time += a + b if time % 60 in passed: print(-1) break else: passed.add(time % 60) ```
output
1
96,044
1
192,089
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,045
1
192,090
"Correct Solution: ``` a,b,c=map(int, input().split()) d=0 for _ in range(60): if c<=d+a: print(c) break d+=a+b while c<=d:c+=60 else: print(-1) ```
output
1
96,045
1
192,091
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,046
1
192,092
"Correct Solution: ``` import sys A,B,C = map(int,input().split()) time = 0 ss = set() while True: if time%60 == C: print(time) sys.exit() for t in range(A): time += 1 if time%60 == C: print(time) sys.exit() time += B if (time%60) in ss: break ss.add(time%60) print(-1) ```
output
1
96,046
1
192,093
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,047
1
192,094
"Correct Solution: ``` A, B, C = map(int, input().split()) t = 0 while True: t += A if t >= C: print(C) break t += B if t > C: C += 60 if t > 1000000: print(-1) break ```
output
1
96,047
1
192,095
Provide a correct Python 3 solution for this coding contest problem. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1
instruction
0
96,048
1
192,096
"Correct Solution: ``` a, b, c = map(int, input().split()) l = 0; r = a; for i in range(80): t = l // 60 p = 60*t + c if l <= p <= r: print(p) exit() l = r + b r = l + a print(-1) ```
output
1
96,048
1
192,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1 Submitted Solution: ``` def solve(a, b, c): l = 0; r = a; t = 0 for i in range(80): t = l // 60 p = 60*t + c if l <= p <= r: print(p) exit() l = r + b r = l + a print(-1) a, b, c = map(int, input().split()) solve(a,b,c) ```
instruction
0
96,049
1
192,098
Yes
output
1
96,049
1
192,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: a,b,c = LI() s = set() s.add(0) t = 0 r = -1 for i in range(60): while t > c: c += 60 if t <= c <= t+a: r = c break t += a + b rr.append(r) break return '\n'.join(map(str, rr)) print(main()) ```
instruction
0
96,050
1
192,100
Yes
output
1
96,050
1
192,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time, but on the contrary, if you are sleeping, you will miss it. Also, Mr. A will continue to take the same train even if he overtakes it, and the train will take 60 minutes to go around the Yamanote line. Therefore, Mr. A will arrive at the destination after 60t + c (t is a non-negative integer) minutes. How many minutes will A be able to reach his destination? Output -1 when it is unreachable. However, if the time you arrive at your destination is the boundary between the time you are sleeping and the time you are awake, you can get off. Constraints * 0 <a, b, c <60 Input The input is given in one line in the following format. a b c The input consists of three integers a, b, c. a is the time you are awake, b is the time you are sleeping, and c is the time it takes to get to your destination after boarding. The unit of a, b, and c is minutes. Output If you can reach your destination, output the time it takes to reach your destination. Otherwise, output -1. Examples Input 10 10 5 Output 5 Input 50 40 51 Output 111 Input 20 20 20 Output 20 Input 30 30 40 Output -1 Submitted Solution: ``` def solve(a, b, c): l = 0; r = a; for t in range(114514): t = l // 60 p = 60*t + c if l <= p <= r: print(p) exit() l = r + b r = l + a print(-1) a, b, c = map(int, input().split()) solve(a,b,c) ```
instruction
0
96,051
1
192,102
Yes
output
1
96,051
1
192,103