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. Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction. More specifically, in one move, he can go from coordinate x to x + D or x - D. He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible. Find the minimum possible absolute value of the coordinate of the destination. Constraints * -10^{15} \leq X \leq 10^{15} * 1 \leq K \leq 10^{15} * 1 \leq D \leq 10^{15} * All values in input are integers. Input Input is given from Standard Input in the following format: X K D Output Print the minimum possible absolute value of the coordinate of the destination. Examples Input 6 2 4 Output 2 Input 7 4 3 Output 1 Input 10 1 2 Output 8 Input 1000000000000000 1000000000000000 1000000000000000 Output 1000000000000000 Submitted Solution: ``` x,k,d = input().split() x = int(x) k = int(k) d = int(d) ans = 0 if abs(x) >= abs(k*d): ans = abs(x) - abs(k*d) else: kaisuu = abs(x)/d k_2 = k - kaisuu if k_2/2 == 0: ans = abs(x) - d*kaisuu else: ans = abs((abs(x) - d*kaisuu) - abs(d)) print(int(ans)) ```
instruction
0
77,355
3
154,710
No
output
1
77,355
3
154,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` def solve(): n = int(input()) points = [] x = input() x = [int(i) for i in x.split(' ')] for i in x: points.append([i, 0]) y = input() y = [int(i) for i in y.split(' ')] for i, v in enumerate(y): points[i][1] = v points.sort() ans = 0 start = [1, 1] for x, y in points: a, b = start if x - y == a - b: if (a - b) % 2 == 0: ans += y - b else: ans += (x - y) // 2 - (a - b) // 2 start = [x, y] print(ans) def main(): t = int(input()) while t: solve() t -= 1 if __name__ == '__main__': main() ```
instruction
0
77,745
3
155,490
Yes
output
1
77,745
3
155,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase class FastIO(IOBase): newlines = 0 BUFSIZE = 8192 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, self.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, self.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 read_int_list(): return list(map(int, input().split())) def read_int_tuple(): return tuple(map(int, input().split())) def read_int(): return int(input()) # Problem t = read_int() for _ in range(t): n = read_int() r = read_int_list() c = read_int_list() points = [] for ri, ci in zip(r, c): ri -= 1 ci -= 1 points.append((ri - ci, ci)) points.sort() total = 0 r, c = 0, 0 for rp, cp in points: total += (rp - r) // 2 if rp % 2 == 0 and r % 2 == 1: total += 1 if rp == r and rp % 2 == 0: total += cp-c r, c = rp, cp print(total) ```
instruction
0
77,746
3
155,492
Yes
output
1
77,746
3
155,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` import sys # sys.stdin = open('input.txt','r') input = sys.stdin.readline def calcDist(r1, c1, r2, c2): if r1 - c1 == r2 - c2: return r2 - r1 if (r1 + c1) % 2 == 0 else 0 r2 -= r1 - 1 c2 -= c1 - 1 return (r2 - c2) // 2 if (r1 + c1) % 2 == 0 else (r2 - c2 + 1) // 2 for _ in range(int(input())): n = int(input()) r = list(map(int, input().split())) c = list(map(int, input().split())) p = [(x, y) for x, y in zip(r, c)] p.sort() ans = 0 lastX, lastY = 1, 1 for x, y in p: ans += calcDist(lastX, lastY, x, y) lastX, lastY = x, y print(ans) ```
instruction
0
77,747
3
155,494
Yes
output
1
77,747
3
155,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` for _ in range(int(input())): input() r = list(map(int, input().split())) c = list(map(int, input().split())) a = [(1, 1)] + sorted((x, x + 1 - y) for x, y in zip(r, c)) if a[0] == a[1]: a = a[1:] ans = 0 for (x, y), (nx, ny) in zip(a, a[1:]): assert x < nx and y <= ny and ny - y <= nx - x if y == ny and y % 2: ans += nx - x else: ans += (ny + 1) // 2 - (y + 1) // 2 print(ans) ```
instruction
0
77,748
3
155,496
Yes
output
1
77,748
3
155,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` for z in range(int(input())): n=int(input()) r=list(map(int,input().split())) c=list(map(int,input().split())) a=[] b=0 a1=0 for i in range(n): b=max(b,r[i]-c[i]) if (r[i]-c[i])%2==0: a.append([r[i]-c[i],r[i]]) a1+=1 b//=2 c=0 if a1!=0: a.sort() for i in range(1,len(a)): if a[i][0]!=a[i-1][0]: if a[i-1][0]==0: b+=a[i-1][1]-1 b+=a[i-1][1]-a[c][1] c=i b+=a[-1][1]-a[c][1] if a[-1][0]==0 and r[0]!=1: b+=a[-1][1]-1 print(b) ```
instruction
0
77,749
3
155,498
No
output
1
77,749
3
155,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` import math for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for i in range(n): c.append((a[i], b[i])) c.sort() if c[0] != (1, 1): c.insert(0, (1, 1)) cost = 0 for u in range(n - 1): p, q = c[u][0], c[u][1] r, s = c[u + 1][0], c[u + 1][1] if abs(p - q) == abs(r - s): if abs(p - q) % 2: continue else: cost += abs(p - r) else: x = abs(p - q) y = abs(r - s) if y % 2: cost += abs(x - y) // 2 else: cost += int(math.ceil(abs(x - y) / 2)) print(cost) ```
instruction
0
77,750
3
155,500
No
output
1
77,750
3
155,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` def is_odd(r, c): return ((r-c) & 1) == 1 def is_even(r, c): return ((r-c) & 1) == 0 def calculateCost(r1, c1, r2, c2): if(r1-c1 == r2-c2): return r2-r1 if is_even(r1,c1) else 0 r2 -= r1 - 1 c2 -= c1 - 1 return (r2-c2) // 2 if is_odd(r2, c2) else (r2 - c2 + 1) // 2 def solve(): n = int(input()) r = input().split(' ') c = input().split(' ') points = list(zip(r, c)) points.sort(key= lambda x : x[0]) curc = 1 curr = 1 res = 0 for point in points: nextr = int(point[0]) nextc = int(point[1]) res += calculateCost(curr, curc, nextr, nextc) curr = nextr curc = nextc print(f'{res}\n') def main(): t = int(input()) while(t > 0): solve() t -= 1 if __name__ == '__main__' : main() ```
instruction
0
77,751
3
155,502
No
output
1
77,751
3
155,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r is the number of the layer, and c is the number of the point in the layer. From each point (r, c) there are two directed edges to the points (r+1, c) and (r+1, c+1), but only one of the edges is activated. If r + c is even, then the edge to the point (r+1, c) is activated, otherwise the edge to the point (r+1, c+1) is activated. Look at the picture for a better understanding. <image> Activated edges are colored in black. Non-activated edges are colored in gray. From the point (r_1, c_1) it is possible to reach the point (r_2, c_2), if there is a path between them only from activated edges. For example, in the picture above, there is a path from (1, 1) to (3, 2), but there is no path from (2, 1) to (1, 1). Initially, you are at the point (1, 1). For each turn, you can: * Replace activated edge for point (r, c). That is if the edge to the point (r+1, c) is activated, then instead of it, the edge to the point (r+1, c+1) becomes activated, otherwise if the edge to the point (r+1, c+1), then instead if it, the edge to the point (r+1, c) becomes activated. This action increases the cost of the path by 1; * Move from the current point to another by following the activated edge. This action does not increase the cost of the path. You are given a sequence of n points of an infinite triangle (r_1, c_1), (r_2, c_2), …, (r_n, c_n). Find the minimum cost path from (1, 1), passing through all n points in arbitrary order. Input The first line contains one integer t (1 ≤ t ≤ 10^4) is the number of test cases. Then t test cases follow. Each test case begins with a line containing one integer n (1 ≤ n ≤ 2 ⋅ 10^5) is the number of points to visit. The second line contains n numbers r_1, r_2, …, r_n (1 ≤ r_i ≤ 10^9), where r_i is the number of the layer in which i-th point is located. The third line contains n numbers c_1, c_2, …, c_n (1 ≤ c_i ≤ r_i), where c_i is the number of the i-th point in the r_i layer. It is guaranteed that all n points are distinct. It is guaranteed that there is always at least one way to traverse all n points. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output the minimum cost of a path passing through all points in the corresponding test case. Example Input 4 3 1 4 2 1 3 1 2 2 4 2 3 2 1 1000000000 1 1000000000 4 3 10 5 8 2 5 2 4 Output 0 1 999999999 2 Submitted Solution: ``` t = int(input()) for _ in range(t): n = int(input()) rs = list(map(int, input().split())) cs = list(map(int, input().split())) sums = [] special = [] levels = dict() levels[0] = [2] for i in range(n): diff = rs[i] - cs[i] if diff not in levels: levels[diff] = [rs[i] + cs[i]] else: levels[diff].append(rs[i] + cs[i]) levels[diff] = sorted(levels[diff]) res = 0 even_levels = dict() odd_levels = dict() for k, v in levels.items(): if k % 2 == 0: even_levels[k] = v else: odd_levels[k] = v for k, v in even_levels.items(): if len(v) > 1: res += (v[-1] - v[0]) / 2 keys = list(levels.keys()) for i in range(len(levels.keys()) - 1): if keys[i] % 2 != 0 and keys[i + 1] % 2 != 0: res += (keys[i + 1] - keys[i]) / 2 if keys[i] % 2 != 0 and keys[i + 1] % 2 == 0: res += (keys[i + 1] - keys[i] + 1) / 2 if keys[i] % 2 == 0 and keys[i + 1] % 2 != 0: res += (keys[i + 1] - keys[i] - 1) / 2 if keys[i] % 2 == 0 and keys[i + 1] % 2 == 0: res += (keys[i + 1] - keys[i]) / 2 print(int(res)) ```
instruction
0
77,752
3
155,504
No
output
1
77,752
3
155,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the town of Aalam-Aara (meaning the Light of the Earth), previously there was no crime, no criminals but as the time progressed, sins started creeping into the hearts of once righteous people. Seeking solution to the problem, some of the elders found that as long as the corrupted part of population was kept away from the uncorrupted part, the crimes could be stopped. So, they are trying to set up a compound where they can keep the corrupted people. To ensure that the criminals don't escape the compound, a watchtower needs to be set up, so that they can be watched. Since the people of Aalam-Aara aren't very rich, they met up with a merchant from some rich town who agreed to sell them a land-plot which has already a straight line fence AB along which a few points are set up where they can put up a watchtower. Your task is to help them find out the number of points on that fence where the tower can be put up, so that all the criminals can be watched from there. Only one watchtower can be set up. A criminal is watchable from the watchtower if the line of visibility from the watchtower to him doesn't cross the plot-edges at any point between him and the tower i.e. as shown in figure 1 below, points X, Y, C and A are visible from point B but the points E and D are not. <image> Figure 1 <image> Figure 2 Assume that the land plot is in the shape of a polygon and coordinate axes have been setup such that the fence AB is parallel to x-axis and the points where the watchtower can be set up are the integer points on the line. For example, in given figure 2, watchtower can be setup on any of five integer points on AB i.e. (4, 8), (5, 8), (6, 8), (7, 8) or (8, 8). You can assume that no three consecutive points are collinear and all the corner points other than A and B, lie towards same side of fence AB. The given polygon doesn't contain self-intersections. Input The first line of the test case will consist of the number of vertices n (3 ≤ n ≤ 1000). Next n lines will contain the coordinates of the vertices in the clockwise order of the polygon. On the i-th line are integers xi and yi (0 ≤ xi, yi ≤ 106) separated by a space. The endpoints of the fence AB are the first two points, (x1, y1) and (x2, y2). Output Output consists of a single line containing the number of points where the watchtower can be set up. Examples Input 5 4 8 8 8 9 4 4 0 0 4 Output 5 Input 5 4 8 5 8 5 4 7 4 2 2 Output 0 Note Figure 2 shows the first test case. All the points in the figure are watchable from any point on fence AB. Since, AB has 5 integer coordinates, so answer is 5. For case two, fence CD and DE are not completely visible, thus answer is 0. Submitted Solution: ``` import sys def main(): # Get values from input n = int(input()) x, y = [ 0 for _ in range(n) ], [ 0 for _ in range(n) ] for i in range(n): x[i], y[i] = list(map(int, input().split())) # Determine point B is on the left of point A flip = x[0] < x[1] x_, y_ = x[1], y[1] for i in range(n): # Translate all points to make point B the origin x[i] -= x_ y[i] -= y_ # If point A is on the left of point B, flip the polygon if flip: x[i] *= -1 y[i] *= -1 # Set bounds along BA to determine interval of the solution lower, upper = 0, x[0] for i in range(2,n-1): # Cross Product to determine edge relation to the solution interval cu = (x[i+1]-x[i])*(y[0]-y[i]) - (x[0]-x[i])*(y[i+1]-y[i]) cl = (x[i+1]-x[i])*(y[1]-y[i]) - (x[1]-x[i])*(y[i+1]-y[i]) # No point on the edge can be seen on the solution interval if cu > 0 and cl > 0: print(0) sys.exit() # Adjust the Interval based on edge lines x0, y0, x1, y1 = x[i], y[i], x[i+1], y[i+1] if cu > 0 or cl > 0: p = x0*(y1-y0) - y0*(x1-x0) q = y1-y0 if q < 0: p *= -1 q *= -1 if cu > 0: upper = min(upper, p//q) else: lower = max(lower, -(-(p+q)//q)) # Solution is found print(upper-lower+1) if (lower <= upper) else print(0) if __name__ == "__main__": main() ```
instruction
0
77,921
3
155,842
No
output
1
77,921
3
155,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Modern researches has shown that a flock of hungry mice searching for a piece of cheese acts as follows: if there are several pieces of cheese then each mouse chooses the closest one. After that all mice start moving towards the chosen piece of cheese. When a mouse or several mice achieve the destination point and there is still a piece of cheese in it, they eat it and become well-fed. Each mice that reaches this point after that remains hungry. Moving speeds of all mice are equal. If there are several ways to choose closest pieces then mice will choose it in a way that would minimize the number of hungry mice. To check this theory scientists decided to conduct an experiment. They located N mice and M pieces of cheese on a cartesian plane where all mice are located on the line y = Y0 and all pieces of cheese — on another line y = Y1. To check the results of the experiment the scientists need a program which simulates the behavior of a flock of hungry mice. Write a program that computes the minimal number of mice which will remain hungry, i.e. without cheese. Input The first line of the input contains four integer numbers N (1 ≤ N ≤ 105), M (0 ≤ M ≤ 105), Y0 (0 ≤ Y0 ≤ 107), Y1 (0 ≤ Y1 ≤ 107, Y0 ≠ Y1). The second line contains a strictly increasing sequence of N numbers — x coordinates of mice. Third line contains a strictly increasing sequence of M numbers — x coordinates of cheese. All coordinates are integers and do not exceed 107 by absolute value. Output The only line of output should contain one number — the minimal number of mice which will remain without cheese. Examples Input 3 2 0 2 0 1 3 2 5 Output 1 Note All the three mice will choose the first piece of cheese. Second and third mice will eat this piece. The first one will remain hungry, because it was running towards the same piece, but it was late. The second piece of cheese will remain uneaten. Submitted Solution: ``` import sys import math import itertools def solve(ma, ca): i = 0 j = 0 best_cheese = [None] * len(ma) hungry = 0 while i < len(ma): if ma[i] <= ca[j]: if ( best_cheese[i] is None or abs(ca[j] - ma[i]) < abs(ca[best_cheese[i]] - ma[i]) or ( abs(ca[j] - ma[i]) == abs(ca[best_cheese[i]] - ma[i]) and i - 1 >= 0 and best_cheese[i - 1] == best_cheese[i] ) ): best_cheese[i] = j i += 1 else: best_cheese[i] = j if j + 1 < len(ca): j += 1 else: i += 1 # print('best_cheese:', best_cheese) for i in range(1, len(ma)): if ( best_cheese[i] == best_cheese[i - 1] and abs(ma[i] - ca[best_cheese[i]]) != abs(ma[i - 1] - ca[best_cheese[i]]) ): hungry += 1 return hungry if __name__ == '__main__': n, m, _, _ = map(int, input().split()) ma = list(map(int, input().split())) ca = list(map(int, input().split())) print(solve(ma, ca)) ```
instruction
0
77,928
3
155,856
No
output
1
77,928
3
155,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` __author__ = 'RaldenProg' x1 = int(input()) x2 = int(input()) y1 = 0 y2 = 0 z1 = 0 z2 = 0 while x1 != x2: if x1 < x2: x1 += 1 y1 += 1 z1 += y1 if x1 < x2: x2 -= 1 y2 -= 1 z2 -= y2 if x2 < x1: x2 += 1 y2 += 1 z2 += y2 if x2 < x1: x1 -= 1 y1 -= 1 z1 -= y1 print(z1+z2) ```
instruction
0
77,975
3
155,950
Yes
output
1
77,975
3
155,951
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` import math a=int(input()) b=int(input()) c=abs(a-b) if c%2==0: d=c/2 e=(d*(d+1)) print(int(e)) else: t=(c-1)/2 h=t+1 f=(t*(t+1))/2 i=(h*(h+1))/2 print(int(f+i)) ```
instruction
0
77,976
3
155,952
Yes
output
1
77,976
3
155,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` a = int(input()) b = int(input()) d = abs(a - b) n = d // 2 if d % 2 == 0: solution = n * ((n+1) / 2) * 2 else: solution = n * ((n+1) / 2) * 2 + n + 1 print(int(solution)) ```
instruction
0
77,977
3
155,954
Yes
output
1
77,977
3
155,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` a = int(input()) b = int(input()) d = abs(a-b) if d == 1: print(1) else: if d%2 == 1: n = d // 2 s1 = (n*(n+1)) // 2 s2 = ((n+1)*(n+2)) // 2 print(s1+s2) else: n = d // 2 s1 = (n*(n+1)) // 2 print(s1+s1) ```
instruction
0
77,978
3
155,956
Yes
output
1
77,978
3
155,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` a,b=int(input()),int(input()) c=max(a,b)-min(a,b) if c<=2: print(c) exit() x=c//2 s=0 for i in range(x+2): s+=i s=(s*2)-x-2 print(s) ```
instruction
0
77,979
3
155,958
No
output
1
77,979
3
155,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` a=int(input()) b=int(input()) c=abs(b-a) y=c//2 z=c%2+y print(y,z) print((y*(y+1))//2+(z*(z+1))//2) ```
instruction
0
77,980
3
155,960
No
output
1
77,980
3
155,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` a = int(input()) b = int(input()) s = min(a,b) l = max(a,b) d = l-s t = 0 for i in range(1,d+1): s+=1 t+=i if(l-s!=0): l=l-1 t+=i else: break print(t) ```
instruction
0
77,981
3
155,962
No
output
1
77,981
3
155,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b. Output Print the minimum possible total tiredness if the friends meet in the same point. Examples Input 3 4 Output 1 Input 101 99 Output 2 Input 5 10 Output 9 Note In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. Submitted Solution: ``` import math a = int (input()) b = int (input()) s = math.fabs(b-a ) r = s/2 s = int(s) r = int(r) t = 0 n =0 f = 0 e = r+1 w =0 q = 0 if s%2!=0: for i in range(r): n+=i+1 for j in range(r+1): t+= j+1 print(n+t) if s%2==0: if s == 0: print("0") for i in range(r): n+=i+1 print(n*2) ```
instruction
0
77,982
3
155,964
No
output
1
77,982
3
155,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` n, x = map(int, input().split()) a = max(n-x, x); b = min(n-x, x) res = n while b!=0: p=a; q=int(a/b); r=a%b res+=q*(2*b) if r==0: res-=b a=b; b=r print(res) ```
instruction
0
78,167
3
156,334
Yes
output
1
78,167
3
156,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` N,X=map(int,input().split()) A=N X,N = sorted((X,N-X)) while N != X and X != 0: if N%X == 0: A += 2*(N//X-1)*X X,N=X,X else: A += 2*(N//X)*X X,N=sorted((X,N%X)) print(A+X) ```
instruction
0
78,168
3
156,336
Yes
output
1
78,168
3
156,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` from fractions import gcd n, k = map(int, input().split(' ')) print(3*(n-gcd(n, k))) ```
instruction
0
78,169
3
156,338
Yes
output
1
78,169
3
156,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, x = map(int, input().split()) n -= x res = 0 while x != 0: q, r = divmod(n, x) res += q * x * 3 n = x x = r print(res) if __name__ == '__main__': resolve() ```
instruction
0
78,170
3
156,340
Yes
output
1
78,170
3
156,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` n,x=map(int,input().strip().split()) y=n-x an=y+x*3+x/2*3 print(an) ```
instruction
0
78,171
3
156,342
No
output
1
78,171
3
156,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` #! /usr/bin/env python3 def f(a, b): b, a = sorted((a, b)) r = b*3*(a//b) if a%b != 0: r += f(b, a-b) return r N, X = map(int, input().split()) print(f(X, N-X)) ```
instruction
0
78,172
3
156,344
No
output
1
78,172
3
156,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` def compute(n, x): quo = n // x rem = n % x if rem is 0: if n < 2*x: return (n - 1) * 3 else: return (2*quo - 1) * x else: if n % (n - x) is 0: return compute(n, n - x) else: return (2*quo - 1) * x + (n - x) + compute(x, rem) n, x = map(int, input().split()) print(compute(n, x)) ```
instruction
0
78,173
3
156,346
No
output
1
78,173
3
156,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc. The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed. The following image shows the ray's trajectory where N = 5 and X = 2. btriangle.png It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory. Constraints * 2≦N≦10^{12} * 1≦X≦N-1 * N and X are integers. Input The input is given from Standard Input in the following format: N X Output Print the total length of the ray's trajectory. Example Input 5 2 Output 12 Submitted Solution: ``` import math n, x = map(int, input().split()) print(3 * (n - gcd(n, x))) ```
instruction
0
78,174
3
156,348
No
output
1
78,174
3
156,349
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,191
3
156,382
"Correct Solution: ``` for e in iter(input,'0'): a=list(tuple(map(int,input().split())) for _ in range(int(e))) s,t=a[0] b={tuple(map(int,input().split())) for _ in range(int(input()))} for x,y in b: flag = True for u,v in a[1:]: if(x+u-s,y+v-t)not in b: flag = False break if flag == True: print(x - s, y - t) break ```
output
1
78,191
3
156,383
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,192
3
156,384
"Correct Solution: ``` while True: m = int(input()) if m == 0: break star = list({tuple(map(int, input().split())) for i in range(m)}) sx, sy = star[0] n = int(input()) starset = {tuple(map(int, input().split())) for i in range(n)} for x, y in starset: flag = True for j in range(len(star)-1): dx = x + star[j+1][0] - sx dy = y + star[j+1][1] - sy if (dx, dy) not in starset: flag = False break if flag == True: print(x - sx, y - sy) break ```
output
1
78,192
3
156,385
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,193
3
156,386
"Correct Solution: ``` def f(e): a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0]) b=sorted([list(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0]) for s,t in b: u,v=a[0] x,y=s-u,t-v for u,v in a: if[u+x,v+y]not in b:break else:return print(x,y) for e in iter(input,'0'):f(e) ```
output
1
78,193
3
156,387
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,194
3
156,388
"Correct Solution: ``` for e in iter(input,'0'): a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0]) b=sorted([list(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0]) for s,t in b: u,v=a[0] x,y=s-u,t-v for u,v in a: if[u+x,v+y]not in b:break else:print(x,y) ```
output
1
78,194
3
156,389
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,195
3
156,390
"Correct Solution: ``` def f(e): a=[list(map(int,input().split()))for _ in[0]*int(e)] b=[list(map(int,input().split()))for _ in[0]*int(input())] for s,t in b: u,v=a[0] x,y=s-u,t-v for u,v in a: if[u+x,v+y]not in b:break else:return print(x,y) for e in iter(input,'0'):f(e) ```
output
1
78,195
3
156,391
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,196
3
156,392
"Correct Solution: ``` def f(e): a=[[*map(int,input().split())]for _ in[0]*int(e)] s,t=min(a) b={tuple(map(int,input().split()))for _ in[0]*int(input())} m=max(b)[0]-max(a)[0]+s for x,y in b: if x<=m: for u,v in a: if(x+u-s,y+v-t)not in b:break else:print(x-s,y-t);break for e in iter(input,'0'):f(e) ```
output
1
78,196
3
156,393
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,197
3
156,394
"Correct Solution: ``` import operator for e in iter(input,'0'): target = [[*map(int,input().split())]for _ in[0]*int(e)] s,t = min(target) target = {(x - s, y - t) for x, y in target} max_tx = max(target)[0] b = {tuple(map(int,input().split()))for _ in[0]*int(input())} max_sx = max(map(operator.itemgetter(0), b)) lim_x = max_sx - max_tx for x,y in b: if x > lim_x:continue for u,v in target: if (x + u, y + v) not in b:break else: print(x - s, y - t) break ```
output
1
78,197
3
156,395
Provide a correct Python 3 solution for this coding contest problem. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None
instruction
0
78,198
3
156,396
"Correct Solution: ``` for e in iter(input,'0'): a=list({tuple(map(int, input().split())) for i in range(int(e))}) s,t=a[0] b={tuple(map(int, input().split())) for i in range(int(input()))} for x,y in b: flag = True for u,v in a[1:]: if (x + u - s, y + v - t) not in b: flag = False break if flag == True: print(x - s, y - t) break ```
output
1
78,198
3
156,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` def f(e): a=list(tuple(map(int,input().split())) for _ in range(int(e))) s,t=a[0] b={tuple(map(int,input().split())) for _ in range(int(input()))} for x,y in b: for u,v in a[1:]: if(x+u-s,y+v-t)not in b:break else:return print(x-s,y-t) for e in iter(input,'0'):f(e) ```
instruction
0
78,199
3
156,398
Yes
output
1
78,199
3
156,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` # -*- coding: utf-8 -*- """ Searching Constellation http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0524 """ import sys def solve(targets, stars): for tx, ty in targets: for sx, sy in stars: dx, dy = sx-tx, sy-ty s_starts = set(stars) for x, y in targets: px, py = x+dx, y+dy if (px, py) in s_starts: s_starts.remove((px, py)) else: break else: return dx, dy def main(args): while True: m = int(input()) if m == 0: break targets = [tuple(int(x) for x in input().split()) for _ in range(m)] n = int(input()) stars = [tuple(int(x) for x in input().split()) for _ in range(n)] ans = solve(targets, stars) print(*ans) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
78,200
3
156,400
Yes
output
1
78,200
3
156,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` board = [[False]*1000001]*1000001 while True: m = int(input()) if m == 0: break star = tuple(tuple(map(int, input().split())) for i in range(m)) sx, sy = star[0] n = int(input()) starlist = [tuple(map(int, input().split())) for i in range(n)] for i in range(n): board[starlist[i][0]][starlist[i][1]] = True for i in range(n): flag = True for j in range(len(star)-1): dx = starlist[i][0] + star[j+1][0] - sx dy = starlist[i][1] + star[j+1][1] - sy if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx][dy] == False: flag = False break if flag == True: print("{} {}".format(starlist[i][0] - sx, starlist[i][1] -sy)) break ```
instruction
0
78,201
3
156,402
Yes
output
1
78,201
3
156,403
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` for e in iter(input,'0'): a=[list(map(int,input().split())) for _ in range(int(e))] s,t=a[0] b=[list(map(int,input().split())) for _ in range(int(input()))] for x,y in b: flag = True for u,v in a[1:]: if [x + u - s, y + v - t] not in b: flag = False break if flag == True: print(x - s, y - t) break ```
instruction
0
78,202
3
156,404
Yes
output
1
78,202
3
156,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` for e in iter(input,'0'): a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0]) b=sorted([tuple(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0]) print(a) print(b) for s,t in b: u,v=a[0] x,y=s-u,t-v if not set((u+x,v+y)for u,v in a)-set(b):print(x,y);break ```
instruction
0
78,203
3
156,406
No
output
1
78,203
3
156,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` def f(): for e in iter(input,'0'): a=[list(map(int,input().split()))for _ in[0]*int(m)] u,v=a[0] b=[tuple(map(int,input().split()))for _ in[0]*int(input())] for x,y in b: for s,t in a[1:]: if(x+s-u,y+t-v)not in b:return print(x-sx,y-sy) f() ```
instruction
0
78,204
3
156,408
No
output
1
78,204
3
156,409
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` def f(): for e in iter(input,'0'): a=[list(map(int,input().split()))for _ in[0]*int(e)] u,v=a[0] b=[tuple(map(int,input().split()))for _ in[0]*int(input())] for x,y in b: for s,t in a[1:]: if(x+s-u,y+t-v)not in b:return print(x-u,y-v) f() ```
instruction
0
78,205
3
156,410
No
output
1
78,205
3
156,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation. For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo. Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture. <image> | <image> --- | --- Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks. The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less. When m is 0, it indicates the end of input. The number of datasets does not exceed 5. output The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction. Examples Input 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 Output 2 -3 -384281 179674 Input None Output None Submitted Solution: ``` for e in iter(input,'0'): a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0]) b=sorted([list(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0]) for s,t in b: u,v=a[0] x,y=s-u,t-v for u,v in a: if[u+x,v+y]not in b:break else:print(x,y) ```
instruction
0
78,206
3
156,412
No
output
1
78,206
3
156,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, this sequence of integers tends to have similar values ​​before and after. Differential pulse code modulation uses this to encode the difference between the values ​​before and after and improve the compression rate. In this problem, we consider selecting the difference value from a predetermined set of values. We call this set of values ​​a codebook. The decrypted audio signal yn is defined by the following equation. > yn = yn --1 + C [kn] Where kn is the output sequence output by the program and C [j] is the jth value in the codebook. However, yn is rounded to 0 if the value is less than 0 by addition, and to 255 if the value is greater than 255. The value of y0 is 128. Your job is to select the output sequence so that the sum of squares of the difference between the original input signal and the decoded output signal is minimized given the input signal and the codebook, and the difference at that time. It is to write a program that outputs the sum of squares of. For example, if you compress the columns 131, 137 using a set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 4 = When compressed into the sequence 132, y2 = 132 + 4 = 136, the sum of squares becomes the minimum (131 --132) ^ 2 + (137 --136) ^ 2 = 2. Also, if you also compress the columns 131, 123 using the set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 1 = 129, y2 = 129 --4 = 125, and unlike the previous example, it is better not to adopt +2, which is closer to 131 (131 --129) ^ 2 + (123 --125) ^ 2 = 8, which is a smaller square. The sum is obtained. The above two examples are the first two examples of sample input. Input The input consists of multiple datasets. The format of each data set is as follows. > N M > C1 > C2 > ... > CM > x1 > x2 > ... > xN > The first line specifies the size of the input dataset. N is the length (number of samples) of the input signal to be compressed. M is the number of values ​​contained in the codebook. N and M satisfy 1 ≤ N ≤ 20000 and 1 ≤ M ≤ 16. The M line that follows is the description of the codebook. Ci represents the i-th value contained in the codebook. Ci satisfies -255 ≤ Ci ≤ 255. The N lines that follow are the description of the input signal. xi is the i-th value of a sequence of integers representing the input signal. xi satisfies 0 ≤ xi ≤ 255. The input items in the dataset are all integers. The end of the input is represented by a line consisting of only two zeros separated by a single space character. Output For each input data set, output the minimum value of the sum of squares of the difference between the original input signal and the decoded output signal in one line. Example Input 2 7 4 2 1 0 -1 -2 -4 131 137 2 7 4 2 1 0 -1 -2 -4 131 123 10 7 -4 -2 -1 0 1 2 4 132 134 135 134 132 128 124 122 121 122 5 1 255 0 0 0 0 0 4 1 0 255 0 255 0 0 0 Output 2 8 0 325125 65026 Submitted Solution: ``` # -*- coding: utf-8 -*- def inpl(): return list(map(int, input().split())) def main(): N, M = inpl() INF = 10**9 while N: C = [int(input()) for _ in range(M)] X = [int(input()) for _ in range(N)] Y = [[INF]*256 for i in range(N+1)] for i in range(256): Y[0][i] = 0 for i, x in enumerate(X): for j in range(256): if Y[i][j] == INF: continue for c in C: k = min(255, max(0, j+c)) Y[i+1][k] = min(Y[i+1][k], Y[i][j] + (x - k)**2) print(min(Y[-1])) N, M = inpl() if __name__ == "__main__": main() ```
instruction
0
78,241
3
156,482
No
output
1
78,241
3
156,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, this sequence of integers tends to have similar values ​​before and after. Differential pulse code modulation uses this to encode the difference between the values ​​before and after and improve the compression rate. In this problem, we consider selecting the difference value from a predetermined set of values. We call this set of values ​​a codebook. The decrypted audio signal yn is defined by the following equation. > yn = yn --1 + C [kn] Where kn is the output sequence output by the program and C [j] is the jth value in the codebook. However, yn is rounded to 0 if the value is less than 0 by addition, and to 255 if the value is greater than 255. The value of y0 is 128. Your job is to select the output sequence so that the sum of squares of the difference between the original input signal and the decoded output signal is minimized given the input signal and the codebook, and the difference at that time. It is to write a program that outputs the sum of squares of. For example, if you compress the columns 131, 137 using a set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 4 = When compressed into the sequence 132, y2 = 132 + 4 = 136, the sum of squares becomes the minimum (131 --132) ^ 2 + (137 --136) ^ 2 = 2. Also, if you also compress the columns 131, 123 using the set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 1 = 129, y2 = 129 --4 = 125, and unlike the previous example, it is better not to adopt +2, which is closer to 131 (131 --129) ^ 2 + (123 --125) ^ 2 = 8, which is a smaller square. The sum is obtained. The above two examples are the first two examples of sample input. Input The input consists of multiple datasets. The format of each data set is as follows. > N M > C1 > C2 > ... > CM > x1 > x2 > ... > xN > The first line specifies the size of the input dataset. N is the length (number of samples) of the input signal to be compressed. M is the number of values ​​contained in the codebook. N and M satisfy 1 ≤ N ≤ 20000 and 1 ≤ M ≤ 16. The M line that follows is the description of the codebook. Ci represents the i-th value contained in the codebook. Ci satisfies -255 ≤ Ci ≤ 255. The N lines that follow are the description of the input signal. xi is the i-th value of a sequence of integers representing the input signal. xi satisfies 0 ≤ xi ≤ 255. The input items in the dataset are all integers. The end of the input is represented by a line consisting of only two zeros separated by a single space character. Output For each input data set, output the minimum value of the sum of squares of the difference between the original input signal and the decoded output signal in one line. Example Input 2 7 4 2 1 0 -1 -2 -4 131 137 2 7 4 2 1 0 -1 -2 -4 131 123 10 7 -4 -2 -1 0 1 2 4 132 134 135 134 132 128 124 122 121 122 5 1 255 0 0 0 0 0 4 1 0 255 0 255 0 0 0 Output 2 8 0 325125 65026 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] M = 256 def f(m, n): cs = [I() for _ in range(m)] xs = [I() for _ in range(n)] d = [inf] * M d[128] = 0 for i in range(n): x = xs[i] nd = [inf] * M for k in range(M): v = d[k] for j in range(m): c = cs[j] nk = max(min(k+c,255),0) if nd[nk] > v + pow(x-nk, 2): nd[nk] = v + pow(x-nk, 2) d = nd return min(d) while True: n,m = LI() if m == 0 and n == 0: break rr.append(f(m,n)) return '\n'.join(map(str,rr)) print(main()) ```
instruction
0
78,242
3
156,484
No
output
1
78,242
3
156,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, this sequence of integers tends to have similar values ​​before and after. Differential pulse code modulation uses this to encode the difference between the values ​​before and after and improve the compression rate. In this problem, we consider selecting the difference value from a predetermined set of values. We call this set of values ​​a codebook. The decrypted audio signal yn is defined by the following equation. > yn = yn --1 + C [kn] Where kn is the output sequence output by the program and C [j] is the jth value in the codebook. However, yn is rounded to 0 if the value is less than 0 by addition, and to 255 if the value is greater than 255. The value of y0 is 128. Your job is to select the output sequence so that the sum of squares of the difference between the original input signal and the decoded output signal is minimized given the input signal and the codebook, and the difference at that time. It is to write a program that outputs the sum of squares of. For example, if you compress the columns 131, 137 using a set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 4 = When compressed into the sequence 132, y2 = 132 + 4 = 136, the sum of squares becomes the minimum (131 --132) ^ 2 + (137 --136) ^ 2 = 2. Also, if you also compress the columns 131, 123 using the set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 1 = 129, y2 = 129 --4 = 125, and unlike the previous example, it is better not to adopt +2, which is closer to 131 (131 --129) ^ 2 + (123 --125) ^ 2 = 8, which is a smaller square. The sum is obtained. The above two examples are the first two examples of sample input. Input The input consists of multiple datasets. The format of each data set is as follows. > N M > C1 > C2 > ... > CM > x1 > x2 > ... > xN > The first line specifies the size of the input dataset. N is the length (number of samples) of the input signal to be compressed. M is the number of values ​​contained in the codebook. N and M satisfy 1 ≤ N ≤ 20000 and 1 ≤ M ≤ 16. The M line that follows is the description of the codebook. Ci represents the i-th value contained in the codebook. Ci satisfies -255 ≤ Ci ≤ 255. The N lines that follow are the description of the input signal. xi is the i-th value of a sequence of integers representing the input signal. xi satisfies 0 ≤ xi ≤ 255. The input items in the dataset are all integers. The end of the input is represented by a line consisting of only two zeros separated by a single space character. Output For each input data set, output the minimum value of the sum of squares of the difference between the original input signal and the decoded output signal in one line. Example Input 2 7 4 2 1 0 -1 -2 -4 131 137 2 7 4 2 1 0 -1 -2 -4 131 123 10 7 -4 -2 -1 0 1 2 4 132 134 135 134 132 128 124 122 121 122 5 1 255 0 0 0 0 0 4 1 0 255 0 255 0 0 0 Output 2 8 0 325125 65026 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] M = 256 sq = [i**2 for i in range(M)] nkss = [[sq[abs(x-nk)] for nk in range(M)] for x in range(M)] ML = list(range(M)) def f(m, n): cs = [I() for _ in range(m)] xs = [I() for _ in range(n)] ml = list(range(m)) d = [inf] * M nd = [inf] * M d[128] = 0 for i in range(n): nd = [inf] * M nks = nkss[xs[i]] for j in ml: c = cs[j] for k in ML: nk = k+c if nk < 0: nk = 0 elif nk > 255: nk = 255 if nd[nk] > d[k]: nd[nk] = d[k] for nk in ML: nd[nk] += nks[nk] d = nd return min(d) while True: n,m = LI() if m == 0 and n == 0: break rr.append(f(m,n)) return '\n'.join(map(str,rr)) print(main()) ```
instruction
0
78,243
3
156,486
No
output
1
78,243
3
156,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, this sequence of integers tends to have similar values ​​before and after. Differential pulse code modulation uses this to encode the difference between the values ​​before and after and improve the compression rate. In this problem, we consider selecting the difference value from a predetermined set of values. We call this set of values ​​a codebook. The decrypted audio signal yn is defined by the following equation. > yn = yn --1 + C [kn] Where kn is the output sequence output by the program and C [j] is the jth value in the codebook. However, yn is rounded to 0 if the value is less than 0 by addition, and to 255 if the value is greater than 255. The value of y0 is 128. Your job is to select the output sequence so that the sum of squares of the difference between the original input signal and the decoded output signal is minimized given the input signal and the codebook, and the difference at that time. It is to write a program that outputs the sum of squares of. For example, if you compress the columns 131, 137 using a set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 4 = When compressed into the sequence 132, y2 = 132 + 4 = 136, the sum of squares becomes the minimum (131 --132) ^ 2 + (137 --136) ^ 2 = 2. Also, if you also compress the columns 131, 123 using the set of values ​​{4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 1 = 129, y2 = 129 --4 = 125, and unlike the previous example, it is better not to adopt +2, which is closer to 131 (131 --129) ^ 2 + (123 --125) ^ 2 = 8, which is a smaller square. The sum is obtained. The above two examples are the first two examples of sample input. Input The input consists of multiple datasets. The format of each data set is as follows. > N M > C1 > C2 > ... > CM > x1 > x2 > ... > xN > The first line specifies the size of the input dataset. N is the length (number of samples) of the input signal to be compressed. M is the number of values ​​contained in the codebook. N and M satisfy 1 ≤ N ≤ 20000 and 1 ≤ M ≤ 16. The M line that follows is the description of the codebook. Ci represents the i-th value contained in the codebook. Ci satisfies -255 ≤ Ci ≤ 255. The N lines that follow are the description of the input signal. xi is the i-th value of a sequence of integers representing the input signal. xi satisfies 0 ≤ xi ≤ 255. The input items in the dataset are all integers. The end of the input is represented by a line consisting of only two zeros separated by a single space character. Output For each input data set, output the minimum value of the sum of squares of the difference between the original input signal and the decoded output signal in one line. Example Input 2 7 4 2 1 0 -1 -2 -4 131 137 2 7 4 2 1 0 -1 -2 -4 131 123 10 7 -4 -2 -1 0 1 2 4 132 134 135 134 132 128 124 122 121 122 5 1 255 0 0 0 0 0 4 1 0 255 0 255 0 0 0 Output 2 8 0 325125 65026 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: n,m = LI() if n == 0 and m == 0: break cs = [I() for _ in range(m)] xs = [I() for _ in range(n)] d = collections.defaultdict(int) d[128] = 0 for x in xs: n = collections.defaultdict(lambda: inf) for k,v in d.items(): for c in cs: nk = max(min(k+c,255),0) if n[nk] > v + (x-nk) ** 2: n[nk] = v + (x-nk) ** 2 d = n rr.append(min(d.values())) return '\n'.join(map(str, rr)) print(main()) ```
instruction
0
78,244
3
156,488
No
output
1
78,244
3
156,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n lanterns in a row. The lantern i is placed in position i and has power equal to p_i. Each lantern can be directed to illuminate either some lanterns to the left or some lanterns to the right. If the i-th lantern is turned to the left, it illuminates all such lanterns j that j ∈ [i - p_i, i - 1]. Similarly, if it is turned to the right, it illuminates all such lanterns j that j ∈ [i + 1, i + p_i]. Your goal is to choose a direction for each lantern so each lantern is illuminated by at least one other lantern, or report that it is impossible. Input The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases. Each test case consists of two lines. The first line contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of lanterns. The second line contains n integers p_1, p_2, ..., p_n (0 ≤ p_i ≤ n) — the power of the i-th lantern. The sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, print the answer as follows: If it is possible to direct all lanterns so that each lantern is illuminated, print YES in the first line and a string of n characters L and/or R (the i-th character is L if the i-th lantern is turned to the left, otherwise this character is R) in the second line. If there are multiple answers, you may print any of them. If there is no answer, simply print NO for that test case. Example Input 4 8 0 0 3 1 1 1 1 2 2 1 1 2 2 2 2 0 1 Output YES RRLLLLRL YES RL YES RL NO Submitted Solution: ``` # First we build segment tree on the reach to the right in single step for range l to r def build_max_segment_tree(ll, left, right): if left >= right: return None root = {} root['l'] = left root['r'] = right for i in range(left, right, 1): val = ll[i] if root.get('max_val', -1) < val: root['max_val'] = val root['max_pos'] = i mid = (left+right)// 2 if left < mid and mid < right: root['mid'] = mid if mid > left: root['lchild'] = build_max_segment_tree(ll, left, mid) if right > mid: root['rchild'] = build_max_segment_tree(ll, mid, right) return root def query_max_segment_tree(st, left, right): if left >= right: return -1, -1 elif 'lchild' not in st and 'rchild' not in st: # print(st) return st['max_val'], st['max_pos'] max_val = -1 max_pos = 0 if left <= st['l'] and right >= st['r']: return st['max_val'], st['max_pos'] else: if 'mid' in st and left < st['mid'] and 'lchild' in st: cur_max_val, cur_max_pos = query_max_segment_tree(st['lchild'], left, min(st['mid'], right)) if max_val < cur_max_val: max_val = cur_max_val max_pos = cur_max_pos if 'mid' in st and right > st['mid'] and 'rchild' in st: cur_max_val, cur_max_pos = query_max_segment_tree(st['rchild'], max(st['mid'], left), right) if max_val < cur_max_val: max_val = cur_max_val max_pos = cur_max_pos return max_val, max_pos # Now we want to create the max value a lantern can reach to the right recursively (by taking the max that is shined upon) def get_recurse_reach(i, recurse_reach, st, right_reach): if i in recurse_reach: return recurse_reach[i] cur_reach = right_reach[i] if cur_reach == i: recurse_reach[i] = i return i # Get the next hop to the right next_reach, next_pos = query_max_segment_tree(st, i+1, cur_reach+1) if next_reach <= cur_reach: recurse_reach[i] = cur_reach return cur_reach recurse_reach[i] = get_recurse_reach(next_pos, recurse_reach, st, right_reach) return recurse_reach[i] def get_solution(n, pp): right_reach = [(i + pp[i]) for i in range(len(pp))] st1 = build_max_segment_tree(right_reach, 0, len(right_reach)) # print(st1) recurse_reach = {} for i in range(n): max_reach = get_recurse_reach(i, recurse_reach, st1, right_reach) # print(i, recurse_reach.get(i)) # Now we start iterate from the left and do the following: # 1. Try to turn the current lantern to the left and see if there are sub-solution that cover all lantern to the left # 2. If no then continue to next lantern # 3. If yes, then we try to propagate all lantern in between to the right and check the max reach to the right that we can have # subsolution contain the end_i where if end_i inside subsolution it meant that there is a configuration where all lantern from 0 to end_i is light up # we should always maintain the subsolution sorted subsolution = [(-1, -1, -1)] max_subsolution = 0 # print(pp) solution = None have_solution = False for i in range(1, n): # print("i: {}".format(i)) if i - pp[i] > max_subsolution: # No subsolution starting from i continue # Get the minimum subsolution that is more or equal to i - pp[i] prev_subsolution_index = None if i - pp[i] <= 0: prev_subsolution_index = 0 else: for j in range(len(subsolution)-1, -1, -1): if subsolution[j][0] < i - pp[i]: break prev_subsolution_index = j if prev_subsolution_index is None: continue chosen_subsolution = subsolution[prev_subsolution_index] if chosen_subsolution[0] > i: continue # print("chosen_subsolution: {}, i: {}, subsolution: {}".format(chosen_subsolution, i, subsolution)) # Get the single step reach between chosen_subsolution+1 until i next_reach, next_pos = query_max_segment_tree(st1, chosen_subsolution[0]+1, i) # print("NEXTREACH", next_reach, next_pos) if next_reach < i: # NO current subsolution! continue elif next_reach == i: cur_subsolution_reach = i else: next_next_reach, next_next_pos = query_max_segment_tree(st1, i+1, next_reach+1) cur_subsolution_reach = recurse_reach.get(next_next_pos, next_next_pos) if cur_subsolution_reach > max_subsolution: subsolution.append((cur_subsolution_reach, i, prev_subsolution_index)) max_subsolution = cur_subsolution_reach if max_subsolution >= n-1: have_solution = True turn_left = [i] while prev_subsolution_index > 0: prev_subsolution = subsolution[prev_subsolution_index] turn_left.append(prev_subsolution[1]) prev_subsolution_index = prev_subsolution[2] solution = ['R'] * n for pos in turn_left: if pos >= 0: solution[pos] = 'L' solution = ''.join(solution) return True, solution return False, None T = int(input()) def reverse_direction(s): if s == 'R': return 'L' else: return 'R' def reverse_solution(s): return ''.join([reverse_direction(ch) for ch in s][::-1]) for t in range(T): n = int(input()) pp = [int(x) for x in input().split()] have_solution, solution = get_solution(n, pp) if not have_solution: have_solution, solution = get_solution(n, pp[::-1]) if have_solution: solution = reverse_solution(solution) # print("-----SOLUTION-----") if have_solution: print("YES") print(solution) else: print("NO") # print("------------------") ```
instruction
0
78,500
3
157,000
No
output
1
78,500
3
157,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n lanterns in a row. The lantern i is placed in position i and has power equal to p_i. Each lantern can be directed to illuminate either some lanterns to the left or some lanterns to the right. If the i-th lantern is turned to the left, it illuminates all such lanterns j that j ∈ [i - p_i, i - 1]. Similarly, if it is turned to the right, it illuminates all such lanterns j that j ∈ [i + 1, i + p_i]. Your goal is to choose a direction for each lantern so each lantern is illuminated by at least one other lantern, or report that it is impossible. Input The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases. Each test case consists of two lines. The first line contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of lanterns. The second line contains n integers p_1, p_2, ..., p_n (0 ≤ p_i ≤ n) — the power of the i-th lantern. The sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, print the answer as follows: If it is possible to direct all lanterns so that each lantern is illuminated, print YES in the first line and a string of n characters L and/or R (the i-th character is L if the i-th lantern is turned to the left, otherwise this character is R) in the second line. If there are multiple answers, you may print any of them. If there is no answer, simply print NO for that test case. Example Input 4 8 0 0 3 1 1 1 1 2 2 1 1 2 2 2 2 0 1 Output YES RRLLLLRL YES RL YES RL NO Submitted Solution: ``` # First we build segment tree on the reach to the right in single step for range l to r def build_max_segment_tree(ll, left, right): if left >= right: return None root = {} root['l'] = left root['r'] = right for i in range(left, right, 1): val = ll[i] if root.get('max_val', -1) < val: root['max_val'] = val root['max_pos'] = i mid = (left+right)// 2 if left < mid and mid < right: root['mid'] = mid if mid > left: root['lchild'] = build_max_segment_tree(ll, left, mid) if right > mid: root['rchild'] = build_max_segment_tree(ll, mid, right) return root def query_max_segment_tree(st, left, right): if left >= right: return -1, -1 elif 'lchild' not in st and 'rchild' not in st: # print(st) return st['max_val'], st['max_pos'] max_val = -1 max_pos = 0 if left <= st['l'] and right >= st['r']: return st['max_val'], st['max_pos'] else: if 'mid' in st and left < st['mid'] and 'lchild' in st: cur_max_val, cur_max_pos = query_max_segment_tree(st['lchild'], left, min(st['mid'], right)) if max_val < cur_max_val: max_val = cur_max_val max_pos = cur_max_pos if 'mid' in st and right > st['mid'] and 'rchild' in st: cur_max_val, cur_max_pos = query_max_segment_tree(st['rchild'], max(st['mid'], left), right) if max_val < cur_max_val: max_val = cur_max_val max_pos = cur_max_pos return max_val, max_pos # Now we want to create the max value a lantern can reach to the right recursively (by taking the max that is shined upon) def get_recurse_reach(i, recurse_reach, st, right_reach): if i in recurse_reach: return recurse_reach[i] cur_reach = right_reach[i] if cur_reach == i: recurse_reach[i] = i return i # Get the next hop to the right next_reach, next_pos = query_max_segment_tree(st, i+1, cur_reach+1) if next_reach <= cur_reach: recurse_reach[i] = cur_reach return cur_reach recurse_reach[i] = get_recurse_reach(next_pos, recurse_reach, st, right_reach) return recurse_reach[i] def get_solution(n, pp): right_reach = [(i + pp[i]) for i in range(len(pp))] st1 = build_max_segment_tree(right_reach, 0, len(right_reach)) # print(st1) recurse_reach = {} for i in range(n): max_reach = get_recurse_reach(i, recurse_reach, st1, right_reach) # print(i, recurse_reach.get(i)) # Now we start iterate from the left and do the following: # 1. Try to turn the current lantern to the left and see if there are sub-solution that cover all lantern to the left # 2. If no then continue to next lantern # 3. If yes, then we try to propagate all lantern in between to the right and check the max reach to the right that we can have # subsolution contain the end_i where if end_i inside subsolution it meant that there is a configuration where all lantern from 0 to end_i is light up # we should always maintain the subsolution sorted subsolution = [(-1, -1, -1)] max_subsolution = 0 # print(pp) solution = None have_solution = False for i in range(1, n): # print("i: {}".format(i)) if i - pp[i] - 1 > max_subsolution: # No subsolution starting from i continue # Get the minimum subsolution that is more or equal to i - pp[i] - 1 prev_subsolution_index = None if i - pp[i] <= 0: prev_subsolution_index = 0 else: for j in range(len(subsolution)-1, -1, -1): if subsolution[j][0] < i - pp[i] - 1: break prev_subsolution_index = j if prev_subsolution_index is None: continue chosen_subsolution = subsolution[prev_subsolution_index] if chosen_subsolution[0] > i: continue # print("chosen_subsolution: {}, i: {}, subsolution: {}".format(chosen_subsolution, i, subsolution)) # Get the single step reach between chosen_subsolution+1 until i next_reach, next_pos = query_max_segment_tree(st1, chosen_subsolution[0]+1, i) # print("NEXTREACH", next_reach, next_pos) if next_reach < i: # NO current subsolution! continue elif next_reach == i: cur_subsolution_reach = i else: next_next_reach, next_next_pos = query_max_segment_tree(st1, i+1, next_reach+1) cur_subsolution_reach = recurse_reach.get(next_next_pos, next_next_pos) if cur_subsolution_reach > max_subsolution: subsolution.append((cur_subsolution_reach, i, prev_subsolution_index)) max_subsolution = cur_subsolution_reach if max_subsolution >= n-1: have_solution = True turn_left = [i] while prev_subsolution_index > 0: prev_subsolution = subsolution[prev_subsolution_index] turn_left.append(prev_subsolution[1]) prev_subsolution_index = prev_subsolution[2] solution = ['R'] * n for pos in turn_left: if pos >= 0: solution[pos] = 'L' solution = ''.join(solution) return True, solution return False, None T = int(input()) def reverse_direction(s): if s == 'R': return 'L' else: return 'R' def reverse_solution(s): return ''.join([reverse_direction(ch) for ch in s][::-1]) for t in range(T): n = int(input()) pp = [int(x) for x in input().split()] have_solution, solution = get_solution(n, pp) if not have_solution: have_solution, solution = get_solution(n, pp[::-1]) if have_solution: solution = reverse_solution(solution) # print("-----SOLUTION-----") if have_solution: print("YES") print(solution) else: print("NO") # print("------------------") ```
instruction
0
78,502
3
157,004
No
output
1
78,502
3
157,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Russian space traveller Alisa Selezneva, like any other schoolgirl of the late 21 century, is interested in science. She has recently visited the MIT (Moscow Institute of Time), where its chairman and the co-inventor of the time machine academician Petrov told her about the construction of a time machine. During the demonstration of the time machine performance Alisa noticed that the machine does not have high speed and the girl got interested in the reason for such disadvantage. As it turns out on closer examination, one of the problems that should be solved for the time machine isn't solved by an optimal algorithm. If you find a way to solve this problem optimally, the time machine will run faster and use less energy. A task that none of the staff can solve optimally is as follows. There exists a matrix a, which is filled by the following rule: The cells are consecutive positive integers, starting with one. Besides, ai, j < at, k (i, j, t, k ≥ 1), if: 1. max(i, j) < max(t, k); 2. max(i, j) = max(t, k) and j < k; 3. max(i, j) = max(t, k), j = k and i > t. So, after the first 36 numbers are inserted, matrix a will look as follows: <image> To solve the problem, you should learn to find rather quickly for the given values of x1, y1, x2 and y2 (x1 ≤ x2, y1 ≤ y2) the meaning of expression: <image> As the meaning of this expression can be large enough, it is sufficient to know only the last 10 digits of the sought value. So, no one in MTI can solve the given task. Alice was brave enough to use the time machine and travel the past to help you. Your task is to write a program that uses the given values x1, y1, x2 and y2 finds the last 10 digits of the given expression. Input The first input line contains a single integer t (1 ≤ t ≤ 105) — the number of test sets for which you should solve the problem. Each of the next t lines contains the description of a test — four positive integers x1, y1, x2 and y2 (1 ≤ x1 ≤ x2 ≤ 109, 1 ≤ y1 ≤ y2 ≤ 109), separated by spaces. Output For each query print the meaning of the expression if it contains at most 10 characters. Otherwise, print three characters "." (without the quotes), and then ten last digits of the time expression. Print the answer to each query on a single line. Follow the format, given in the sample as closely as possible. Examples Input 5 1 1 1 1 2 2 3 3 2 3 5 6 100 87 288 2002 4 2 5 4 Output 1 24 300 ...5679392764 111 Submitted Solution: ``` #!/bin/python def mul(a): r = 1 for i in a: r *= i return r def dsum(n, k): return mul(range(n - k + 1, n + 1)) def ssq(n): n += 1; return dsum(n, 3) // 3 + dsum(n, 2) // 2 def snum(n): return (n * (n + 1)) // 2 def ssq2(x, y): return ssq(y) - ssq(x - 1) def ssum(x, y): if x == y: return snum(x * x) elif x > y: return ssum(y, y) - (x - y) * snum(y - 1) + y * ssq2(y + 1, x) else: return ssum(x, x) + (y - x) * snum(x) + x * ssq2(x, y - 1) def sshow(x): if x < 10**10: return str(x) else: return "..." + str(x)[-10:] def rectsum(x1, y1, x2, y2): return ssum(x2, y2) - ssum(x1-1, y2) - ssum(x2, y1-1) + ssum(x1-1, y1-1) n = int(input()) for i in range(n): a, b, c, d = map(int, input().split()) print(rectsum(a, b, c, d)) ```
instruction
0
78,568
3
157,136
No
output
1
78,568
3
157,137