message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
276
109k
cluster
float64
23
23
__index_level_0__
int64
552
217k
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92
instruction
0
101,488
23
202,976
Tags: implementation, math Correct Solution: ``` from fractions import gcd n, m, x, y, a, b = map(int, input().split()) g = gcd(a, b) a, b = a // g, b // g k = min(n // a, m // b) a, b = k * a, k * b x1, x2 = x - (a - a // 2), x + a // 2 y1, y2 = y - (b - b // 2), y + b // 2 d = max(0, 0 - x1) x1, x2 = x1 + d, x2 + d d = max(0, x2 - n) x1, x2 = x1 - d, x2 - d d = max(0, 0 - y1) y1, y2 = y1 + d, y2 + d d = max(0, y2 - m) y1, y2 = y1 - d, y2 - d print(" ".join(map(str, [x1, y1, x2, y2]))); ```
output
1
101,488
23
202,977
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92
instruction
0
101,489
23
202,978
Tags: implementation, math Correct Solution: ``` import sys from fractions import gcd with sys.stdin as fin, sys.stdout as fout: n, m, x, y, a, b = map(int, next(fin).split()) d = gcd(a, b) a //= d b //= d k = min(n // a, m // b) # >_< w = k * a h = k * b best = tuple([float('inf')] * 3) for add1 in 0, 1: for add2 in 0, 1: x1 = x - w // 2 - add1 y1 = y - h // 2 - add2 cur = ((2 * x1 + w - 2 * x) ** 2 + (2 * y1 + h - 2 * y) ** 2, x1, y1) if cur < best: best = cur x1, y1 = best[1:] x1 = min(x1, n - w) y1 = min(y1, m - h) x1 = max(x1, 0) y1 = max(y1, 0) print(x1, y1, x1 + w, y1 + h) ```
output
1
101,489
23
202,979
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92
instruction
0
101,490
23
202,980
Tags: implementation, math Correct Solution: ``` from fractions import gcd n, m, x, y, a, b = map(int, input().split()) r = gcd(a, b) a, b = a // r, b // r r = min(n // a, m // b) a, b = a * r, b * r cx, cy = (a + 1) // 2, (b + 1) // 2 dx, dy = min(n - a, max(cx, x) - cx), min(m - b, max(cy, y) - cy) print(dx, dy, a + dx, b + dy) # Made By Mostafa_Khaled ```
output
1
101,490
23
202,981
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92
instruction
0
101,491
23
202,982
Tags: implementation, math Correct Solution: ``` from fractions import gcd n, m, x, y, a, b = map(int, input().split()) r = gcd(a, b) a, b = a // r, b // r r = min(n // a, m // b) a, b = a * r, b * r cx, cy = (a + 1) // 2, (b + 1) // 2 dx, dy = min(n - a, max(cx, x) - cx), min(m - b, max(cy, y) - cy) print(dx, dy, a + dx, b + dy) ```
output
1
101,491
23
202,983
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92
instruction
0
101,492
23
202,984
Tags: implementation, math Correct Solution: ``` from fractions import gcd n, m, x, y, a, b = map(int, input().split()) k = gcd(a, b) a //= k b //= k times = min(n // a, m // b) a *= times b *= times x1 = x - (a + 1) // 2 y1 = y - (b + 1) // 2 if x1 < 0: x1 = 0 if y1 < 0: y1 = 0 if x1 + a > n: x1 -= (x1 + a - n) if y1 + b > m: y1 -= (y1 + b - m) print(x1, y1, x1 + a, y1 + b) ```
output
1
101,492
23
202,985
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92 Submitted Solution: ``` import sys from fractions import gcd with sys.stdin as fin, sys.stdout as fout: n, m, x, y, a, b = map(int, next(fin).split()) d = gcd(a, b) a //= d b //= d k = n // max(a, b) w = k * a h = k * b x1 = x - (w + 1) // 2 y1 = y - (h + 1) // 2 print(x1, y1, x1 + w, y1 + h) ```
instruction
0
101,493
23
202,986
No
output
1
101,493
23
202,987
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92 Submitted Solution: ``` import math n, m, x, y, a, b = map(int, input().split()) gcd = math.gcd(a, b) a //= gcd b //= gcd max_ratio = min(n // a, m // b) #if (a * max_ratio) % 2 == 1 or (b * max_ratio) % 2 == 1: # max_ratio -= 1 a *= max_ratio b *= max_ratio print(x - a // 2, y - b // 2, x + a // 2, y + b // 2) ```
instruction
0
101,494
23
202,988
No
output
1
101,494
23
202,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92 Submitted Solution: ``` import math n, m, x, y, a, b = map(int, input().split()) gcd = math.gcd(a, b) a //= gcd b //= gcd max_ratio = min(n // a, m // b) #if (a * max_ratio) % 2 == 1 or (b * max_ratio) % 2 == 1: # max_ratio -= 1 a *= max_ratio b *= max_ratio print(x - (a + 1) // 2, y - (b + 1) // 2, x + a // 2, y + b // 2) ```
instruction
0
101,495
23
202,990
No
output
1
101,495
23
202,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangle grid. That grid's size is n Γ— m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (x, y) (0 ≀ x ≀ n, 0 ≀ y ≀ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≀ x1 ≀ x ≀ x2 ≀ n, 0 ≀ y1 ≀ y ≀ y2 ≀ m, <image>. The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers. <image> If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one. Input The first line contains six integers n, m, x, y, a, b (1 ≀ n, m ≀ 109, 0 ≀ x ≀ n, 0 ≀ y ≀ m, 1 ≀ a ≀ n, 1 ≀ b ≀ m). Output Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2). Examples Input 9 9 5 5 2 1 Output 1 3 9 7 Input 100 100 52 50 46 56 Output 17 8 86 92 Submitted Solution: ``` import sys from fractions import gcd with sys.stdin as fin, sys.stdout as fout: n, m, x, y, a, b = map(int, next(fin).split()) d = gcd(a, b) a //= d b //= d k = min(n // a, m // b) # >_< w = k * a h = k * b best = tuple([float('inf')] * 3) for add1 in 0, 1: for add2 in 0, 1: x1 = x - w // 2 - add1 y1 = y - h // 2 - add2 cur = ((x1 + w / 2 - x) ** 2 + (y1 + h / 2 - y) ** 2, x1, y1) if cur < best: best = cur print(best[1], best[2], best[1] + w, best[2] + h) ```
instruction
0
101,496
23
202,992
No
output
1
101,496
23
202,993
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,760
23
203,520
Tags: geometry Correct Solution: ``` from collections import namedtuple from itertools import combinations Point = namedtuple('Point', ['x', 'y']) def read(): x, y = input().split() return Point(int(x), int(y)) def doubled_oriented_area(p1, p2, p3): return (p3.y - p1.y) * (p2.x - p1.x) - (p3.x - p1.x) * (p2.y - p1.y) def filter_points(p1, p2, points): res = [] for p in points: if doubled_oriented_area(p1, p2, p) != 0: res.append(p) return res def on_the_same_line(points): if len(points) < 3: return True return not filter_points(points[0], points[1], points[2:]) def main(): n = int(input()) if n <= 4: print('YES') return points = [] for i in range(n): points.append(read()) for p in combinations(range(3), 2): filtered = filter_points(points[p[0]], points[p[1]], points) if on_the_same_line(filtered): print('YES') return print('NO') if __name__ == '__main__': main() ```
output
1
101,760
23
203,521
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,761
23
203,522
Tags: geometry Correct Solution: ``` import math import sys from collections import defaultdict def solve(io): N = io.readInt() P = [None] * N for i in range(0, N): X = io.readInt() Y = io.readInt() P[i] = (X, Y) if N <= 4: io.println("YES") return for i in range(0, 3): P[0], P[i] = P[i], P[0] if can(P): io.println("YES") return io.println("NO") def can(P): slopes = makeSlopeDict(P) if len(slopes) <= 2: return True matches = 0 others = [] for _, v in slopes.items(): if len(v) > 1: matches += 1 else: others += v if matches > 1: return False line = makeSlopeDict(others) return len(line) <= 1 def makeSlopeDict(pts): slopes = defaultdict(set) for i in range(1, len(pts)): dx = pts[i][0] - pts[0][0] dy = pts[i][1] - pts[0][1] if dy < 0: dx *= -1 dy *= -1 if dx != 0 and dy != 0: g = math.gcd(dx, dy) v = (dx / g, dy / g) elif dx == 0 and dy != 0: v = (0, 1) elif dx != 0 and dy == 0: v = (1, 0) else: v = (0, 0) slopes[v].add(pts[i]) return slopes # +---------------------+ # | TEMPLATE CODE BELOW | # | DO NOT MODIFY | # +---------------------+ # TODO: maybe reading byte-by-byte is faster than reading and parsing tokens. class IO: input = None output = None raw = "" buf = [] pos = 0 def __init__(self, inputStream, outputStream): self.input = inputStream self.output = outputStream def readToBuffer(self): self.raw = self.input.readline().rstrip('\n') self.buf = self.raw.split() self.pos = 0 def readString(self): while self.pos == len(self.buf): self.readToBuffer() ans = self.buf[self.pos] self.pos += 1 return ans def readInt(self): return int(self.readString()) def readFloat(self): return float(self.readString()) def readStringArray(self, N, offset = 0): arr = [ None ] * offset for _ in range(0, N): arr.append(self.readString()) return arr def readIntArray(self, N, offset = 0): arr = [ None ] * offset for _ in range(0, N): arr.append(self.readInt()) return arr def readFloatArray(self, N, offset = 0): arr = [ None ] * offset for _ in range(0, N): arr.append(self.readFloat()) return arr def readLine(self): while self.pos == len(self.buf): self.readToBuffer() if self.pos > 0: raise ValueError("Cannot call readline in the middle of a line.") return self.raw def print(self, s): self.output.write(str(s)) def println(self, s): self.print(s) self.print('\n') def flushOutput(self): self.output.flush() pythonIO = IO(sys.stdin, sys.stdout) solve(pythonIO) pythonIO.flushOutput() ```
output
1
101,761
23
203,523
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,762
23
203,524
Tags: geometry Correct Solution: ``` ## necessary imports import sys input = sys.stdin.readline #from math import ceil, floor, factorial; # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp ## gcd function def gcd(a,b): if b == 0: return a return gcd(b, a % b); ## nCr function efficient using Binomial Cofficient def nCr(n, k): if(k > n - k): k = n - k res = 1 for i in range(k): res = res * (n - i) res = res / (i + 1) return int(res) ## upper bound function code -- such that e in a[:i] e < x; def upper_bound(a, x, lo=0): hi = len(a) while lo < hi: mid = (lo+hi)//2 if a[mid] < x: lo = mid+1 else: hi = mid return lo ## prime factorization def primefs(n): ## if n == 1 ## calculating primes primes = {} while(n%2 == 0 and n > 0): primes[2] = primes.get(2, 0) + 1 n = n//2 for i in range(3, int(n**0.5)+2, 2): while(n%i == 0 and n > 0): primes[i] = primes.get(i, 0) + 1 n = n//i if n > 2: primes[n] = primes.get(n, 0) + 1 ## prime factoriazation of n is stored in dictionary ## primes and can be accesed. O(sqrt n) return primes ## MODULAR EXPONENTIATION FUNCTION def power(x, y, p): res = 1 x = x % p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : res = (res * x) % p y = y >> 1 x = (x * x) % p return res ## DISJOINT SET UNINON FUNCTIONS def swap(a,b): temp = a a = b b = temp return a,b # find function with path compression included (recursive) # def find(x, link): # if link[x] == x: # return x # link[x] = find(link[x], link); # return link[x]; # find function with path compression (ITERATIVE) def find(x, link): p = x; while( p != link[p]): p = link[p]; while( x != p): nex = link[x]; link[x] = p; x = nex; return p; # the union function which makes union(x,y) # of two nodes x and y def union(x, y, link, size): x = find(x, link) y = find(y, link) if size[x] < size[y]: x,y = swap(x,y) if x != y: size[x] += size[y] link[y] = x ## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #### PRIME FACTORIZATION IN O(log n) using Sieve #### MAXN = int(1e6 + 5) def spf_sieve(): spf[1] = 1; for i in range(2, MAXN): spf[i] = i; for i in range(4, MAXN, 2): spf[i] = 2; for i in range(3, ceil(MAXN ** 0.5), 2): if spf[i] == i: for j in range(i*i, MAXN, i): if spf[j] == j: spf[j] = i; ## function for storing smallest prime factors (spf) in the array ################## un-comment below 2 lines when using factorization ################# # spf = [0 for i in range(MAXN)] # spf_sieve() def factoriazation(x): ret = {}; while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1; x = x//spf[x] return ret ## this function is useful for multiple queries only, o/w use ## primefs function above. complexity O(log n) ## taking integer array input def int_array(): return list(map(int, input().strip().split())) ## taking string array input def str_array(): return input().strip().split(); #defining a couple constants MOD = int(1e9)+7; CMOD = 998244353; INF = float('inf'); NINF = -float('inf'); ################### ---------------- TEMPLATE ENDS HERE ---------------- ################### def fxn(p, q): x = []; for r in a: ## simple slope check (y3 - y1 )/(x3 - x1) = (y2 - y1)/(x2 - x1); if (r[1] - p[1]) * (q[0] - p[0]) != (q[1] - p[1]) * (r[0] - p[0]): x.append(r); if len(x) <= 2: return True; rh, cp = x[0], x[1]; for c in x: if (c[1] - rh[1]) * (cp[0] - rh[0]) != (cp[1] - rh[1]) * (c[0] - rh[0]): return False; return True; n = int(input()); a = []; for _ in range(n): x, y = int_array(); a.append((x, y)); if n < 5: print('YES'); else: if fxn(a[0], a[1]) or fxn(a[0], a[2]) or fxn(a[1], a[2]): print('YES'); else: print('NO'); ```
output
1
101,762
23
203,525
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,763
23
203,526
Tags: geometry Correct Solution: ``` import sys input = sys.stdin.readline n = int(input()) if n <= 4: print("YES") exit() A = [None]*n for i in range(n): A[i] = list(map(int,input().split())) def is_colinear(a1,a2,a3): if a1 == a2 or a2 == a3 or a1 == a3: return True x1,y1 = a1 x2,y2 = a2 x3,y3 = a3 if x1 == x2 or x1 == x3 or x2 == x3: return x1 == x2 == x3 if y1 == y2 or y1 == y3 or y2 == y3: return y1 == y2 == y3 return (y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1) X,Y,Z = A[0],A[1],A[2] def good(X,Y): # are X,Y on the same line? bad = [] for i in range(n): if not is_colinear(X,Y,A[i]): bad.append(A[i]) if len(bad) <= 2: return True U,V = bad[0],bad[1] for i in range(len(bad)): if not is_colinear(U,V,bad[i]): return False return True if good(X,Y) or good(Y,Z) or good(X,Z): print("YES") exit() print("NO") exit() ```
output
1
101,763
23
203,527
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,764
23
203,528
Tags: geometry Correct Solution: ``` from decimal import Decimal class Point: def __init__(self,x,y): self.x = x self.y = y def __eq__(self, other): return self.x == other.x and self.y == other.y def __hash__(self): return self.x.__hash__()^self.y.__hash__() class Line: def __init__(self,p1,p2): self.A = p1.y - p2.y self.B = p2.x - p1.x self.C = p1.x*p2.y - p2.x*p1.y def isPointOnLine(self,p): if (self.A*p.x + self.B*p.y + self.C) == 0: return True else: return False def __eq__(self, line): if ((self.A==0) != (line.A == 0)) or ((self.B==0) != (line.B == 0)) or ((self.C==0) != (line.C == 0)): return False t = 0 if self.A != 0: t = Decimal(self.A)/Decimal(line.A) if self.B != 0: if t == 0: t = Decimal(self.B)/Decimal(line.B) else: if t != Decimal(self.B)/Decimal(line.B): return False if self.C != 0: if t == 0: t = Decimal(self.C)/Decimal(line.C) else: if t != Decimal(self.C)/Decimal(line.C): return False return True #in n = int(input()) points = [] for i in range(0,n): a = list(map(int,input().split())) points.append(Point(a[0],a[1])) #calc ans = "" if n < 5: ans = "Yes" else: lines = [] linePoints = [] lines.append(Line(points[0], points[1])) linePoints.append([points[0], points[1]]) for i in range(1, 5): for j in range(0, i): if i != j: line = Line(points[i], points[j]) exist = False for k in range(0, len(lines)): if lines[k] == line: exist = True existP = False for p in range(0, len(linePoints[k])): if linePoints[k][p] == points[i]: existP = True break if not existP: linePoints[k].append(points[i]) if not exist: lines.append(Line(points[i],points[j])) linePoints.append([points[i],points[j]]) firstLine = 0 secondLine = 0 i_point = 0 if len(lines) == 9: ans == "No" else: if len(lines) == 8 or len(lines) == 6: for i in range(0, len(linePoints)): if len(linePoints[i]) == 3: firstLine = i for i in range(0, len(linePoints)): if len(set(linePoints[i])-set(linePoints[firstLine])) == 2: secondLine = i lines = [lines[firstLine], lines[secondLine]] linePoints = [linePoints[firstLine], linePoints[secondLine]] elif len(lines) == 5: for i in range(0, len(linePoints)): if len(linePoints[i]) == 4: firstLine = i fifth_point = list(set(points[:5])-set(linePoints[firstLine]))[0] if len(points) > 5: for i in range(5, len(points)): exist = False if not lines[firstLine].isPointOnLine(points[i]): six_point = points[i] lines = [lines[firstLine], Line(fifth_point, six_point)] i_point = i + 1 exist = True break if not exist: ans = "Yes" else: ans = "Yes" elif len(lines) == 1: if len(points) > 5: for i in range(5, len(points)): exist = False if not lines[0].isPointOnLine(points[i]): first_point = points[i] i_point = i + 1 exist = True break if exist: if len(points) > i_point: for i in range(i_point, len(points)): exist = False if not lines[0].isPointOnLine(points[i]): second_point = points[i] i_point = i + 1 exist = True lines = [lines[0], Line(first_point, second_point)] break if not exist: ans = "Yes" else: ans = "Yes" else: ans = "Yes" else: ans = "Yes" if ans == "" and len(points) > i_point: exist = False for i in range(i_point, len(points)): if not (lines[0].isPointOnLine(points[i]) or lines[1].isPointOnLine(points[i])): exist = True ans = "No" break if not exist: ans = "Yes" else: ans = "Yes" #out print(ans) ```
output
1
101,764
23
203,529
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,765
23
203,530
Tags: geometry Correct Solution: ``` def collinear(a, b, c): return a[0]*(b[1] - c[1]) + b[0]*(c[1] - a[1]) + c[0]*(a[1] - b[1]) def check(a, pt1, pt2): tmp = [] for x in a: if collinear(a[pt1], x, a[pt2]) != 0: tmp.append(x) if len(tmp) < 3: return True x = tmp[0] y = tmp[1] for z in tmp: if collinear(x, z, y) != 0: return False return True; n = int(input()) ok = False a = [] for i in range(n): a.append(list(map(int, input().split()))) if (n < 5) or (check(a, 0, 1)) or (check(a, 0, 2)) or (check(a, 1, 2)): ok = True if ok == True: print('YES') else: print('NO') ```
output
1
101,765
23
203,531
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,766
23
203,532
Tags: geometry Correct Solution: ``` n = int(input()) lst = [] for x in range(n): (a, b) = map(int, input().split()) lst.append((a, b)) def scal(x1, y1, x2, y2, x3, y3): if (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) == 0: return True return False def check(): for x in range(n - 2): if len(s2) >= 3: if not scal(lst[s2[-3]][0], lst[s2[-3]][1], lst[s2[-2]][0], lst[s2[-2]][1], lst[s2[-1]][0], lst[s2[-1]][1]): return False if scal(lst[0][0], lst[0][1], lst[1][0], lst[1][1], lst[x + 2][0], lst[x + 2][1]): s1.append(x + 2) else: s2.append(x + 2) if len(s2) >= 3: if not scal(lst[s2[-3]][0], lst[s2[-3]][1], lst[s2[-2]][0], lst[s2[-2]][1], lst[s2[-1]][0], lst[s2[-1]][1]): return False return True flag = True if n >= 5: s1 = [] s2 = [] if not check(): lst[1], lst[s2[0]] = lst[s2[0]], lst[1] x = s2[0] s1 = [] s2 = [] if not check(): lst[0], lst[s2[0]] = lst[s2[0]], lst[0] s1 = [] s2 = [] if not check(): flag = False if flag: print("YES") else: print("NO") ```
output
1
101,766
23
203,533
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image>
instruction
0
101,767
23
203,534
Tags: geometry Correct Solution: ``` # https://codeforces.com/problemset/problem/961/D def is_linear(A, B, C): return (B[0] - A[0]) * (C[1] - A[1]) == (C[0] - A[0]) * (B[1] - A[1]) def is_line(pos): if len(pos) <= 2: return True A, B = P[pos[0]], P[pos[1]] for p in pos[2:]: if is_linear(A, B, P[p]) == False: return False return True def check(A, B, used): for i, p in enumerate(P): if is_linear(A, B, p) == True: used[i] = 1 def refresh(): for i in range(n): used[i] = 0 n = int(input()) P = [list(map(int, input().split())) for _ in range(n)] if n <= 3: print("YES") else: used = [0] * n flg = "NO" for i in range(3): A, B = P[i], P[(i+1)%3] check(A, B, used) pos = [i for i, x in enumerate(used) if x==0] if is_line(pos) == True: flg = "YES" #print(A, B) refresh() print(flg) ```
output
1
101,767
23
203,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` from itertools import combinations ps = [tuple(map(int, input().split())) for ln in range(int(input()))] def outside(pt, v1, v2): return ((pt[0]-v2[0])*(v1[1] - v2[1]) - (pt[1]-v2[1])*(v1[0] - v2[0])) def oneline(ps): return len(ps) <= 2 or not [p for p in ps if outside(p, ps[0], ps[1])] if len(ps) <= 4: print("YES") else: vs = (ps[:2] + [p for p in ps if outside(p, *ps[:2])] + [ps[0]])[:3] print ("YES" if any(oneline([p for p in ps if outside(p, v1, v2)]) for v1, v2 in combinations(vs,2)) else "NO") ```
instruction
0
101,768
23
203,536
Yes
output
1
101,768
23
203,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` import math import sys from collections import defaultdict def solve(io): N = io.readInt() P = [None] * N for i in range(0, N): X = io.readInt() Y = io.readInt() P[i] = (X, Y) if N <= 4: io.println("YES") return if can(P): io.println("YES") return P[0], P[1] = P[1], P[0] if can(P): io.println("YES") return P[0], P[2] = P[2], P[0] if can(P): io.println("YES") return io.println("NO") def can(P): slopes = makeSlopeDict(P) if len(slopes) <= 2: return True matches = 0 others = [] for _, v in slopes.items(): if len(v) > 1: matches += 1 else: others += v if matches > 1: return False line = makeSlopeDict(others) return len(line) <= 1 def makeSlopeDict(pts): slopes = defaultdict(set) for i in range(1, len(pts)): dx = pts[i][0] - pts[0][0] dy = pts[i][1] - pts[0][1] if dy < 0: dx *= -1 dy *= -1 if dx != 0 and dy != 0: g = math.gcd(dx, dy) v = (dx / g, dy / g) elif dx == 0 and dy != 0: v = (0, 1) elif dx != 0 and dy == 0: v = (1, 0) else: v = (0, 0) slopes[v].add(pts[i]) return slopes # +---------------------+ # | TEMPLATE CODE BELOW | # | DO NOT MODIFY | # +---------------------+ # TODO: maybe reading byte-by-byte is faster than reading and parsing tokens. class IO: input = None output = None raw = "" buf = [] pos = 0 def __init__(self, inputStream, outputStream): self.input = inputStream self.output = outputStream def readToBuffer(self): self.raw = self.input.readline().rstrip('\n') self.buf = self.raw.split() self.pos = 0 def readString(self): while self.pos == len(self.buf): self.readToBuffer() ans = self.buf[self.pos] self.pos += 1 return ans def readInt(self): return int(self.readString()) def readFloat(self): return float(self.readString()) def readStringArray(self, N, offset = 0): arr = [ None ] * offset for _ in range(0, N): arr.append(self.readString()) return arr def readIntArray(self, N, offset = 0): arr = [ None ] * offset for _ in range(0, N): arr.append(self.readInt()) return arr def readFloatArray(self, N, offset = 0): arr = [ None ] * offset for _ in range(0, N): arr.append(self.readFloat()) return arr def readLine(self): while self.pos == len(self.buf): self.readToBuffer() if self.pos > 0: raise ValueError("Cannot call readline in the middle of a line.") return self.raw def print(self, s): self.output.write(str(s)) def println(self, s): self.print(s) self.print('\n') def flushOutput(self): self.output.flush() pythonIO = IO(sys.stdin, sys.stdout) solve(pythonIO) pythonIO.flushOutput() ```
instruction
0
101,769
23
203,538
Yes
output
1
101,769
23
203,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` from itertools import combinations import sys d = [int(x) for x in sys.stdin.read().split()][1:] ps = list(zip(d[::2], d[1::2])) def outside(pt, v1, v2): return ((pt[0]-v2[0])*(v1[1] - v2[1]) - (pt[1]-v2[1])*(v1[0] - v2[0])) def oneline(ps): return len(ps) <= 2 or not [p for p in ps if outside(p, ps[0], ps[1])] if len(ps) <= 4: print("YES") else: vs = (ps[:2] + [p for p in ps if outside(p, *ps[:2])] + [ps[0]])[:3] print ("YES" if any(oneline([p for p in ps if outside(p, v1, v2)]) for v1, v2 in combinations(vs,2)) else "NO") ```
instruction
0
101,770
23
203,540
Yes
output
1
101,770
23
203,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` import math def get_line(x1, y1, x2, y2): a = x2 - x1 b = y1 - y2 c = x1 * (y2 - y1) - y1 * (x2 - x1) g = math.gcd(math.gcd(a, b), c) a //= g b //= g c //= g return a, b, c n = int(input()) xy = [] for i in range(n): x, y = [int(x) for x in input().split()] xy.append((x, y)) if n <= 3: print("YES") exit() def check(x1, y1, x2, y2, xy): a1, b1, c1 = get_line(x1, y1, x2, y2) other_point = None cnt_other = 0 a2, b2, c2 = 0, 0, 0 for i in range(len(xy)): x, y = xy[i] if a1 * y + b1 * x + c1 != 0: if other_point is None: other_point = x, y cnt_other = 1 elif cnt_other == 1: cnt_other = 2 a2, b2, c2 = get_line(*other_point, x, y) else: if a2 * y + b2 * x + c2 != 0: return False return True if check(*xy[0], *xy[1], xy[2:]): print("YES") elif check(*xy[1], *xy[2], [xy[0]] + xy[3:]): print("YES") elif check(*xy[0], *xy[2], [xy[1]] + xy[3:]): print("YES") else: print("NO") ```
instruction
0
101,771
23
203,542
Yes
output
1
101,771
23
203,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` n = int(input()) L = [(0, 0)] * n for i in range(n): t = input().split(' ') a = int(t[0]) b = int(t[1]) L[i] = (a, b) if n <= 4: print("YES") else: b0 = True b1 = True b2 = True L0 = [L[0]] L1 = [L[1]] L2 = [L[2]] for j in range(3, n): if (L[0][0]-L[1][0])*(L[0][1]-L[j][1])!=(L[0][1]-L[1][1])*(L[0][0]-L[j][0]): L2.append(L[j]) if (L[2][0]-L[0][0])*(L[2][1]-L[j][1])!=(L[2][1]-L[0][1])*(L[2][0]-L[j][0]): L1.append(L[j]) if (L[2][0]-L[1][0])*(L[2][1]-L[j][1])!=(L[2][1]-L[1][1])*(L[2][0]-L[j][0]): L0.append(L[j]) if len(L0) >= 3: for j in range(2, len(L0)): if (L0[0][0]-L0[1][0])*(L0[0][1]-L0[j][1])!=(L0[0][1]-L0[1][1])*(L0[0][0]-L0[j][0]): b0 = False if len(L1) >= 3: for j in range(2, len(L1)): if (L1[0][0]-L1[1][0])*(L1[0][1]-L1[j][1])!=(L1[0][1]-L1[1][1])*(L1[0][0]-L1[j][0]): b1 = False if len(L2) >= 3: for j in range(2, len(L2)): if (L2[0][0]-L2[1][0])*(L2[0][1]-L2[j][1])!=(L2[0][1]-L2[1][1])*(L2[0][0]-L2[j][0]): b2 = False if b0 or b1 or b2: print("YES") else: print("NO") ```
instruction
0
101,772
23
203,544
No
output
1
101,772
23
203,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` class Point: def __init__(self,x,y): self.x = x self.y = y def __eq__(self, other): return self.x == other.x and self.y == other.y def __hash__(self): return self.x.__hash__()^self.y.__hash__() class Line: def __init__(self,p1,p2): self.A = p1.y - p2.y self.B = p2.x - p1.x self.C = p1.x*p2.y - p2.x*p1.y def isPointOnLine(self,p): if (self.A*p.x + self.B*p.y + self.C) == 0: return True else: return False def __eq__(self, line): if ((self.A==0) != (line.A == 0)) or ((self.B==0) != (line.B == 0)) or ((self.C==0) != (line.C == 0)): return False t = 0 if self.A != 0: t = self.A/line.A if self.B != 0: if t == 0: t = self.B/line.B else: if t != self.B/line.B: return False if self.C != 0: if t == 0: t = self.C/line.C else: if t != self.C/line.C: return False return True #in n = int(input()) points = [] for i in range(0,n): a = list(map(int,input().split())) points.append(Point(a[0],a[1])) #calc ans = "" if n < 5: ans = "Yes" else: lines = [] linePoints = [] lines.append(Line(points[0], points[1])) linePoints.append([points[0], points[1]]) for i in range(1, 5): for j in range(0, i): if i != j: line = Line(points[i], points[j]) exist = False for k in range(0, len(lines)): if lines[k] == line: exist = True existP = False for p in range(0, len(linePoints[k])): if linePoints[k][p] == points[i]: existP = True break if not existP: linePoints[k].append(points[i]) if not exist: lines.append(Line(points[i],points[j])) linePoints.append([points[i],points[j]]) firstLine = 0 secondLine = 0 i_point = 0 if len(lines) == 10: ans == "No" else: if len(lines) == 8: for i in range(0, len(linePoints)): if len(linePoints[i]) == 3: firstLine = i for i in range(0, len(linePoints)): if len(set(linePoints[i]) & set(linePoints[firstLine])) == 0: secondLine = i lines = [lines[firstLine], lines[secondLine]] linePoints = [linePoints[firstLine], linePoints[secondLine]] elif len(lines) == 5: for i in range(0, len(linePoints)): if len(linePoints[i]) == 4: firstLine = i fifth_point = list(set(points[:5])-set(linePoints[firstLine]))[0] if len(points) > 5: for i in range(5, len(points)): exist = False if not lines[firstLine].isPointOnLine(points[i]): six_point = points[i] lines = [lines[firstLine], Line(fifth_point, six_point)] i_point = i + 1 exist = True break if not exist: ans = "Yes" else: ans = "Yes" elif len(lines) == 1: if len(points) > 5: for i in range(5, len(points)): exist = False if not lines[0].isPointOnLine(points[i]): first_point = points[i] i_point = i + 1 exist = True break if exist: if len(points) > i_point: for i in range(i_point, len(points)): exist = False if not lines[0].isPointOnLine(points[i]): second_point = points[i] i_point = i + 1 exist = True lines = [lines[0], Line(first_point, second_point)] break if not exist: ans = "Yes" else: ans = "Yes" else: ans = "Yes" else: ans = "Yes" if ans == "" and len(points) > i_point: exist = False for i in range(i_point, len(points)): if not (lines[0].isPointOnLine(points[i]) or lines[1].isPointOnLine(points[i])): exist = True ans = "No" break if not exist: ans = "Yes" else: ans = "Yes" #out print(ans) ```
instruction
0
101,773
23
203,546
No
output
1
101,773
23
203,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` def gcd(a, b): if a > b: a, b = b, a if b % a==0: return a return gcd(b % a, a) def line(a, b): x0, y0 = a x1, y1 = b if x0==x1: return [True, x1, None] else: slope = (y1-y0)/(x1-x0) inter = y0-slope*x0 return [False, slope, inter] def online(line, a): x0, y0 = a if line[0]: return x0==line[1] else: C, slope, inter = line return slope*x0+inter==y0 def process(A): n = len(A) if n <= 3: return 'YES' l1 = line(A[0], A[1]) l2 = line(A[1], A[2]) l3 = line(A[0], A[2]) for Line1 in [l1, l2, l3]: other = [] for x in A: if not online(Line1, x): other.append(x) if len(other) <= 2: return 'YES' a1 = other[0] a2 = other[1] Line2 = line(a1, a2) works = True for x in other: if not online(Line2, x): works = False break if works: return 'YES' return 'NO' n = int(input()) A = [] for i in range(n): x, y = [int(x) for x in input().split()] A.append([x, y]) print(process(A)) ```
instruction
0
101,774
23
203,548
No
output
1
101,774
23
203,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≀ 109)β€” coordinates of i-th point. All n points are distinct. Output If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. Examples Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO Note In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. <image> Submitted Solution: ``` import sys input = sys.stdin.readline from math import gcd def linear(a, b, c): if len(set([a, b, c])) < 3: return True q1, p1 = a[1] - b[1], a[0] - b[0] g1 = gcd(q1, p1) q1 //= g1 p1 //= g1 if p1 * q1 < 0: p1 = -abs(p1) q1 = abs(q1) q2, p2 = b[1] - c[1], b[0] - c[0] g2 = gcd(q2, p2) q2 //= g2 p2 //= g2 if p2 * q2 < 0: p2 = -abs(p2) q2 = abs(q2) if p1 == 0 and p2 == 0 or q1 == 0 and q2 == 0: return True return p1 == p2 and q1 == q2 n = int(input()) a = [] for i in range(n): x, y = map(int, input().split()) a.append((x, y)) if n <= 4: print('YES') exit() b = [a[0], a[1]] d = dict() d[(a[0], a[1])] = 2 for i in range(2, n): lin = False for j in range(len(b) - 1): for k in range(j+1, len(b)): p1, p2 = b[j], b[k] if linear(p1, p2, a[i]): lin = True d[(p1, p2)] += 1 if not lin: b.append(a[i]) for p in b: d[(p, a[i])] = 2 if len(b) == 4: break if len(b) == 2: print('YES') exit() if len(b) == 3: if min(d.values()) > 2: print('NO') else: print('YES') exit() for i in range(len(b)): for j in range(i+1, len(b)): p1, p2 = b[i], b[j] p3, p4 = set(b) - set([p1, p2]) poss = True for p in a: if linear(p1, p2, p) or linear(p3, p4, p): pass else: poss = False break if poss: print('YES') exit() print('NO') ```
instruction
0
101,775
23
203,550
No
output
1
101,775
23
203,551
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,951
23
203,902
"Correct Solution: ``` import sys import math n = int(input()) for _ in range(n): xa, ya, ra, xb, yb, rb = map(float, input().split()) distance = math.sqrt((xa-xb)**2 + (ya-yb)**2) if ra + rb >= distance: if (distance + ra < rb): print(-2) elif (distance + rb < ra): print(2) else: print(1) else: print(0) ```
output
1
101,951
23
203,903
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,952
23
203,904
"Correct Solution: ``` for _ in range(int(input())): x1, y1, r1, x2, y2, r2 = [float(x) for x in input().split()] distance = ((x1 - x2)**2 + (y1 - y2)**2)**0.5 if distance > r1 + r2: print(0) else: if r1 > r2 and distance + r2 < r1: print(2) elif r1 < r2 and distance + r1 < r2: print(-2) else: print(1) ```
output
1
101,952
23
203,905
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,953
23
203,906
"Correct Solution: ``` N=int(input()) for i in range(N): x1,y1,r1,x2,y2,r2=map(float,input().split()) d=((x1-x2)**2+(y1-y2)**2)**0.5 if r1-r2>d: if r1==r2+d: print("1") else: print("2") elif r2-r1>d: if r2==r1+d: print("1") else: print("-2") elif d<r1+r2: print("1") elif r1+r2==d: print("1") elif d>r1+r2: print("0") ```
output
1
101,953
23
203,907
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,954
23
203,908
"Correct Solution: ``` import math def aux(v): [xa,ya,ra,xb,yb,rb] = v ab = math.sqrt((xb-xa)**2 + (yb-ya)**2) if ab > ra + rb: rst = 0 elif ab + rb < ra: rst = 2 elif ab + ra < rb: rst = -2 else: rst = 1 return(rst) if __name__ == "__main__": n = int(input()) for i in range(n): v = list(map(float, input().split())) print(aux(v)) ```
output
1
101,954
23
203,909
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,955
23
203,910
"Correct Solution: ``` from math import sqrt n = int(input()) while n: xa, ya, ra, xb, yb, rb = map(float, input().split()) d = sqrt((xb - xa) ** 2 + (yb - ya) ** 2) if ra > d + rb: print(2) elif rb > d + ra: print(-2) elif d > ra + rb: print(0) else: print(1) n -= 1 ```
output
1
101,955
23
203,911
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,956
23
203,912
"Correct Solution: ``` import math num = int(input()) for i in range(num): lst = list(map(float, input().split())) xa, ya, ra = lst[0], lst[1], lst[2] xb, yb, rb = lst[3], lst[4], lst[5] d = math.sqrt((xa - xb)**2 + (ya - yb)**2) if ra + rb < d: print(0) elif d + min(ra, rb) < max(ra, rb): if ra < rb: print(-2) else: print(2) else: print(1) ```
output
1
101,956
23
203,913
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,957
23
203,914
"Correct Solution: ``` import math N = int(input()) for i in range(N): x1,y1,r1,x2,y2,r2 = map(float,input().split()) d = math.sqrt(pow(x1 - x2,2.0) + pow(y1 - y2,2.0)) if d < abs(r2 - r1): if r1 > r2: print(2) else: print(-2) elif d <= r1 + r2: print(1) else: print(0) ```
output
1
101,957
23
203,915
Provide a correct Python 3 solution for this coding contest problem. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0
instruction
0
101,958
23
203,916
"Correct Solution: ``` import math N = int(input()) for _ in [0]*N: x1, y1, r1, x2, y2, r2 = map(float, input().split()) dist = math.hypot(x2-x1, y2-y1) if dist+r2 < r1: print(2) elif dist+r1 < r2: print(-2) elif dist <= r1+r2: print(1) else: print(0) ```
output
1
101,958
23
203,917
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys import os import math N = int(input()) for i in range(N): ax, ay, ar, bx, by, br = map(float, input().split()) between_center = math.hypot(ax - bx, ay - by) # ????????Β£???????????? if between_center > ar + br: print(0) # ????????????????????Β¨ else: # B in A if ar > between_center + br: print(2) # A in B elif br > between_center + ar: print(-2) else: print(1) ```
instruction
0
101,959
23
203,918
Yes
output
1
101,959
23
203,919
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` n = int(input()) for _ in range(n): xa, ya, ra, xb, yb, rb = map(float, input().split()) if xa - ra < xb - rb and xa + ra > xb + rb and ya - ra < yb - rb and ya + ra > yb + rb: print(2) elif xa - ra > xb - rb and xa + ra < xb + rb and ya - ra > yb - rb and ya + ra < yb + rb: print(-2) elif (xa - xb)**2 + (ya - yb)**2 <= (ra + rb)**2: print(1) else: print(0) ```
instruction
0
101,960
23
203,920
Yes
output
1
101,960
23
203,921
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` import math for i in range(int(input())): xa, ya, ra, xb, yb, rb = list(map(float, input().split())) d1 = (xa - xb) ** 2 + (ya - yb) ** 2 d2 = (ra + rb) ** 2 dr = (ra-rb) ** 2 if d1 <= d2: if dr > d1: print(2 if ra > rb else -2) else: print(1) else: print(0) ```
instruction
0
101,961
23
203,922
Yes
output
1
101,961
23
203,923
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` for _ in range(int(input())): xa, ya, ra, xb, yb, rb = list(map(float,input().split())) dAB = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5 if ra + rb < dAB: print('0') elif dAB + rb < ra: print('2') elif dAB + ra < rb: print('-2') else: print('1') ```
instruction
0
101,962
23
203,924
Yes
output
1
101,962
23
203,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` import math num = int(input()) for i in range(num): ax,ay,ar,bx,by,br = map(float,input().split(' ')) d = (ax - bx)*(ax - bx) + (ay * by) if d < abs(br - ar): if ar > br: print(2) else: print(-2) elif d <= ar + br: print(1) else: print(0) ```
instruction
0
101,963
23
203,926
No
output
1
101,963
23
203,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` # your code goes here import math n = int(input()) for i in range(n): xa, ya, ra, xb, yb, rb = [float(x) for x in input().split(" ")] distance = math.sqrt((xb-xa)**2 + (yb-ya)**2) if distance > ra+rb: print(0) elif distance <= abs(ra-rb): if ra > rb: print(2) elif ra < rb: print(-2) else: print(1) elif distance <= ra+rb: print(1) ```
instruction
0
101,964
23
203,928
No
output
1
101,964
23
203,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` import math count = int(input()) for i in range(count): x1,y1,r1,x2,y2,r2 =map(float,input().split()) depth=math.sqrt((x1-x2)**2+(y1-y2)**2) if depth+r2<=r1: print(2) elif depth>r1+r2: print(0) else: print(1) ```
instruction
0
101,965
23
203,930
No
output
1
101,965
23
203,931
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical. Input The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$ Output For each dataset, print 2, -2, 1, or 0 in a line. Example Input 2 0.0 0.0 5.0 0.0 0.0 4.0 0.0 0.0 2.0 4.1 0.0 2.0 Output 2 0 Submitted Solution: ``` import math N = int(input()) for _ in [0]*N: x1, y1, r1, x2, y2, r2 = map(float, input().split()) dist = math.sqrt((x1-x2)**2+(y1-y2)**2) if dist <= abs(r1-r2): print(2 if r1 > r2 else -2) elif dist <= r1+r2: print(1) else: print(0) ```
instruction
0
101,966
23
203,932
No
output
1
101,966
23
203,933
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from bisect import insort from collections import Counter from collections import deque from heapq import heappush,heappop,heapify from itertools import permutations,combinations from itertools import accumulate as ac mod = int(1e9)+7 #mod = 998244353 ip = lambda : int(stdin.readline()) inp = lambda: map(int,stdin.readline().split()) ips = lambda: stdin.readline().rstrip() out = lambda x : stdout.write(str(x)+"\n") t = int(input()) for _ in range(t) : n = ip() ans = 0 i = 3 while i*i<= 2*n -1: ans += 1 i += 2 print(ans) ```
instruction
0
102,277
23
204,554
Yes
output
1
102,277
23
204,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import math def solve(n,ans): odd = int(math.ceil(n/2)) low = 0 high = odd k = -1 while low <= high: mid = (low+high)//2 sq = pow(2*mid+1,2) b = sq//2 if b+1 <= n: low = mid+1 k = mid else: high = mid-1 ans.append(str(k)) def main(): t = int(input()) ans = [] for i in range(t): n = int(input()) solve(n,ans) print('\n'.join(ans)) main() ```
instruction
0
102,278
23
204,556
Yes
output
1
102,278
23
204,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` k = int(((10**9)*2 - 1)**0.5) dp = [0]*(k+1) for a in range(1,k+1): if (a**2)%2!=0: if a**2 - 1>0: dp[a] = dp[a-1] + 1 else: dp[a] = dp[a-1] else: dp[a] = dp[a-1] #print(dp) for _ in range(int(input())): n = int(input()) n = int((2*n - 1)**0.5) ans = dp[n] print(ans) ```
instruction
0
102,279
23
204,558
Yes
output
1
102,279
23
204,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase import math import itertools import bisect import heapq def main(): pass BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def binary(n): return (bin(n).replace("0b", "")) def decimal(s): return (int(s, 2)) def pow2(n): p = 0 while (n > 1): n //= 2 p += 1 return (p) def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n / i if n > 2: l.append(int(n)) return (l) def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) def maxPrimeFactors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime) def countcon(s, i): c = 0 ch = s[i] for i in range(i, len(s)): if (s[i] == ch): c += 1 else: break return (c) def lis(arr): n = len(arr) lis = [1] * n for i in range(1, n): for j in range(0, i): if arr[i] > arr[j] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 maximum = 0 for i in range(n): maximum = max(maximum, lis[i]) return maximum def isSubSequence(str1, str2): m = len(str1) n = len(str2) j = 0 i = 0 while j < m and i < n: if str1[j] == str2[i]: j = j + 1 i = i + 1 return j == m def maxfac(n): root = int(n ** 0.5) for i in range(2, root + 1): if (n % i == 0): return (n // i) return (n) def p2(n): c=0 while(n%2==0): n//=2 c+=1 return c def seive(n): primes=[True]*(n+1) primes[1]=primes[0]=False for i in range(2,n+1): if(primes[i]): for j in range(i+i,n+1,i): primes[j]=False p=[] for i in range(0,n+1): if(primes[i]): p.append(i) return(p) def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p def denofactinverse(n,m): fac=1 for i in range(1,n+1): fac=(fac*i)%m return (pow(fac,m-2,m)) def numofact(n,m): fac = 1 for i in range(1, n + 1): fac = (fac * i) % m return(fac) for _ in range(0,int(input())): n=int(input()) t=2*n-1 t=int(t**0.5) #print(t) print(math.ceil(t/2)-1) ```
instruction
0
102,280
23
204,560
Yes
output
1
102,280
23
204,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import math for _ in range(int(input())): n=int(input()) s=math.floor(math.sqrt(2*n))//2 print(s) ```
instruction
0
102,281
23
204,562
No
output
1
102,281
23
204,563
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import sys import os.path if(os.path.exists('input_file.txt')): sys.stdin = open("input_file.txt", "r") sys.stdout = open("output_file.txt", "w") mod=1000000007 def factorial(a): ans=1 for i in range(1,a+1): ans=(ans*i)%mod return ans #perfectsuare, other shorthanded for _ in range(int(input())): n=int(input()) ans=int((2*n+1)**.5) if ans%2==0: print((ans//2)-1) else:print(ans//2) ```
instruction
0
102,282
23
204,564
No
output
1
102,282
23
204,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import math i=2 x=int(999999999**0.5)+100 dp=[0,0] ans=0 a=0 b=0 c=0 while(i<=x): a=i b=(a*a-1)//2 c=b+1 if a*a+b*b==c*c: ans+=1 dp.append(ans) i+=1 x=len(dp) for _ in range(int(input())): n=int(input()) print(dp[math.ceil(n**0.5)]) ```
instruction
0
102,283
23
204,566
No
output
1
102,283
23
204,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5). Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Each test case consists of one line containing one integer n (1 ≀ n ≀ 10^9). Output For each test case, print one integer β€” the number of triples of integers (a, b, c) with 1 ≀ a ≀ b ≀ c ≀ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. Example Input 3 3 6 9 Output 0 1 1 Note The only Pythagorean triple satisfying c = a^2 - b with 1 ≀ a ≀ b ≀ c ≀ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") import math t=int(input()) for _ in range(t): n=int(input()) ans=0 for i in range(2,n+1): x=2*i+1 s=math.sqrt(x) if int(s+0.5)**2==x: ans+=1 print(ans) ```
instruction
0
102,284
23
204,568
No
output
1
102,284
23
204,569
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): * point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y * point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y * point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y * point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. Input The first input line contains the only integer n (1 ≀ n ≀ 200) β€” the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≀ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. Output Print the only number β€” the number of supercentral points of the given set. Examples Input 8 1 1 4 2 3 1 1 2 0 2 0 1 1 0 1 3 Output 2 Input 5 0 0 0 1 1 0 0 -1 -1 0 Output 1 Note In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point β€” point (0, 0).
instruction
0
102,317
23
204,634
Tags: implementation Correct Solution: ``` def isLeft(pt,pt_l): return (pt[1] == pt_l[1] and pt_l[0]<pt[0]) def isRight(pt,pt_r): return (pt[1] == pt_r[1] and pt_r[0]>pt[0]) def isUpper(pt,pt_u): return (pt[1]< pt_u[1] and pt_u[0]==pt[0]) def isLower(pt,pt_lo): return (pt[1] > pt_lo[1] and pt_lo[0]== pt[0]) n=int(input()) points =[] for i in range(n): points.append(list(map(int,input().split(' ')))) count=0 ori_points = points super_central ={'Left':False,'Right':False,'Lower':False,'Upper':False } for i in range(len(ori_points)): for k in super_central: super_central[k] = False for j in range(len(ori_points)): if(i!=j): if(isLeft(ori_points[i],ori_points[j])): super_central['Left'] = True elif(isRight(ori_points[i],ori_points[j])): super_central['Right'] = True elif(isUpper(ori_points[i],ori_points[j])): super_central['Upper'] = True elif(isLower(ori_points[i],ori_points[j])): super_central['Lower'] = True if all(super_central.values()): count +=1 print(count) ```
output
1
102,317
23
204,635