message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible. The function f_k(x) can be described in the following way: * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x); * sort list d in non-descending order; * take d_{k + 1} as a result. If there are multiple optimal answers you can print any of them. Input The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent. The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order. It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5. Output Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them. Example Input 3 3 2 1 2 5 2 1 1 1000000000 1 0 4 Output 3 500000000 4 Submitted Solution: ``` import math def solve(points,k): if k == 0: print(points[0]) return index = 0 curr = points[index] diff = 0 count = 1 min_diff = float('inf') ans = float('inf') total = curr i = 1 while i < len(points): diff += points[i]-points[i-1] total += points[i] count += 1 if count == k+1: if diff < min_diff: min_diff = diff ans = min(ans,math.ceil(total/(k+1))) count -= 1 total -= points[index] index += 1 diff -= points[index]-points[index-1] i += 1 print(ans) def main(): t = int(input()) for i in range(t): n,k = map(int,input().split()) points = list(map(int,input().split())) solve(points,k) main() ```
instruction
0
80,901
3
161,802
No
output
1
80,901
3
161,803
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct. Output Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Examples Input 2 2 1 1 2 Output 1 Input 2 2 1 4 1 Output 0 Submitted Solution: ``` dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]] N = 1001 def dfs(arr, i, j): arr[i][j] = 0 for d in dirs: a = i + d[0] b = j + d[1] if arr[i][j] == 0: while a >=0 and a < N and b >= 0 and b < N and arr[a][b] != 1: a += d[0]; b+= d[1] if a >=0 and a < N and b >= 0 and b < N and arr[a][b] == 1: dfs(arr, a, b) if __name__ == "__main__": n = int(input()) arr = [[0 for j in range(N)] for i in range(N)] for i in range(n): a, b = map(int, input().split()) arr[a][b] = 1 res = -1 for i in range(1, N): for j in range(1, N): if arr[i][j] == 1: res += 1 dfs(arr, i, j) print(res) ```
instruction
0
81,074
3
162,148
Yes
output
1
81,074
3
162,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct. Output Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Examples Input 2 2 1 1 2 Output 1 Input 2 2 1 4 1 Output 0 Submitted Solution: ``` n,x,y,s=int(input()),{0},{0},-1 for i in range(n): q,w=map(int,input().split()) if q not in x and w not in y:s+=1 x.add(q) y.add(w) print(s) ```
instruction
0
81,077
3
162,154
No
output
1
81,077
3
162,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct. Output Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Examples Input 2 2 1 1 2 Output 1 Input 2 2 1 4 1 Output 0 Submitted Solution: ``` n = int(input()) coodenadas = [] for i in range(n): x, y = [ int(i) for i in input().split() ] coodenadas.append((x,y)) resultado = 0 for i in range(1, n): x = coodenadas[i][0] - coodenadas[i - 1][0] y = coodenadas[i][1] - coodenadas[i - 1][1] if x != 0 and y != 0: resultado += 1 print(resultado) ```
instruction
0
81,078
3
162,156
No
output
1
81,078
3
162,157
Provide tags and a correct Python 3 solution for this coding contest problem. After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. Input The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning. The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. Output Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Examples Input 3 3 1 2 2 Output 1 1 Input 3 3 1 1 1 Output 3 3 Input 3 3 2 1 1 3 3 Output 2 2
instruction
0
81,124
3
162,248
Tags: brute force, dfs and similar, shortest paths Correct Solution: ``` ''' ___ ____ ____ _____ _____/ (_)_ ______ ____ _____/ / /_ __ ______ ___ __ / __ `/ __ `/ __ / / / / / __ \/ __ `/ __ / __ \/ / / / __ `/ / / / / /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ / \__,_/\__,_/\__,_/_/\__,_/ .___/\__,_/\__,_/_/ /_/\__, /\__,_/\__, / /_/ /____/ /____/ ''' import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): return int(sys.stdin.readline()) def pr(n): return sys.stdout.write(str(n)+"\n") def prl(n): return sys.stdout.write(str(n)+" ") if os.path.exists('input.txt'): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] def solve(): n, m = mp() k = inp() l = li() q = deque() v = [[0]*(m+1) for i in range(n+1)] for i in range(0, 2*k - 1, 2): q.append((l[i], l[i+1])) v[l[i]][l[i+1]] = 1 while q: a, b = q.popleft() for i in range(4): A, B = a+dx[i], b+dy[i] if A > 0 and A <= n and B > 0 and B <= m: if not v[A][B]: q.append((A, B)) v[A][B] = 1 print(a, b) for _ in range(1): solve() ```
output
1
81,124
3
162,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. Input The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning. The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. Output Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Examples Input 3 3 1 2 2 Output 1 1 Input 3 3 1 1 1 Output 3 3 Input 3 3 2 1 1 3 3 Output 2 2 Submitted Solution: ``` # Author : -pratyay- import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") inp=sys.stdin.buffer.readline inar=lambda: list(map(int,inp().split())) inin=lambda: int(inp()) inst=lambda: inp().decode().rstrip('\n\r') # Am I debugging, check if I'm using same variable name in two places _T_=1#inin() for _t_ in range(_T_): n,m=inar() gr=[[0 for i in range(m)] for j in range(n)] k=inin() arr=inar() i=0 for j in range(k): x,y=arr[i]-1,arr[i+1]-1 i+=2 gr[x][y]=1 #print(gr) temp=[] while(True): flag=True for i in range(n): for j in range(m): if gr[i][j]==1: for dx,dy in zip([-1,0,1,0],[0,-1,0,1]): if 0<=i+dx<n and 0<=j+dy<m and gr[i+dx][j+dy]==0: flag=False temp.append(i+dx+1) temp.append(j+dy+1) gr[i+dx][j+dy]=1 if flag==True: break print(temp[-2],temp[-1]) ```
instruction
0
81,125
3
162,250
No
output
1
81,125
3
162,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. Input The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning. The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. Output Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Examples Input 3 3 1 2 2 Output 1 1 Input 3 3 1 1 1 Output 3 3 Input 3 3 2 1 1 3 3 Output 2 2 Submitted Solution: ``` def find_result(n,m,cords): queue=[] visited={} for cord in cords: queue.append((cord[0],cord[1],0)) while queue: x,y,val=queue.pop(0) if (x,y) in visited: continue visited[(x,y)]=1 dr=[(-1,0),(1,0),(0,-1),(0,1)] for (a,b) in dr: xx=x+a yy=y+b if xx<0 or xx>m:continue if yy<0 or yy>n: continue if (xx,yy) not in visited: queue.append((xx,yy,val+1)) file1 = open("output.txt", "w") # write mode file1.write(str(x+1)+" "+str(y+1)) file1.close() def main(): with open('input.txt') as fp: n,m = fp.readline().split() n,m = int(n),int(m) k=fp.readline() # for i in range(k): cords=fp.readline().split() cords= [(int(cords[i])-1,int(cords[i+1])-1) for i in range(0,len(cords),2)] # print(n,m,cords) find_result(n-1,m-1,cords) if __name__ == "__main__": main() """ """ ```
instruction
0
81,126
3
162,252
No
output
1
81,126
3
162,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. Input The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning. The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. Output Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Examples Input 3 3 1 2 2 Output 1 1 Input 3 3 1 1 1 Output 3 3 Input 3 3 2 1 1 3 3 Output 2 2 Submitted Solution: ``` from math import log spaces = (" ","\n","\t") stops = (""," ","\n","\t") extendedPoints = set() startingPoints = set() interestPoints = [] class TPoint: def __init__(self,x,y): self.x=x self.y=y def __str__(self): return "("+str(self.x)+","+str(self.y)+")" def __eq__(self, other): return self.x == other.x and self.y == other.y def __hash__(self): return self.x*20000 + self.y #x=0 #y=0 #h=0 # эвристика def sortKey(p): return p.h def heuristic(p, otherPoints): minH = float("inf") for point in otherPoints: currentH = abs(point.x - p.x) + abs(point.y - p.y) if currentH < minH: minH = currentH return minH def addPoint(p,pointList): if not p in extendedPoints: p.h = heuristic(p,startingPoints) extendedPoints.add(p) pointList.append(p) #print(p.x,p.y,p.h) return True else: return False def extend(point,n,m,poinList): ok = False if point.x>1: ok = addPoint(TPoint(point.x-1,point.y),poinList) or ok if point.y>1: ok = addPoint(TPoint(point.x-1,point.y-1),poinList) or ok if point.y<m: ok = addPoint(TPoint(point.x-1,point.y+1),poinList) or ok if point.x<n: ok = addPoint(TPoint(point.x+1,point.y),poinList) or ok if point.y>1: ok = addPoint(TPoint(point.x+1,point.y-1),poinList) or ok if point.y<m: ok = addPoint(TPoint(point.x+1,point.y+1),poinList) or ok if point.y>1: ok = addPoint(TPoint(point.x,point.y-1),poinList) or ok if point.y<m: ok = addPoint(TPoint(point.x,point.y+1),poinList) or ok return ok def ReadNext(fileObject): currentBuffer = "" currentRead=fileObject.read(1) while currentRead in spaces: currentRead=fileObject.read(1) currentBuffer = currentBuffer + currentRead while not currentRead in stops: currentRead=fileObject.read(1) currentBuffer = currentBuffer + currentRead return currentBuffer.strip() w, r= open('output.txt', 'w'), open('input.txt', 'r') n = int(ReadNext(r)) m = int(ReadNext(r)) k = int(ReadNext(r)) mscale = int(5 + log(m*n,10)) for i in range(k): x = int(ReadNext(r)) y = int(ReadNext(r)) p = TPoint(x,y) startingPoints.add(p) extendedPoints.add(p) tmpPoints = [] tmpPoints.append(TPoint(1,1)) tmpPoints.append(TPoint(1,m)) tmpPoints.append(TPoint(n,1)) tmpPoints.append(TPoint(n,m)) tmpPoints.append(TPoint(int(n/2),1)) tmpPoints.append(TPoint(1,int(m/2))) tmpPoints.append(TPoint(int(n/2),m)) tmpPoints.append(TPoint(n,int(m/2))) tmpPoints.append(TPoint(int(n/2),int(m/2))) for p in tmpPoints: extend(p,n,m,interestPoints) for p in startingPoints: extend(p,n,m,interestPoints) interestPoints.sort(reverse=True, key=sortKey) while len(interestPoints) > mscale: interestPoints.pop(len(interestPoints)-1) if(len(interestPoints)>0): maxPoint = interestPoints[0] for p in interestPoints: currentBeam = [p] canExtend = True while canExtend: canExtend = False for i in range(len(currentBeam)): if extend(currentBeam[i],n,m,currentBeam): canExtend = True currentBeam.sort(reverse=True, key=sortKey) while len(currentBeam) > 4: currentBeam.pop(len(currentBeam)-1) if currentBeam[0].h>maxPoint.h: maxPoint = currentBeam[0] #print(maxPoint.x,maxPoint.y) #print(str(len(extendedPoints))) w.write(str(maxPoint.x)+" "+str(maxPoint.y)+"\n") else: w.write(str(n)+" "+str(m)+"\n") ```
instruction
0
81,127
3
162,254
No
output
1
81,127
3
162,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. Input The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning. The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. Output Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Examples Input 3 3 1 2 2 Output 1 1 Input 3 3 1 1 1 Output 3 3 Input 3 3 2 1 1 3 3 Output 2 2 Submitted Solution: ``` ''' ___ ____ ____ _____ _____/ (_)_ ______ ____ _____/ / /_ __ ______ ___ __ / __ `/ __ `/ __ / / / / / __ \/ __ `/ __ / __ \/ / / / __ `/ / / / / /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ / \__,_/\__,_/\__,_/_/\__,_/ .___/\__,_/\__,_/_/ /_/\__, /\__,_/\__, / /_/ /____/ /____/ ''' import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): return int(sys.stdin.readline()) def pr(n): return sys.stdout.write(str(n)+"\n") def prl(n): return sys.stdout.write(str(n)+" ") if os.path.exists('input.txt'): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') dx = [0, 0, 1, -1, 1, 1, -1, -1] dy = [1, -1, 0, 0, 1, -1, 1, -1] def solve(): n, m = mp() k = inp() l = li() q = deque() v = defaultdict(int) dist = defaultdict(int) for i in range(0, 2*k - 1, 2): q.append((l[i], l[i+1])) v[(l[i], l[i+1])] = 1 last = [] while q: last = q[0] a, b = q.popleft() for i in range(4): A, B = a+dx[i], b+dy[i] if A > 0 and A <= n and B > 0 and B <= m: if not v[(A, B)]: q.append((A, B)) dist[(A, B)] = dist[(a, b)] + 1 v[(A, B)] = 1 ans = [] ma = 0 for i in dist: if dist[i] > ma: ma = dist[i] ans = i print(*ans) for _ in range(1): solve() ```
instruction
0
81,128
3
162,256
No
output
1
81,128
3
162,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distance). We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value <image>. Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length. Input The first line contains integer n (1 ≤ n ≤ 106). The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106). It is guaranteed that no two points coincide. Output Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality <image>. If there are multiple possible answers, print any of them. It is guaranteed that the answer exists. Examples Input 5 0 7 8 10 3 4 5 0 9 12 Output 4 3 1 2 5 Note In the sample test the total distance is: <image> (|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26 Submitted Solution: ``` import sys def read(): # 2.8 sec with reading by line lines = sys.stdin.readlines() n = int(lines[0]) ans = [] for ix in range(n): a, b = lines[ix + 1].rstrip().split(' ') ans.append((int(a), int(b), ix)) return ans DIVISOR = int(1e4) def box(pt): return (pt[0] // DIVISOR, pt[1] // DIVISOR) def ix(pt): return pt[2] def pack(a): geo = dict() for pt in a: k = box(pt) if k not in geo: geo[k] = [] geo[k].append(ix(pt)) return geo def output(geo): for cell in sorted(geo.keys()): for ix in geo[cell]: sys.stdout.write(str(ix) + ' ') def main(): a = read() boxes = pack(a) output(boxes) if __name__ == '__main__': main() ```
instruction
0
81,224
3
162,448
No
output
1
81,224
3
162,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distance). We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value <image>. Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length. Input The first line contains integer n (1 ≤ n ≤ 106). The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106). It is guaranteed that no two points coincide. Output Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality <image>. If there are multiple possible answers, print any of them. It is guaranteed that the answer exists. Examples Input 5 0 7 8 10 3 4 5 0 9 12 Output 4 3 1 2 5 Note In the sample test the total distance is: <image> (|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26 Submitted Solution: ``` n=int(input()) if n<10000: s="" for i in range(n): s+=str(i)+" " print(s) else:print("oups") ```
instruction
0
81,225
3
162,450
No
output
1
81,225
3
162,451
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distance). We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value <image>. Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length. Input The first line contains integer n (1 ≤ n ≤ 106). The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106). It is guaranteed that no two points coincide. Output Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality <image>. If there are multiple possible answers, print any of them. It is guaranteed that the answer exists. Examples Input 5 0 7 8 10 3 4 5 0 9 12 Output 4 3 1 2 5 Note In the sample test the total distance is: <image> (|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26 Submitted Solution: ``` n = int( input( ) ) v = [ [] ] tmp = [] for i in range( 1001 ): v.append( tmp ) for i in range( n ): a, b = map( int, input( ).split( ) ) tup = ( b, i + 1 ) index = int( a / 1000 ) v[ index ].append( tup ) for i in range( 1001 ): if( len( v[ i ] ) == 0 ): continue v[ i ].sort( ) if( i % 2 ): v[ i ].reverse( ) for j in range( len( v[ i ] ) ): print( v[ i ][ j ][ 1 ], end = ' ' ) ```
instruction
0
81,226
3
162,452
No
output
1
81,226
3
162,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distance). We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value <image>. Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length. Input The first line contains integer n (1 ≤ n ≤ 106). The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106). It is guaranteed that no two points coincide. Output Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality <image>. If there are multiple possible answers, print any of them. It is guaranteed that the answer exists. Examples Input 5 0 7 8 10 3 4 5 0 9 12 Output 4 3 1 2 5 Note In the sample test the total distance is: <image> (|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26 Submitted Solution: ``` import sys n=int(sys.stdin.readline()) for j in range(n): a,b=sys.stdin.readline().split() print('%s' % ' '.join(str(j) for j in range(1,n+1))) ```
instruction
0
81,227
3
162,454
No
output
1
81,227
3
162,455
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,705
3
163,410
Tags: binary search, math Correct Solution: ``` import math def issuff(n,m,a,b,f): for i in range(n): if f>0: burn=(f+m)/a[i] f=round(f-burn,6) burn=(f+m)/b[(i+1)%n] f=round(f-burn,6) if f<0: return False return True def answer(n,m,a,b): l=0.1 r=1000000006 ans=-1 while r>=l: mid=round((r+l)/2,6) if issuff(n,m,a,b,mid): ans=mid r=mid-0.000001 else: l=mid+0.000001 return ans n=int(input()) m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) print(answer(n,m,a,b)) ```
output
1
81,705
3
163,411
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,706
3
163,412
Tags: binary search, math Correct Solution: ``` n=int(input())#number of planets. m=int(input())#weight of the payload lift=list(map(int,input().split())) # the number of tons, which can be lifted off by one ton of fuel. land=list(map(int,input().split())) #the number of tons, which can be landed by one ton of fuel. #n flights: 1→2→…n→1. #rocketの重さが9、燃料が3、a_iが8のとき, #(9+3)//8=1.5消費する. fuellist=[None]*(2*n) for i in range(n): fuellist[2*i]=lift[i] if i!=n-1: fuellist[2*i+1]=land[i+1] else: fuellist[2*i+1]=land[0] coe=fuellist[::-1] def weight(W,A): return W*(A/(A-1)) we=m if min(lift)<=1 or min(land)<=1: print(-1) else: for i in range(2*n): we=weight(we,coe[i]) print(we-m) ```
output
1
81,706
3
163,413
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,707
3
163,414
Tags: binary search, math Correct Solution: ``` n = int(input()) rm = m = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) if min(a+b) is 1: print(-1) else: for i in range(n-1,-1,-1): m += m / (a[(i + 1) % n] - 1) m += m / (b[i] - 1) print(round(m - rm,7)) ```
output
1
81,707
3
163,415
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,708
3
163,416
Tags: binary search, math Correct Solution: ``` i=input i() m=int(i()) v=m try: for a in map(int, (i()+' '+i()).split()):v*=a/(a-1) except:v=m-1 print(v-m) # Made By Mostafa_Khaled ```
output
1
81,708
3
163,417
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,709
3
163,418
Tags: binary search, math Correct Solution: ``` #!/usr/bin/python3 N = int(input()) M = int(input()) a = [int(x) for x in input().split(' ')] b = [int(x) for x in input().split(' ')] for i in range(len(a)): if a[i] == 1 or b[i] == 1: print(-1) exit() def galima(fuel): fuel -= (M + fuel)/a[0] for i in range(1, len(a)): fuel -= (M + fuel)/a[i] fuel -= (M + fuel)/b[i] fuel -= (M + fuel)/b[0] if(fuel >= 0): return True else: return False low = 0.0 high = 1e9 for _ in range(300): mid = (low+high)/2 if(galima(mid)): high = mid else: low = mid print(high) ```
output
1
81,709
3
163,419
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,710
3
163,420
Tags: binary search, math Correct Solution: ``` input() m=int(input()) v=m try: for a in map(int, input().split() + input().split()): v*=a/(a-1) print(v-m) except ZeroDivisionError: print(-1) ```
output
1
81,710
3
163,421
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,711
3
163,422
Tags: binary search, math Correct Solution: ``` import math def issuff(n,m,a,b,f): for i in range(n): if f>0: burn=(f+m)/a[i] f=round(f-burn,6) burn=(f+m)/b[(i+1)%n] f=round(f-burn,6) if f<0: return False return True def answer(n,m,a,b): l=0.1 r=1000000007 ans=-1 while r>=l: mid=round((r+l)/2,6) if issuff(n,m,a,b,mid): ans=mid r=mid-0.000001 else: l=mid+0.000001 return ans n=int(input()) m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) print(answer(n,m,a,b)) ```
output
1
81,711
3
163,423
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
81,712
3
163,424
Tags: binary search, math Correct Solution: ``` '''a[i]*f1 = m+(ans) b[i+1]*l2 = m+(ans-f1) a[i+1]*f2 = m+(ans-f1-l2) b[i+2]*l3 = m+(ans-f1-l2-f2) a[i+2]*f3 = m+(ans-f1-l2-f2-l3) b[i+1]*l2' = m+(ans-f1-l2-f2-l3-f3) a[i+1]*f2' = m+(ans-f1-l2-f2-l3-f3-l2') b[i]*l1' = m+(ans-f1-l2-f2-l3-f3-l2'-f2') f1+l2+f2+l3+f3+l2'+f2'+l1' = ans l1' = m/b[i]-1 f2' = m+l1'/(a[i+1]-1) l2' = (m+l1'+f2')/(b[i+1]-1) f3 = (m+l1'+f2'+l2')/(a[i+2]-1) ... f1 = (m+l1'+f2'+l2'+f3+l3+f2+l2)/(a[i]-1) ''' n = int(input()) m = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) k = m i=0 j=1 ans = 0 c = 1 while i>=0 and i<n: try: if j==1: ans = m/(b[i]-1) else: ans = m/(a[i]-1) except: print(-1) break m += ans j = 0 if j==1 else 1 i+=c if i==n: c = -c i-=1 else: print("{0:.10f}".format(m-k)) ```
output
1
81,712
3
163,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` import os import sys 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") ########################################################## def prime_factors(x): s=set() n=x i=2 while i*i<=n: if n%i==0: while n%i==0: n//=i s.add(i) i+=1 if n>1: s.add(n) return s from collections import Counter # c=sorted((i,int(val))for i,val in enumerate(input().split())) import heapq # c=sorted((i,int(val))for i,val in enumerate(input().split())) # n = int(input()) # ls = list(map(int, input().split())) # n, k = map(int, input().split()) # n =int(input()) #arr=[(i,x) for i,x in enum] #arr.sort(key=lambda x:x[0]) #print(arr) import math # e=list(map(int, input().split())) from collections import Counter #print("\n".join(ls)) #print(os.path.commonprefix(ls[0:2])) #n=int(input()) from bisect import bisect_right #d=sorted(d,key=lambda x:(len(d[x]),-x)) d=dictionary d={x:set() for x in arr} #n=int(input()) #n,m,k= map(int, input().split()) import heapq #for _ in range(int(input())): #n,k=map(int, input().split()) import sys input=sys.stdin.buffer.readline #for _ in range(int(input())): #ans=0 import math def f(g): l =g-1 r =g while l <=r: mid = (l + r) / 2 if can(mid): anss = mid r=mid else: l=mid if (l-r)<10**(-10): break def can(x): for i in range(n): if i!=0: w=m+x x-=w/ls[i] w=m+x x-=w/arr[i] if (x<0): return False w=x+m x-=w/ls[0] if x<0.0: return False return True n=int(input()) m=int(input()) arr=list(map(int, input().split())) ls=list(map(int, input().split())) l=0 ans=-1 r=10**9+100 anss=-1 while l+1e-7<r: mid=(l+r)/2 if can(mid): ans=mid r=mid else: l=mid #print("%.12f"%ans) print(ans) from collections import deque ```
instruction
0
81,713
3
163,426
Yes
output
1
81,713
3
163,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` R = lambda: map(int, input().split()) n = int(input()) m = int(input()) a, b = list(R()), list(R()) b = b[1:] + b[:1] l, r = 0, 2 * 10**9 while (r - l) / max(1, r) >= 1e-7 and l < 10**9 + 1: rem = mid = (l + r) / 2 for i in range(n): rem -= (m + max(0, rem)) / a[i] rem -= (m + max(0, rem)) / b[i] if rem < 0: l = mid else: r = mid print(l if l < 10**9 + 1 else -1) ```
instruction
0
81,714
3
163,428
Yes
output
1
81,714
3
163,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` def main(): n = int(input()) start_m = m = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] try: mt = m / (b[0] - 1) except ZeroDivisionError: print(-1) return m += mt for i in range(len(a)): try: mt = m / (a[len(a) - i - 1] - 1) except ZeroDivisionError: print(-1) return m += mt if i == len(a) - 1: continue try: mt = m / (b[len(b) - i - 1] - 1) except ZeroDivisionError: print(-1) return m += mt print(m - start_m) if __name__ == '__main__': main() ```
instruction
0
81,715
3
163,430
Yes
output
1
81,715
3
163,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` """for p in range(int(input())): n,k=map(int,input().split(" ")) number=input().split(" ") chances=[k for i in range(n)] prev=-1 prev_updated=-1 last_used=False toSub=0 start=0 prevSub=0 if(number[0]=='1'): prev=0 prev_updated=0 start=1 for i in range(start,n): if(number[i]=='1'): # print("\ni",i,"\ntoSub",toSub,"\nprevUpadted",prev_updated,"\nprev",prev,"\nlast_used",last_used) f1=False # toSub+=1 toSub=0 zeros=i - prev_updated - 1 if(last_used): zeros-=1 #chances[i]-=toSub #print(prevSub,(i - prev - 1 ) +1) if(i - prev - 1 <= prevSub): chances[i]-= prevSub - (i - prev - 1 ) +1 if(chances[i]<zeros): chances[i]=zeros toSub+= prevSub - (i - prev - 1 ) +1 f1=True if(zeros==0 or chances[i]==0): prev_updated=i prev=i last_used=False prevSub=toSub continue # print("\nchances: ",chances[i],"\t\tzeroes : ",zeros,"\t\tprevSub :",prevSub) if(chances[i]>zeros): # print("\t\t\t\t1") number[i-zeros]='1' number[i]='0' prev_updated=i-zeros last_used=False elif(chances[i]==zeros): # print("\t\t\t\t2") number[i]='0' number[i-chances[i]]='1' prev_updated=i-chances[i] last_used=True else: # print("\t\t\t\t3") number[i]='0' number[i-chances[i]]='1' prev_updated=i-chances[i] last_used=True prev=i prevSub=toSub if(prev_updated>2 and f1): if(number[prev_updated]=='1' and number[prev_updated-1]=='0' and number[prev_updated-2]=='1'): last_used=False #if() # print("\ni",i,"\ntoSub",toSub,"\nprevUpadted",prev_updated,"\nprev",prev,"\nlast_used",last_used) # print(number) else: toSub=0 print(*number) # print(chances)""" """class offer: def __init__(self, n, fre): self.num = n self.free = fre self.delta= n-fre n,m,k=map(int,input().split(" ")) shovel=list(map(int,input().split(" "))) #dicti={} offers=[] temp_arr=[False for i in range(n)] for i in range(m): p,q=map(int,input().split(" ")) if(p>k): continue offers.append(offer(p,q)) # dicti[p]=q #for i in dicti: # dicti[i].sort() shovel.sort() shovel=shovel[:k+1] offers.sort(key=lambda x: x.delta/x.num,reverse=True) bestoffer=[] for i in offers: if(not temp_arr[i.num]): temp_arr[i.num]=True bestoffer.append(i) cost=0 for i in bestoffer: for p in range(int(input())): arr=list(input()) n=len(arr) for i in range(n): arr[i]=ord(arr[i])-96 arr.sort() arr1=arr[:n//2] arr2=arr[n//2:] arr=[] #print(arr,arr1,arr2) i1=n//2-1 i2=n-i1-2 while (i1!=-1 and i2!=-1): arr.append(arr1[i1]) arr.append(arr2[i2]) i1-=1 i2-=1 if(i1!=-1): arr.append(arr1[i1]) elif(i2!=-1): arr.append(arr2[i2]) #print(arr) s="" for i in range(n-1): if(abs(arr[i]-arr[i+1])==1): s=-1 print("No answer") break else: s+=chr(arr[i]+96) if(s!=-1): s+=chr(arr[-1]+96) print(s)""" """ n,m=map(int,input().split(" ")) seti=[] ans=[1 for i in range(n)] for i in range(m): arr=list(map(int,input().split(" "))) if(arr[0]>1): seti.append(set(arr[1:])) else: m-=1 parent=[-1 for i in range(m)] #print(seti) for i in range(m-1): for j in range(i+1,m): if(parent[j]==-1): if(len(seti[i].intersection(seti[j]))>0): seti[i]=seti[i].union(seti[j]) parent[j]=i #print(parent) for i in range(m): if(parent[i]==-1): temp=list(seti[i]) store=len(temp) for j in temp: ans[j-1]=store print(*ans) for p in range(int(input())): arr=list(input()) n=len(arr) for i in range(n): arr[i]=ord(arr[i])-96 arr.sort() arr1=arr[:n//2] arr2=arr[n//2:] arr=[] #print(arr,arr1,arr2) i1=n//2-1 i2=n-i1-2 while (i1!=-1 and i2!=-1): arr.append(arr1[i1]) arr.append(arr2[i2]) i1-=1 i2-=1 if(i1!=-1): arr.append(arr1[i1]) elif(i2!=-1): arr.append(arr2[i2]) s="" for i in range(n-1): if(abs(arr[i]-arr[i+1])==1): s=-1 print("No answer") break else: s+=chr(arr[i]+96) if(s!=-1): s+=chr(arr[-1]+96) print(s) #n=0""" n=int(input()) p=int(input()) arr1=list(map(int,input().split(" "))) arr2=list(map(int,input().split(" "))) a=1 flag=False for i in range(n): a*=((arr1[i]-1)*(arr2[i]-1))/(arr1[i]*arr2[i]) if(a==0): flag=True break if(flag): print(-1) else: print(p*((1-a)/a)) ```
instruction
0
81,716
3
163,432
Yes
output
1
81,716
3
163,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` '''import sys sys.setrecursionlimit(2**20)''' global precisao precisao = 0.000001 def check(palpite, qtd_planetas, peso, decolagem, aterrisagem): peso_total = palpite + peso for i in range(qtd_planetas): combustivel = (peso_total / decolagem[i]) peso_total = peso_total - combustivel #print("P", peso_total) if peso_total < peso and abs(peso_total - peso) > precisao : #print("if 1") #print("foguete", peso) return False next_index = i+1 if next_index == qtd_planetas: #print("if x") next_index = 0 combustivel = (peso_total / aterrisagem[next_index]) peso_total = peso_total - combustivel if peso_total < peso and abs(peso_total - peso) > precisao: #print("if 2") return False return True def busca(a, b, peso, qtd_planetas, left, right): mid = (left + right) / 2 #print("M",mid) if(abs(left - right) < precisao): #print("left", left) #print("right", right) #if check(palpite, qtd_planetas, mid + precisao, a, b) or check(palpite, qtd_planetas, mid - precisao, a, b): return mid #else: # return -1 if check(mid, qtd_planetas, peso, a, b): return busca(a, b, peso, qtd_planetas, left, mid) else: return busca(a, b, peso, qtd_planetas, mid, right) l = input().split() n = int(l[0]) l = input().split() m = int(l[0]) a = list(map(int, input().split())) b = list(map(int, input().split())) #print(a) #print(b) flag = 1 for i in range(1, n): if a[i] == 1 or b[i] == 1: print(-1) flag = 0 break if flag: result = busca(a, b, m, n, 0, 1000000000) print('%.10f' % result) ```
instruction
0
81,717
3
163,434
No
output
1
81,717
3
163,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n = int(input()) m = int(input()) v = list(map(int, input().split())) p = list(map(int, input().split())) f = float(1) for i in range(0, n): f *= v[i] * p[i] k = float(1) s = float(0) for i in range(0, n - 1): s += f / v[i] * k k -= k / v[i] s += f / p[i + 1] * k k -= k / p[i + 1] s += f / v[n - 1] * k k -= k / v[n - 1] s += f / p[0] * k if f == s: f+=0.000001 else: ans = (m * s) / (f - s) b = 0 for i in range(0, n): if v[i] == 1 or p[i] == 1: b = 1 break if b == 1: print(-1) else: print(ans) ```
instruction
0
81,718
3
163,436
No
output
1
81,718
3
163,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n = int(input()) m = int(input()) v = list(map(int, input().split())) p = list(map(int, input().split())) f = float(1) for i in range(0, n): f *= v[i] * p[i] k = float(1) s = float(0) for i in range(0, n - 1): s += f / v[i] * k k -= k / v[i] s += f / p[i + 1] * k k -= k / p[i + 1] s += f / v[n - 1] * k k -= k / v[n - 1] s += f / p[0] * k b = 0 for i in range(0, n): if v[i] == 1 or p[i] == 1: b = 1 break if b == 1: print(-1) else: if f == s: print(804389417.2082357407) else: print((m * s) / (f - s)) ```
instruction
0
81,719
3
163,438
No
output
1
81,719
3
163,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 → 2 → … n → 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet → take-off from the 1-st planet → landing to the 2-nd planet → 2-nd planet → take-off from the 2-nd planet → … → landing to the n-th planet → the n-th planet → take-off from the n-th planet → landing to the 1-st planet → the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 ⋅ 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≤ n ≤ 1000) — number of planets. The second line contains the only integer m (1 ≤ m ≤ 1000) — weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≤ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` def good_combination(m, a, b, f): weight = m+f for i in range(len(a)): burnt_takeoff = weight / a[i] weight -= burnt_takeoff burnt_landing = weight / b[i] weight -= burnt_landing if weight < m: return False return True def solve(m, a, b): if not good_combination(m, a, b, 1000000000): return -1 l = 1 r = 1000000000 while r-l > 10 ** -6: mid = (l+r)/2 if good_combination(m, a, b, mid): r = mid else: l = mid return l if good_combination(m, a, b, l) else r input() m = int(input().strip()) a = [int(x) for x in input().strip().split()] b = [int(x) for x in input().strip().split()] print(solve(m, a, b)) ```
instruction
0
81,720
3
163,440
No
output
1
81,720
3
163,441
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,822
3
163,644
Tags: greedy Correct Solution: ``` n,m=map(int,input().split()) a = [list(map(int,input().split())) for _ in range(m)] def calc(idx): diff = sorted([(x[-1] - x[idx], i) for i, x in enumerate(a)]) tot = sum([x[0] for x in diff]) ans = [] while tot > 0: tot -= diff[-1][0] ans.append(diff[-1][1]+1) diff.pop() return ans ans = [i+1 for i in range(m)] for i in range(n-1): temp = calc(i) if len(temp) < len(ans): ans = temp print(len(ans)) print(" ".join(map(str,ans))) ```
output
1
81,822
3
163,645
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,823
3
163,646
Tags: greedy Correct Solution: ``` def getMaxBoothForCandidateToWin(candidate,opposition,m): diff=[] # [difference, station] for i in range(m): diff.append([candidate[i]-opposition[i],i]) diff.sort(key=lambda x:x[0],reverse=True) prefixSum=0 maxBooth=0 pollingStations=[] for x,station in diff: if prefixSum+x<0: break prefixSum+=x pollingStations.append(station) maxBooth+=1 # print('maxbooth:{} station:{}'.format(maxBooth,pollingStations)) return maxBooth,pollingStations def main(): # check max booth for every other candidate to win opposition n,m=readIntArr() arr=[] for _ in range(m): arr.append(readIntArr()) opposition=[] for i in range(m): opposition.append(arr[i][n-1]) maxBooth=0 pollingStations=[] for i in range(n-1): candidate=[] for j in range(m): candidate.append(arr[j][i]) mb,ps=getMaxBoothForCandidateToWin(candidate,opposition,m) if mb>maxBooth: maxBooth=mb pollingStations=ps minBooths=m-maxBooth psSet=set(pollingStations) removedStations=[] for i in range(m): if i not in psSet: removedStations.append(i) for i in range(len(removedStations)): removedStations[i]+=1 print(minBooths) oneLineArrayPrint(removedStations) return import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) # input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] # def readFloatArr(): # return [float(x) for x in input().split()] def makeArr(defaultVal,dimensionArr): # eg. makeArr(0,[n,m]) dv=defaultVal;da=dimensionArr if len(da)==1:return [dv for _ in range(da[0])] else:return [makeArr(dv,da[1:]) for _ in range(da[0])] def queryInteractive(x,y): print('? {} {}'.format(x,y)) sys.stdout.flush() return int(input()) def answerInteractive(ans): print('! {}'.format(ans)) sys.stdout.flush() inf=float('inf') MOD=10**9+7 for _abc in range(1): main() ```
output
1
81,823
3
163,647
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,824
3
163,648
Tags: greedy Correct Solution: ``` import math IP = lambda: list(map(int, input().split())) INF = 1e9 n, m = IP() lst = [[] for i in range(n)] for i in range(m): d = IP() for j in range(n): lst[j].append(d[j]) # print(*lst, sep = '\n') s = [sum(i) for i in lst] ret = [[] for i in range(n-1)] if s[-1] <= max(s[:-1]): print(0) print() else: for i in range(n-1): diff = s[-1] - s[i] for k in range(m): mdiff = idx = 0 for j in range(m): if mdiff < lst[-1][j] - lst[i][j]: mdiff = lst[-1][j] - lst[i][j] idx = j ret[i].append(idx+1) diff -= mdiff lst[i][idx] = 10**9 if diff <= 0: break idx = min([(len(ret[i]), i) for i in range(len(ret))])[1] print(len(ret[idx])) print(*ret[idx]) ```
output
1
81,824
3
163,649
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,825
3
163,650
Tags: greedy Correct Solution: ``` #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction 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---------------------------------------------------- col,ro=map(int,input().split()) grid=[] for i in range(ro): l=list(map(int,input().split())) l=[l[k]-l[-1] for k in range(len(l))] grid+=[l] work=[[[grid[j][i],j+1] for j in range(ro)] for i in range(col-1)] for i in work: i.sort(reverse=True) maxi=0 maxind=0 ind=0 #print(work) for i in work: ind+=1 summ=0 x=0 for k in i: summ+=k[0] if(summ>=0): x+=1 else: break if(x>=maxi): maxi=x maxind=ind print(ro-maxi) ans=[] #print(maxi) for i in range(maxi,ro): ans+=[work[maxind-1][i][1]] ans.sort() print(*ans) ```
output
1
81,825
3
163,651
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,826
3
163,652
Tags: greedy Correct Solution: ``` a = [int(s) for s in input().split()] b = [] for numbers in range(a[1]): b.append([int(s) for s in input().split()]) c = [0 for i in range(len(b[0]))] for i in range(len(b)): for j in range(len(b[0])): c[j] += b[i][j] if c.index(max(c)) != len(c) - 1: print(0) else: e = [] for columns in range(len(b[0]) - 1): d = [] for rows in range(len(b)): d.append([b[rows][-1] - b[rows][columns], b[rows][columns], b[rows][-1], rows + 1]) d.sort(reverse=True) e0, e1, num, l = c[columns], c[-1], 0, [] for delta in d: e0 -= delta[1] e1 -= delta[2] num += 1 l.append(delta[-1]) if e0 >= e1: e.append([num, l]) break e.sort() print(e[0][0]) for i in e[0][1]: print(i, end=' ') print() ```
output
1
81,826
3
163,653
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,827
3
163,654
Tags: greedy Correct Solution: ``` def solve(n, m, a): answer = [(i + 1) for i in range(m)] for i in range(n - 1): pret = solve_two(m, a[i], a[n - 1]) if len(answer) > len(pret): answer = pret return answer def solve_two(m, a1, a0): dif = [] difsum = 0 for i in range(m): dif.append((a1[i] - a0[i], i + 1)) difsum += a1[i] - a0[i] dif.sort(key=lambda d: d[0]) answer = [] for i in range(m): if difsum >= 0: break difsum -= dif[i][0] answer.append(dif[i][1]) return answer def main(): n, m = [int(s) for s in input().split()] a = [[0] * m for _ in range(n)] for i in range(m): line = [int(s) for s in input().split()] for j in range(n): a[j][i] = line[j] answer = solve(n, m, a) print(len(answer)) for c in answer: print(c, end=" ") if __name__ == "__main__": main() ```
output
1
81,827
3
163,655
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,828
3
163,656
Tags: greedy Correct Solution: ``` import copy from operator import itemgetter n, m = map(int, input().split()) a = [] for i in range(m): a.append([i] + [int(x) for x in input().split()]) b = [0 for x in range(n)] for i in range(m): for j in range(1, n + 1): b[j - 1] += a[i][j] #print(*a, sep='\n') #print(b) aans = [x for x in range(n * m)] #some = b.index(max(b[:-1])) + 1 aa = copy.deepcopy(a) bb = copy.deepcopy(b) for some in range(1, n): a = copy.deepcopy(aa) b = copy.deepcopy(bb) #print(some) for i in range(m): a[i].append(a[i][-1] - a[i][some]) ans = [] #print(*a, sep='\n') #print(b) a.sort(key=itemgetter(-1), reverse=True) for i in range(m): if b[-1] <= max(b[:-1]): break #if a[i][-1] > max(a[i][1:-1]): if True: ans.append(a[i][0] + 1) for j in range(1, n + 1): b[j - 1] -= a[i][j] #print('---') #print(*a, sep='\n') #print(b) #print(ans) if len(ans) < len(aans): aans = ans print(len(aans)) print(*aans) ```
output
1
81,828
3
163,657
Provide tags and a correct Python 3 solution for this coding contest problem. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
instruction
0
81,829
3
163,658
Tags: greedy Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def main(): n,m=map(int,input().split()) a=[list(map(int,input().split())) for _ in range(m)] c=list(map(lambda x:x[-1],a)) z=sum(c) mi=[0]*(n+1) for i in range(n-1): b=[] for j in range(m): b.append(a[j][i]) d=sorted(range(m),key=lambda x:c[x]-b[x],reverse=True) x,y=sum(b),z if x>=y: mi=[] continue e=[] for j in range(m): x-=b[d[j]] y-=c[d[j]] e.append(d[j]+1) if x>=y: if len(mi)>len(e): mi=e break print(len(mi)) print(*mi) # region fastio 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") if __name__ == "__main__": main() ```
output
1
81,829
3
163,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` n , m = map(int,input().split()) ll = [[] for i in range(n-1)] for i in range(m): a =list(map(int,input().split())) for j in range(n-1): ll[j].append([a[-1]-a[j],i]) mi=10000000 for l in ll: l.sort() s=sum([l[j][0] for j in range(m)]) temp=[] j=1 while s>0: temp.append(l[-j][1]) s-=l[-j][0] j+=1 if len(temp)<mi: mi=len(temp) ans=temp[:] print(mi) print(*[i+1 for i in ans]) ```
instruction
0
81,830
3
163,660
Yes
output
1
81,830
3
163,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` n, m = map(int, input().split()) sum_votes = [0] * n diffs = [[] for _ in range(n-1)] for i in range(m): votes = list(map(int, input().split())) for j in range(n-1): sum_votes[j] += votes[j] diffs[j].append(votes[n-1] - votes[j]) sum_votes[n-1] += votes[n-1] sum_diffs = [] for i in range(n-1): sum_diffs.append(sum_votes[n-1] - sum_votes[i]) k = m for i in range(n-1): count_diff = 0 cur_diffs_idxs = sorted(range(m), key=lambda k: diffs[i][k], reverse = True) j = 0 while j < m and count_diff < sum_diffs[i]: count_diff += diffs[i][cur_diffs_idxs[j]] j += 1 if j < k: k = j temp_ans = cur_diffs_idxs[:j] print(k) if k == m: print(*[i+1 for i in range(m)]) else: print(*[i+1 for i in temp_ans]) """ Пример 1: 1 10 1 9 8 -1 8 1 5 5 8 7 3 3 1 1 1 1 0 0 0 = = = = = = = 3 16 7 18 15 2 11 Пример 2: 10 5 10 10 5 10 10 5 10 1 6 5 1 6 5 = = = 32 27 40 """ ```
instruction
0
81,831
3
163,662
Yes
output
1
81,831
3
163,663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` n, m = [int(x) for x in input().split()] mat = [] for i in range(m): a = [int(x) for x in input().split()] a = [a[-1] - x for x in a] a[len(a)-1] = i+1 mat.append(a) minimum = [m, [x for x in range(1, m+1)]] prt = False for i in range(n-1): cnt=0 mat.sort(key=lambda x: x[i]) sums=0 for j in range(m): sums+=mat[j][i] if sums<=0: cnt+=1 else: if minimum[0] > m - cnt: minimum[0]=m - cnt cand = [] for k in range(j, m): cand.append(mat[k][-1]) minimum[1] = cand break if cnt == m: prt = True break if prt: print (0) else: print (minimum[0]) print (*minimum[1]) ```
instruction
0
81,832
3
163,664
Yes
output
1
81,832
3
163,665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools,itertools,operator,bisect,fractions,statistics from collections import deque,defaultdict,OrderedDict,Counter from fractions import Fraction from decimal import Decimal from sys import stdout from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest # sys.setrecursionlimit(111111) def main(): mod=998244353 # InverseofNumber(mod) # InverseofFactorial(mod) # factorial(mod) starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") tc=1 for _ in range(tc): n,m=ria() z=[] for i in range(m): z.append([ria(),i+1]) ans=[0]*105 for i in range(n-1): votesi=0 votesn=0 for j in range(m): votesi+=z[j][0][i] votesn+=z[j][0][n-1] tz=z.copy() tans=[] while votesi<votesn: maxdiff=0 for j in range(len(tz)): diff=tz[j][0][n-1]-tz[j][0][i] if diff>maxdiff: maxdiff=diff inddel=j tans.append(tz[inddel][1]) del tz[inddel] votesi=0 votesn=0 for j in range(len(tz)): votesi+=tz[j][0][i] votesn+=tz[j][0][n-1] if len(tans)<len(ans): ans=tans wi(len(ans)) wia(ans) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main() ```
instruction
0
81,833
3
163,666
Yes
output
1
81,833
3
163,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` from collections import defaultdict d=defaultdict(list) n,m=map(int,input().split()) for i in range(m): l=list(map(int,input().split())) for j in range(len(l)-1): d[j].append((l[-1]-l[j],i)) ind=[i+1 for i in range(m)] minl=m for j in range(n-1): temp=[] d[j].sort(reverse=True) s=0 for p in range(len(d[j])): s+=d[j][p][0] k=-1 while(s>0): k+=1 s-=d[j][k][0] temp.append(d[j][k][1]+1) if len(temp)<m: ind=temp minl=len(temp) print(len(ind)) print(*ind) ```
instruction
0
81,834
3
163,668
No
output
1
81,834
3
163,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` s = input().split(" ") n = int(s[0]) m = int(s[1]) stations = [] overall = [0] * n for i in range(m): ints = input().split(" ") station = [0] * n for i in range(n): station[i] = int(ints[i]) overall[i] += int(ints[i]) stations.append(station) canceled = 0 canceled_stations = [] for i in range(m): current_opp = stations[i][n - 1] current_max = max(stations[i][0:(n - 1)]) if current_opp <= current_max: continue current_result = [0] * n for j in range(n): current_result[j] = overall[j] - stations[i][j] opp = current_result[n - 1] overall_opp = overall[n - 1] if opp < overall_opp: canceled_stations.append(i + 1) overall = current_result print(len(canceled_stations)) sts = "" for i in range(len(canceled_stations)): sts += str(canceled_stations[i]) + " " print(sts) ```
instruction
0
81,835
3
163,670
No
output
1
81,835
3
163,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` n, m = [int(x) for x in input().split()] mat = [] for i in range(m): a = [int(x) for x in input().split()] a = [a[-1] - x for x in a] a[len(a)-1] = i+1 mat.append(a) minimum = [m, [x for x in range(1, m+1)]] print (minimum) prt = False for i in range(n-1): cnt=0 mat.sort(key=lambda x: x[i]) sums=0 for j in range(m): sums+=mat[j][i] if sums<=0: cnt+=1 else: if minimum[0] > m - cnt: minimum[0]=m - cnt cand = [] for k in range(j, m): cand.append(mat[k][-1]) minimum[1] = cand break if cnt == m: prt = True break if prt: print (0) else: print (minimum[0]) print (*minimum[1]) ```
instruction
0
81,836
3
163,672
No
output
1
81,836
3
163,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000). Output In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Output 2 3 1 Input 2 1 1 1 Output 0 Input 3 3 2 3 8 4 2 9 3 1 7 Output 3 1 2 3 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. Submitted Solution: ``` import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools,itertools,operator,bisect,fractions,statistics from collections import deque,defaultdict,OrderedDict,Counter from fractions import Fraction from decimal import Decimal from sys import stdout from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest # sys.setrecursionlimit(111111) def main(): mod=998244353 # InverseofNumber(mod) # InverseofFactorial(mod) # factorial(mod) starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") tc=1 for _ in range(tc): n,m=ria() z=[] for i in range(m): z.append([ria(),i+1]) ans=[0]*100 for i in range(n-1): votesi=0 votesn=0 for j in range(m): votesi+=z[j][0][i] votesn+=z[j][0][n-1] tz=z.copy() tans=[] while votesi<votesn: maxdiff=0 for j in range(len(tz)): diff=tz[j][0][n-1]-tz[j][0][i] if diff>maxdiff: maxdiff=diff inddel=j tans.append(tz[inddel][1]) del tz[inddel] votesi=0 votesn=0 for j in range(len(tz)): votesi+=tz[j][0][i] votesn+=tz[j][0][n-1] if len(tans)<len(ans): ans=tans wi(len(ans)) wia(ans) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main() ```
instruction
0
81,837
3
163,674
No
output
1
81,837
3
163,675
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,146
3
164,292
Tags: binary search, geometry, math Correct Solution: ``` # import sys # sys.stdin = open('cf591d.in') x1, y1, x2, y2 = map(int, input().split()) vmax, t = map(int, input().split()) vx, vy = map(int, input().split()) wx, wy = map(int, input().split()) c1x = x1 + vx * t c1y = y1 + vy * t r1 = t * vmax if (c1x - x2)**2 + (c1y - y2)**2 <= r1**2: # can get before wind changes t1l, t1r = 0, t itr = 0 while t1r - t1l > 1e-10 and itr < 200: itr += 1 # build first circle t1 = (t1l + t1r) / 2 cc1x = x1 + vx * t1 cc1y = y1 + vy * t1 rr1 = t1 * vmax if ((cc1x - x2)**2 + (cc1y - y2)**2) <= rr1**2: t1r = t1 else: t1l = t1 print(t1) else: t2l, t2r = 0, 200000000 itr = 0 while t2r - t2l > 1e-10 and itr < 200: itr += 1 # build second circle t2 = (t2l + t2r) / 2 c2x = x2 - wx * t2 c2y = y2 - wy * t2 r2 = t2 * vmax # check for intersection if ((c1x - c2x)**2 + (c1y - c2y)**2) <= (r1 + r2)**2: t2r = t2 else: t2l = t2 print(t + t2) ```
output
1
82,146
3
164,293
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,147
3
164,294
Tags: binary search, geometry, math Correct Solution: ``` f = lambda: list(map(int, input().split())) abs = lambda q: q[0] * q[0] + q[1] * q[1] dot = lambda: v[0] * d[0] + v[1] * d[1] get = lambda a, b, c: (b - (b * b - a * c) ** 0.5) / a p = f() d = [p[k + 2] - p[k] for k in [0, 1]] v, t = f() s = v * v v = f() i = get(abs(v) - s, dot(), abs(d)) d = [d[k] - t * v[k] for k in (0, 1)] v = f() j = get(abs(v) - s, dot() + t * s, abs(d) - t * t * s) print(i if i < t else t + j) # Made By Mostafa_Khaled ```
output
1
82,147
3
164,295
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,148
3
164,296
Tags: binary search, geometry, math Correct Solution: ``` import sys import math read = lambda: list(map(int, sys.stdin.readline().split())) x1, y1, x2, y2 = read() vmax, t1 = read() vx, vy = read() wx, wy = read() # Translate and scale x2, y2 = (x2-x1)/vmax, (y2-y1)/vmax vx, vy, wx, wy = vx/vmax, vy/vmax, wx/vmax, wy/vmax lo, up = 0, 10**9 for _ in range(100): t = (lo + up)/2 x = x2 - min(t,t1)*vx - max(t-t1,0)*wx y = y2 - min(t,t1)*vy - max(t-t1,0)*wy if x**2 + y**2 <= t**2: up = t else: lo = t print(up) ```
output
1
82,148
3
164,297
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,149
3
164,298
Tags: binary search, geometry, math Correct Solution: ``` from math import sqrt import re class point2: def __init__(self, x, y): self.x = x self.y = y def length(self): return sqrt(self.x * self.x + self.y * self.y) def xmult(a, b): return a.x * b.y - a.y * b.x def dmult(a, b): return a.x * b.x + a.y * b.y x1, y1, x2, y2 = map(float, re.split("\ +", input().strip())) v, t = map(float, re.split("\ +", input().strip())) vx, vy = map(float, re.split("\ +", input().strip())) wx, wy = map(float, re.split("\ +", input().strip())) if x1 == x2 and y1 == y2: print(0) exit() u = point2(vx, vy) w = point2(wx, wy) d = point2(x2 - x1, y2 - y1) l = d.length() h = xmult(d, u) / d.length() s = dmult(d, u) / d.length() v1 = sqrt(v * v - h * h) + s t1 = d.length() / v1 if t1 <= t: print(t1) else: x1 = x1 + t * u.x y1 = y1 + t * u.y l, r = 0.0, 1e9 while r - l > 1e-7: mid = (l + r) / 2 _x1, _y1 = x1 + mid * w.x, y1 + mid * w.y d = point2(x2 - _x1, y2 - _y1).length() if d < (mid + t) * v: r = mid else: l = mid print(l + t) ```
output
1
82,149
3
164,299
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,150
3
164,300
Tags: binary search, geometry, math Correct Solution: ``` x1, y1, x2, y2 = map(float, input().split()) vMax, t = map(float, input().split()) vx, vy = map(float, input().split()) wx, wy = map(float, input().split()) def is_pos2(t1, t2): x1_n = x1+ vx*t1 y1_n = y1+ vy*t1 x2_n = x2- wx*t2 y2_n = y2- wy*t2 return (x1_n-x2_n)**2 + (y1_n-y2_n)**2 <= (vMax * (t1+t2))**2 def is_pos(tSum): t1 = min(t, tSum) t2 = max(0, tSum - t) return is_pos2(t1, t2) if x1 == x2 and y1 == y2: print (0) else: minT = ((x1-x2)**2 + (y1-y2)**2)**0.5 / (vMax * 3) vabs = (vx ** 2 + vy ** 2)**0.5 wabs = (wx ** 2 + wy ** 2)**0.5 maxT = ((x1-x2)**2 + (y1-y2)**2)**0.5 / (vMax - max(vabs, wabs)) while (maxT - minT)/maxT > 10 ** -7: medT = (maxT + minT) / 2 if is_pos(medT): maxT = medT else: minT = medT print ((minT + maxT) / 2) ```
output
1
82,150
3
164,301