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
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` print(int((int(input())+int(input()))/2*int(input()))) ```
instruction
0
30,839
23
61,678
Yes
output
1
30,839
23
61,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` a, b, h = map(int, [input() for i in range(3)]) print((a + b) * h // 2) ```
instruction
0
30,840
23
61,680
Yes
output
1
30,840
23
61,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` a, b, c = map(int, open(0)) print((a + b) * (c // 2)) ```
instruction
0
30,841
23
61,682
Yes
output
1
30,841
23
61,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` a,b,h=int(input()),int(input()),int(input()) print(int(((a+b)*h)/2)) ```
instruction
0
30,842
23
61,684
Yes
output
1
30,842
23
61,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` a = int(input()) b = int(input()) h = int(input()) s = 0.5 * (a + b) * h ```
instruction
0
30,843
23
61,686
No
output
1
30,843
23
61,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` a, b, h = int(input()), int(input()), int(input()) res = (a+b)**2 / h print(res) ```
instruction
0
30,844
23
61,688
No
output
1
30,844
23
61,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` l = [int(input()) for i in range(3)] s = (l[0] + l[1]) * l[2] / 2 print(s) ```
instruction
0
30,845
23
61,690
No
output
1
30,845
23
61,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. <image> An example of a trapezoid Find the area of this trapezoid. Constraints * 1≦a≦100 * 1≦b≦100 * 1≦h≦100 * All input values are integers. * h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Examples Input 3 4 2 Output 7 Input 4 4 4 Output 16 Submitted Solution: ``` a,b,h=[int(input()) for i in range(3)] print(a*b*h/2) ```
instruction
0
30,846
23
61,692
No
output
1
30,846
23
61,693
Provide a correct Python 3 solution for this coding contest problem. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3
instruction
0
30,913
23
61,826
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def intersection(a1, a2, b1, b2): x1,y1 = a1 x2,y2 = a2 x3,y3 = b1 x4,y4 = b2 ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1) eta = (x2 - x1) * (y4 - y1) - (y2 - y1) * (x4 - x1) delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3) if delta == 0: return None ramda = ksi / delta; mu = eta / delta; if ramda >= 0 and ramda <= 1 and mu >= 0 and mu <= 1: return (round(x1 + ramda * (x2 - x1), 9), round(y1 + ramda * (y2 - y1), 9)) return None def main(): rr = [] def f(n): def _f(l): return [(l[0],l[1]), (l[2],l[3])] a = [_f(LI()) for _ in range(n)] r = 1 + n itc = collections.defaultdict(int) for i in range(n): a1,a2 = a[i] for j in range(i+1,n): it = intersection(a1,a2,a[j][0],a[j][1]) if not it: continue if max(it) == 100 or min(it) == -100: continue itc[it] += 1 # print('itc',itc) for v in itc.values(): if v <= 1: r += v continue for i in range(101): if v == i * (i+1) / 2: r += i break return r while 1: n = I() if n == 0: break rr.append(f(n)) return '\n'.join(map(str,rr)) print(main()) ```
output
1
30,913
23
61,827
Provide a correct Python 3 solution for this coding contest problem. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3
instruction
0
30,914
23
61,828
"Correct Solution: ``` def _f(px, py, qx, qy, rx, ry): return (qx - px) * (ry - py) - (qy - py) * (rx - px) def intersect(px, py, qx, qy, rx, ry, sx, sy): f1 = _f(px, py, qx, qy, rx, ry) f2 = _f(px, py, qx, qy, sx, sy) f3 = _f(rx, ry, sx, sy, px, py) f4 = _f(rx, ry, sx, sy, qx, qy) return f1 * f2 < 0 and f3 * f4 < 0 def intersection(px, py, qx, qy, rx, ry, sx, sy): det = (px - qx) * (sy - ry) - (sx - rx) * (py - qy) t = ((sy - ry) * (sx - qx) + (rx - sx) * (sy - qy)) / det x = t * px + (1 - t) * qx y = t * py + (1 - t) * qy return (x, y) def solve(): from sys import stdin f_i = stdin while True: n = int(f_i.readline()) if n == 0: break area = 1 segments = set() for i in range(n): px, py, qx, qy = map(int, f_i.readline().split()) points = set() cnt = 1 for rx, ry, sx, sy in segments: if intersect(px, py, qx, qy, rx, ry, sx, sy): ip = intersection(px, py, qx, qy, rx, ry, sx, sy) if ip not in points: cnt += 1 points.add(ip) segments.add((px, py, qx, qy)) area += cnt print(area) solve() ```
output
1
30,914
23
61,829
Provide a correct Python 3 solution for this coding contest problem. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3
instruction
0
30,915
23
61,830
"Correct Solution: ``` def make_line(line_str): x1, y1, x2, y2 = map(int, line_str.split()) return (x1 + 1j * y1, x2 + 1j * y2) def cross_point(l1, l2): (p1, p2), (p3, p4) = l1, l2 v34, v12, v23, v31 = p4 - p3, p2 - p1, p3 - p2, p1 - p3 s1 = v34.real * v31.imag - v34.imag * v31.real s2 = v34.real * v23.imag - v34.imag * v23.real if s1 + s2 == 0: return None rt = s1 / (s1 + s2) if 0 < rt < 1: cp = (p1 + v12 * rt) * 1e10 return (int(cp.real), int(cp.imag)) else: return None while True: n = int(input()) if not n: break lines = [make_line(input()) for _ in range(n)] num_crossed = 0 for i, line in enumerate(lines): crossed = set(cross_point(line, l) for l in lines[:i]) crossed.discard(None) num_crossed += len(crossed) print(1 + n + num_crossed) ```
output
1
30,915
23
61,831
Provide a correct Python 3 solution for this coding contest problem. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3
instruction
0
30,916
23
61,832
"Correct Solution: ``` def make_line(line_str): x1, y1, x2, y2 = map(int, line_str.split()) return (x1 + 1j * y1, x2 + 1j * y2) def cross_point(l1, l2): (p1, p2), (p3, p4) = l1, l2 v34, v12, v23, v31 = p4 - p3, p2 - p1, p3 - p2, p1 - p3 s1 = v34.real * v31.imag - v34.imag * v31.real s2 = v34.real * v23.imag - v34.imag * v23.real if s1 + s2 == 0: return None rt = s1 / (s1 + s2) cp = p1 + v12 * rt if abs(cp.real) >= 100 or abs(cp.imag) >= 100: return None cp *= 1e10 return (int(cp.real), int(cp.imag)) while True: n = int(input()) if not n: break lines = [make_line(input()) for _ in range(n)] num_crossed = 0 for i, line in enumerate(lines): current_crossed = set(cross_point(line, l) for l in lines[:i]) current_crossed.discard(None) num_crossed += len(current_crossed) print(1 + n + num_crossed) ```
output
1
30,916
23
61,833
Provide a correct Python 3 solution for this coding contest problem. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3
instruction
0
30,917
23
61,834
"Correct Solution: ``` import math EPS = 1e-10 def eq(a, b): return (abs(a-b) < EPS) def eqv(a, b): return (eq(a.real, b.real) and eq(a.imag, b.imag)) def cross(a, b): return a.real * b.imag - a.imag * b.real def is_intersected_ls(a1, a2, b1, b2): return (cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS) and \ (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS) def intersection_l(a1, a2, b1, b2): a = a2 - a1 b = b2 - b1 return a1 + a * cross(b, b1-a1) / cross(b, a) while True: n = int(input()) if n==0: break lines = [] for _ in range(n): x1, y1, x2, y2 = map(int, input().split()) lines.append((complex(x1, y1), complex(x2, y2))) ans = 2 for i in range(1, n): cross_point = [] for j in range(0, i): l1, l2 = lines[i], lines[j] if is_intersected_ls(l1[0], l1[1], l2[0], l2[1]): p = intersection_l(l1[0], l1[1], l2[0], l2[1]) if -100+EPS<=p.real<=100-EPS and -100+EPS<=p.imag<=100-EPS: cross_point.append(p) cnt = min(len(cross_point), 1) for i in range(1, len(cross_point)): flag = 0 for j in range(0, i): if eqv(cross_point[i], cross_point[j]): flag = 1 if not flag: cnt+=1 ans += 1+cnt print(ans) ```
output
1
30,917
23
61,835
Provide a correct Python 3 solution for this coding contest problem. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3
instruction
0
30,918
23
61,836
"Correct Solution: ``` #!/usr/bin/env python from collections import deque import itertools as it import sys import math sys.setrecursionlimit(1000000) def gcd(a, b): if b == 0: return a a1 = b b1 = a % b return gcd(a1, b1) while True: n = int(input()) if n == 0: break line = [] for loop in range(n): x1, y1, x2, y2 = list(map(int, input().split())) # ax + by + c = 0 a = y1 - y2 b = x2 - x1 c = -x1 * a - y1 * b line.append((a, b, c)) ans = n + 1 m = {} for i in range(n): for j in range(i + 1, n): l1 = line[i] l2 = line[j] det = l1[0] * l2[1] - l1[1] * l2[0] deta = int(abs(det)) if det == 0: continue x = l2[1] * l1[2] - l1[1] * l2[2] y = -l2[0] * l1[2] + l1[0] * l2[2] if x > -100 * deta and x < 100 * deta and y > -100 * deta and y < 100 * deta: ans += 1 G = gcd(gcd(int(abs(x)), int(abs(y))), int(abs(det))) x //= G y //= G det //= G if det < 0: x *= -1 y *= -1 det *= -1 if (x, y, det) in m: m[(x, y, det)] += 1 else: m[(x, y, det)] = 1 for p in m: S = 0 cnt = 0 while True: S += cnt if m[p] == S: ans -= cnt * (cnt - 1) // 2 break cnt += 1 print(ans) ```
output
1
30,918
23
61,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3 Submitted Solution: ``` from itertools import combinations from decimal import Decimal def get_point(line1, line2): m1, k1 = line1 m2, k2 = line2 if m1 == m2: return None elif m1 is None and m2 is None: return None elif m1 is None: x = k1 y = m2 * x + k2 elif m2 is None: x = k2 y = m1 * x + k1 else: x = (k2-k1)/(m2-m1) y = m1*x+k return (x, y) while True: N = int(input()) if not N: break lines = [] for i in range(N): x1, y1, x2, y2 = [Decimal(int(i)) for i in input().split()] if x1 == x2: lines.append(None, x1) else: m = (y2-y1) / (x2-x1) k = y1 - m * x1 lines.append((m, k)) iterated_lines = [] ans = 1 for line1 in lines: pt_set = set() for line2 in iterated_lines: pt = get_point(line1, line2) # print(pt) if pt: pt_set.add(pt) ans += len(pt_set) + 1 iterated_lines.append(line1) print(ans) ```
instruction
0
30,919
23
61,838
No
output
1
30,919
23
61,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3 Submitted Solution: ``` from itertools import combinations from decimal import Decimal def get_point(line1, line2): m1, k1 = line1 m2, k2 = line2 if m1 == m2: return None elif m1 is None and m2 is None: return None elif m1 is None: x = k1 y = m2 * x + k2 elif m2 is None: x = k2 y = m1 * x + k1 else: x = (k2-k1)/(m2-m1) y = m1*x+k if -100 < x < 100 and -100 < y < 100: return (x, y) else: return None while True: N = int(input()) if not N: break lines = [] for i in range(N): x1, y1, x2, y2 = [Decimal(int(i)) for i in input().split()] if x1 == x2: lines.append((None, x1)) else: m = (y2-y1) / (x2-x1) k = y1 - m * x1 lines.append((m, k)) iterated_lines = [] ans = 1 for line1 in lines: pt_set = set() for line2 in iterated_lines: pt = get_point(line1, line2) # print(pt) if pt: pt_set.add(pt) ans += len(pt_set) + 1 iterated_lines.append(line1) print(ans) ```
instruction
0
30,920
23
61,840
No
output
1
30,920
23
61,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3 Submitted Solution: ``` def make_line(line_str): x1, y1, x2, y2 = map(int, line_str.split()) return (x1 + 1j * y1, x2 + 1j * y2) def cross_point(l1, l2): (p1, p2), (p3, p4) = l1, l2 v34, v12, v23, v31 = p4 - p3, p2 - p1, p3 - p2, p1 - p3 s1 = v34.real * v31.imag - v34.imag * v31.real s2 = v34.real * v23.imag - v34.imag * v23.real if s1 + s2 == 0: return None rt = s1 / (s1 + s2) cp = p1 + v12 * rt if abs(cp.real) >= 100 or abs(cp.imag) >= 100: return None cp *= 1e10 return (int(cp.real), int(cp.imag)) while True: n = int(input()) if not n: break lines = [make_line(input()) for _ in range(n)] crossed = set() for i, line in enumerate(lines): crossed.update(cross_point(line, l) for l in lines[:i]) crossed.discard(None) print(1 + n + len(crossed)) ```
instruction
0
30,921
23
61,842
No
output
1
30,921
23
61,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his promotion is certain. However, there are many people who are not happy with his career advancement. One such person was Mr. Sato Seabreeze Suzuki. He has planned to pull Mr. Yamada's foot every time. Again, Mr. Sato put pressure on the organization responsible for the actual land readjustment in order to pull back, making the land readjustment results very confusing. Therefore, the result passed to Mr. Yamada was only information about which straight line divided a square land. At the very least, Mr. Yamada is sure to be fired rather than promoted if he doesn't know just how many divisions the square land has. Your job is how many square regions with vertices (-100, -100), (100, -100), (100, 100), (-100, 100) are divided by a given n straight lines. To save Mr. Yamada from the crisis of dismissal by writing a program to find out. Input The input consists of multiple test cases. The first line of each test case is given the integer n representing the number of straight lines (1 <= n <= 100). Subsequent n lines contain four integers x1, y1, x2, and y2, respectively. These integers represent two different points (x1, y1) and (x2, y2) on a straight line. The two points given are always guaranteed to be points on the sides of the square. The n straight lines given are different from each other, and the straight lines do not overlap. Also, the straight line does not overlap the sides of the square. The end of input is represented by n = 0. Output For each test case, print the number of regions divided by n straight lines in one line. Two points with a distance of less than 10-10 can be considered to match. Also, there is no set of intersections P, Q, R such that | PQ | <10-10, | QR | <10-10 and | PR |> = 10-10. Example Input 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 Output 4 3 Submitted Solution: ``` from itertools import combinations from decimal import Decimal def get_point(line1, line2): m1, k1 = line1 m2, k2 = line2 if m1 == m2: return None elif m1 is None and m2 is None: return None elif m1 is None: x = k1 y = m2 * x + k2 elif m2 is None: x = k2 y = m1 * x + k1 else: x = (k2-k1)/(m2-m1) y = m1*x+k if -100 < x < 100 and -100 < y < 100: return (x, y) else: return None while True: N = int(input()) if not N: break lines = [] for i in range(N): x1, y1, x2, y2 = [Decimal(int(i)) for i in input().split()] if x1 == x2: lines.append(None, x1) else: m = (y2-y1) / (x2-x1) k = y1 - m * x1 lines.append((m, k)) iterated_lines = [] ans = 1 for line1 in lines: pt_set = set() for line2 in iterated_lines: pt = get_point(line1, line2) # print(pt) if pt: pt_set.add(pt) ans += len(pt_set) + 1 iterated_lines.append(line1) print(ans) ```
instruction
0
30,922
23
61,844
No
output
1
30,922
23
61,845
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,929
23
61,858
"Correct Solution: ``` from math import sqrt if __name__ == "__main__": c1x, c1y, c1r = map(float, input().split()) c2x, c2y, c2r = map(float, input().split()) dx, dy = c2x - c1x, c2y - c1y cdist = dx ** 2 + dy ** 2 a = (cdist + c1r ** 2 - c2r ** 2) / 2 df = sqrt(cdist * c1r ** 2 - a ** 2) ix1, ix2 = (a * dx + dy * df) / cdist, (a * dx - dy * df) / cdist iy1, iy2 = (a * dy - dx * df) / cdist, (a * dy + dx * df) / cdist if (ix1, iy1) > (ix2, iy2): ix1, ix2, iy1, iy2 = ix2, ix1, iy2, iy1 print(ix1 + c1x, iy1 + c1y, ix2 + c1x, iy2 + c1y) ```
output
1
30,929
23
61,859
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,930
23
61,860
"Correct Solution: ``` import math class Point: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Point(self.x + other.x, self.y + other.y) def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def __mul__(self, other): return Point(self.x * other, self.y * other) def __truediv__(self, other): return Point(self.x / other, self.y / other) def __repr__(self): return str(round(self.x, 8)) + ' ' + str(round(self.y, 8)) def __lt__(self, other): if self.x == other.x: return self.y < other.y else: return self.x < other.x class Vector(Point): pass class Line: def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 class Segment(Line): pass class Circle: def __init__(self, c, r): self.c = c self.r = r def points_to_vector(p1, p2): x = p1.x - p2.x y = p1.y - p2.y return Vector(x, y) def vector(p): return Vector(p.x, p.y) def dot(v1, v2): return v1.x * v2.x + v1.y * v2.y def cross(v1, v2): return v1.x * v2.y - v1.y * v2.x def norm(v): return v.x**2 + v.y**2 def distance(v): return math.sqrt(norm(v)) def project(s, p): base = points_to_vector(s.p1, s.p2) hypo = points_to_vector(p, s.p1) r = dot(hypo, base) / norm(base) return s.p1 + base * r def reflect(s, p): return p + (project(s, p) -p) * 2 def get_distance(s1, s2): if intersect_s(s1, s2): return 0 d1 = get_distance_sp(s1, s2.p1) d2 = get_distance_sp(s1, s2.p2) d3 = get_distance_sp(s2, s1.p1) d4 = get_distance_sp(s2, s1.p2) return min(d1, min(d2, min(d3, d4))) def get_distance_pp(p1, p2): return distance(p1 - p2) def get_distance_lp(l, p): return abs(cross(l.p2 - l.p1, p - l.p1) / distance(l.p2 - l.p1)) def get_distance_sp(s, p): if dot(s.p2 - s.p1, p - s.p1) < 0: return distance(p - s.p1) elif dot(s.p1 - s.p2, p - s.p2) < 0: return distance(p - s.p2) else: return get_distance_lp(s, p) def ccw(p0, p1, p2): EPS = 1e-10 COUNTER_CLOCKWISE = 1 CLOCKWISE = -1 ONLINE_BACK = 2 ONLINE_FRONT = -2 ON_SEGMENT = 0 v1 = p1 - p0 v2 = p2 - p0 if cross(v1, v2) > EPS: return COUNTER_CLOCKWISE elif cross(v1, v2) < -EPS: return CLOCKWISE elif dot(v1, v2) < -EPS: return ONLINE_BACK elif norm(v1) < norm(v2): return ONLINE_FRONT else: return ON_SEGMENT def intersect_p(p1, p2, p3, p4): return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0 def intersect_s(s1, s2): return intersect_p(s1.p1, s1.p2, s2.p1, s2.p2) def get_cross_point(s1, s2): base = s2.p2 - s2.p1 d1 = abs(cross(base, s1.p1 - s2.p1)) d2 = abs(cross(base, s1.p2 - s2.p1)) t = d1 / (d1 + d2) return s1.p1 + (s1.p2 - s1.p1) * t def get_cross_points(c, l): pr = project(l, c.c) e = (l.p2 - l.p1) / distance(l.p2 - l.p1) base = math.sqrt(c.r**2 - norm(pr - c.c)) return pr + e * base, pr - e * base def arg(p): return math.atan2(p.y, p.x) def polar(a, r): return Point(math.cos(r) * a, math.sin(r) * a) def get_cross_points_cirlces(c1, c2): d = distance(c1.c - c2.c) a = math.acos((c1.r**2 + d * d - c2.r**2) / (2 * c1.r * d)) t = arg(c2.c - c1.c) return c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a) import sys # sys.stdin = open('input.txt') temp = list(map(int, input().split())) c1 = Circle(Point(temp[0], temp[1]), temp[2]) temp = list(map(int, input().split())) c2 = Circle(Point(temp[0], temp[1]), temp[2]) ans = get_cross_points_cirlces(c1, c2) print(min(ans), max(ans)) ```
output
1
30,930
23
61,861
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,931
23
61,862
"Correct Solution: ``` # -*- coding: utf-8 -*- import collections import math class Vector2(collections.namedtuple("Vector2", ["x", "y"])): def __add__(self, other): return Vector2(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector2(self.x - other.x, self.y - other.y) def __mul__(self, scalar): return Vector2(self.x * scalar, self.y * scalar) def __neg__(self): return Vector2(-self.x, -self.y) def __pos__(self): return Vector2(+self.x, +self.y) def __abs__(self): # norm return math.sqrt(float(self.x * self.x + self.y * self.y)) def __truediv__(self, scalar): return Vector2(self.x / scalar, self.y / scalar) def abs2(self): return float(self.x * self.x + self.y * self.y) def dot(self, other): # dot product return self.x * other.x + self.y * other.y def cross(self, other): # cross product return self.x * other.y - self.y * other.x def getDistanceSP(segment, point): p = point p1, p2 = segment if (p2 - p1).dot(p - p1) < 0: return abs(p - p1) if (p1 - p2).dot(p - p2) < 0: return abs(p - p2) return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1) def getDistance(s1, s2): a, b = s1 c, d = s2 if intersect(s1, s2): # intersect return 0 return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b)) def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if a.cross(b) > 0: return 1 # COUNTER_CLOCKWISE elif a.cross(b) < 0: return -1 # CLOCKWISE elif a.dot(b) < 0: return 2 # ONLINE_BACK elif abs(a) < abs(b): return -2 # ONLINE_FRONT else: return 0 # ON_SEGMENT def intersect(s1, s2): a, b = s1 c, d = s2 return ccw(a, b, c) * ccw(a, b, d) <= 0 and ccw(c, d, a) * ccw(c, d, b) <= 0 def project(l, p): p1, p2 = l base = p2 - p1 hypo = p - p1 return p1 + base * (hypo.dot(base) / abs(base)**2) class Circle(): def __init__(self, c, r): self.c = c self.r = r def getCrossPoints(c, l): pr = project(l, c.c) p1, p2 = l e = (p2 - p1) / abs(p2 - p1) base = math.sqrt(c.r * c.r - (pr - c.c).abs2()) return [pr + e * base, pr - e * base] def polar(r, a): return Vector2(r * math.cos(a), r * math.sin(a)) def getCrossPointsCircle(c1, c2): base = c2.c - c1.c d = abs(base) a = math.acos((c1.r**2 + d**2 - c2.r**2) / (2 * c1.r * d)) t = math.atan2(base.y, base.x) return [c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)] if __name__ == '__main__': a, b, r = map(int, input().split()) c1 = Circle(Vector2(a, b), r) a, b, r = map(int, input().split()) c2 = Circle(Vector2(a, b), r) ans = getCrossPointsCircle(c1, c2) ans = sorted(ans, key=lambda x: (x.x, x.y)) print("{:.8f} {:.8f} {:.8f} {:.8f}".format( ans[0].x, ans[0].y, ans[1].x, ans[1].y)) ```
output
1
30,931
23
61,863
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,932
23
61,864
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) INF=float('inf') class Geometry: EPS = 10 ** -9 def add(self, a, b): x1, y1 = a x2, y2 = b return (x1+x2, y1+y2) def sub(self, a, b): x1, y1 = a x2, y2 = b return (x1-x2, y1-y2) def mul(self, a, b): x1, y1 = a if not isinstance(b, tuple): return (x1*b, y1*b) x2, y2 = b return (x1*x2, y1*y2) def div(self, a, b): x1, y1 = a if not isinstance(b, tuple): return (x1/b, y1/b) x2, y2 = b return (x1/x2, y1/y2) def abs(self, a): from math import hypot x1, y1 = a return hypot(x1, y1) def norm(self, a): x, y = a return x**2 + y**2 def dot(self, a, b): x1, y1 = a x2, y2 = b return x1*x2 + y1*y2 def cross(self, a, b): x1, y1 = a x2, y2 = b return x1*y2 - y1*x2 def project(self, seg, p): """ 線分segに対する点pの射影 """ p1, p2 = seg base = self.sub(p2, p1) r = self.dot(self.sub(p, p1), base) / self.norm(base) return self.add(p1, self.mul(base, r)) def reflect(self, seg, p): """ 線分segを対称軸とした点pの線対称の点 """ return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2)) def ccw(self, p0, p1, p2): """ 線分p0,p1から線分p0,p2への回転方向 """ a = self.sub(p1, p0) b = self.sub(p2, p0) # 反時計回り if self.cross(a, b) > self.EPS: return 1 # 時計回り if self.cross(a, b) < -self.EPS: return -1 # 直線上(p2 => p0 => p1) if self.dot(a, b) < -self.EPS: return 2 # 直線上(p0 => p1 => p2) if self.norm(a) < self.norm(b): return -2 # 直線上(p0 => p2 => p1) return 0 def intersect(self, seg1, seg2): """ 線分seg1と線分seg2の交差判定 """ p1, p2 = seg1 p3, p4 = seg2 return ( self.ccw(p1, p2, p3) * self.ccw(p1, p2, p4) <= 0 and self.ccw(p3, p4, p1) * self.ccw(p3, p4, p2) <= 0 ) def get_distance_LP(self, line, p): """ 直線lineと点pの距離 """ p1, p2 = line return abs(self.cross(self.sub(p2, p1), self.sub(p, p1)) / self.abs(self.sub(p2, p1))) def get_distance_SP(self, seg, p): """ 線分segと点pの距離 """ p1, p2 = seg if self.dot(self.sub(p2, p1), self.sub(p, p1)) < 0: return self.abs(self.sub(p, p1)) if self.dot(self.sub(p1, p2), self.sub(p, p2)) < 0: return self.abs(self.sub(p, p2)) return self.get_distance_LP(seg, p) def get_distance_SS(self, seg1, seg2): """ 線分seg1と線分seg2の距離 """ p1, p2 = seg1 p3, p4 = seg2 if self.intersect(seg1, seg2): return 0 return min( self.get_distance_SP(seg1, p3), self.get_distance_SP(seg1, p4), self.get_distance_SP(seg2, p1), self.get_distance_SP(seg2, p2), ) def get_cross_pointSS(self, seg1, seg2): """ 線分seg1と線分seg2の交点 """ p1, p2 = seg1 p3, p4 = seg2 base = self.sub(p4, p3) dist1 = abs(self.cross(base, self.sub(p1, p3))) dist2 = abs(self.cross(base, self.sub(p2, p3))) t = dist1 / (dist1+dist2) return self.add(p1, self.mul(self.sub(p2, p1), t)) def get_cross_pointCL(self, c, line): """ 円cと直線lineの交点 """ from math import sqrt # if not intersect(c, line): return -1 x, y, r = c p1, p2 = line pr = self.project(line, (x, y)) e = self.div(self.sub(p2, p1), self.abs(self.sub(p2, p1))) base = sqrt(r*r - self.norm(self.sub(pr, (x, y)))) return [self.add(pr, self.mul(e, base)), self.sub(pr, self.mul(e, base))] def arg(self, p): from math import atan2 x, y = p return atan2(y, x) def polar(self, a, r): from math import sin, cos return (cos(r)*a, sin(r)*a) def get_cross_pointCC(self, c1, c2): """ 円c1と円c2の交点 """ from math import acos # if not intersect(c1, c2): return -1 x1, y1, r1 = c1 x2, y2, r2 = c2 d = self.abs(self.sub((x1, y1), (x2, y2))) a = acos((r1*r1+d*d-r2*r2) / (2*r1*d)) t = self.arg(self.sub((x2, y2), (x1, y1))) return [self.add((x1, y1), self.polar(r1, t+a)), self.add((x1, y1), self.polar(r1, t-a))] gm = Geometry() x1, y1, r1 = MAP() x2, y2, r2 = MAP() c1 = (x1, y1, r1) c2 = (x2, y2, r2) res = gm.get_cross_pointCC(c1, c2) res.sort() # 2次元タプルをsumの第2引数で1次元にする res = sum(res, ()) for i in range(3): print('{:.10f}'.format(res[i]), end=' ') print('{:.10f}'.format(res[-1])) ```
output
1
30,932
23
61,865
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,933
23
61,866
"Correct Solution: ``` # coding: utf-8 # Your code here! import math EPS = 0.0000000001 COUNTER_CLOCKWISE = 1 CLOCKWISE = -1 ONLINE_BACK = 2 ONLINE_FRONT = -2 ON_SEGMENT = 0 class Point: global EPS def __init__(self, x = 0, y = 0): self.x = x self.y = y def __add__(a, b): s = a.x + b.x t = a.y + b.y return Point(s, t) def __sub__(a, b): s = a.x - b.x t = a.y - b.y return Point(s, t) def __mul__(self, a): s = a * self.x t = a * self.y return Point(s, t) def __truediv__(self, a): s = self.x / a t = self.y / a return Point(s, t) def norm(self): return self.x * self.x + self.y * self.y def abs(self): return self.norm() ** 0.5 def __eq__(self, other): return abs(self.x - other.y) < self.EPS and abs(self.y - other.y) < self.EPS def dot(self, b): return self.x * b.x + self.y * b.y def cross(self, b): return self.x * b.y - self.y * b.x class Segment: def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 class Circle: def __init__(self, c, r): self.c = c self.r = r def project(s, p): base = s.p2 - s.p1 hypo = p - s.p1 r = hypo.dot(base) / base.norm() return s.p1 + base * r def reflecton(s, p): return p + (project(s,p) - p) * 2 def getDistance(a, b): return (a-b).abs() def getDistanceLP(l, p): return abs((l.p2-l.p1).cross(p-l.p1)) / ((l.p2-l.p1).abs()) def getDistanceSP(s, p): if (s.p2 - s.p1).dot(p-s.p1) < 0: return (p-s.p1).abs() elif (s.p1 - s.p2).dot(p-s.p2) < 0: return (p-s.p2).abs() return getDistanceLP(s,p) def getDistanceSS(s1, s2): if intersectS(s1, s2): return 0 return min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2), getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)) def ccw(p0, p1, p2): a = p1-p0 b = p2-p0 if a.cross(b) > 0: return COUNTER_CLOCKWISE elif a.cross(b) <0: return CLOCKWISE elif a.dot(b) < 0: return ONLINE_BACK elif a.abs() < b.abs(): return ONLINE_FRONT else: return ON_SEGMENT def intersect(p1, p2, p3, p4): return ccw(p1, p2, p3) *ccw(p1, p2, p4) <=0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0 def intersectS(s1, s2): return intersect(s1.p1, s1.p2, s2.p1, s2.p2) def getCrossPoint(s1, s2): base = s2.p2-s2.p1 a = s1.p1-s2.p1 b = s1.p2-s2.p1 d1 = abs(a.cross(base)) d2 = abs(b.cross(base)) t = d1 / (d1+d2) return s1.p1 + (s1.p2-s1.p1) * t def getCrossPointC(c, l): pr = project(l, c.c) e = (l.p2-l.p1) / (l.p2-l.p1).abs() base = (c.r *c.r - (pr - c.c).norm()) ** 0.5 return pr - e * base, pr + e * base def printPoint(p1, p2): print(round(p1.x, 8), round(p1.y, 8), round(p2.x, 8), round(p2.y, 8)) def arg(p): return math.atan2(p.y ,p.x) def polar(a, r): return Point(a * math.cos(r), a * math.sin(r)) def getCrossPointCC(c1, c2): d = (c2.c - c1.c).abs() a = math.acos((c1.r * c1.r + d*d - c2.r*c2.r) / (2*c1.r*d)) b = arg(c2.c-c1.c) return c1.c + polar(c1.r, b+a), c1.c + polar(c1.r, b-a) nums=list(map(int,input().split())) c1 = Circle(Point(nums[0],nums[1]), nums[2]) nums=list(map(int,input().split())) c2 = Circle(Point(nums[0],nums[1]), nums[2]) p1, p2 = getCrossPointCC(c1, c2) if p1.x < p2.x: printPoint(p1, p2) elif p1.x > p2.x: printPoint(p2, p1) else: if p1.y < p2.y: printPoint(p1, p2) else: printPoint(p2, p1) ```
output
1
30,933
23
61,867
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,934
23
61,868
"Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E """ import sys from math import sqrt, atan2, acos, sin, cos from sys import stdin input = stdin.readline class Point(object): epsilon = 1e-10 def __init__(self, x=0.0, y=0.0): if isinstance(x, tuple): self.x = x[0] self.y = x[1] else: self.x = x self.y = y # ???????????? def __add__(self, other): return Point(self.x + other.x, self.y + other.y) def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def __mul__(self, other): return Point(other * self.x, other * self.y) def __truediv__(self, other): return Point(self.x / other, self.y / other) def __lt__(self, other): if self.x == other.x: return self.y < other.y else: return self.x < other.x def __eq__(self, other): from math import fabs if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon: return True else: return False def norm(self): return self.x * self.x + self.y * self.y def __abs__(self): return sqrt(self.norm()) def ccw(self, p0, p1): # ??????2???(p0, p1)?????????????????????????????????????????¢???????????? a = Vector(p1 - p0) b = Vector(self - p0) if Vector.cross(a, b) > Point.epsilon: return 1 # 'COUNTER_CLOCKWISE' elif Vector.cross(a, b) < -Point.epsilon: return -1 # 'CLOCKWISE' elif Vector.dot(a, b) < -Point.epsilon: return 2 # 'ONLINE_BACK' elif a.norm() < b.norm(): return -2 # 'ONLINE_FRONT' else: return 0 # 'ON_SEGMENT' def project(self, s): # ??????(Point)????????????s??????????????????????????????????????§?¨?(?°???±)????±??????? base = Vector(s.p2 - s.p1) a = Vector(self - s.p1) r = Vector.dot(a, base) r /= base.norm() return s.p1 + base * r def reflect(self, s): # ??????s???????§°?????¨?????????????????¨???????§°??????????????§?¨?(????°?)????±??????? proj = self.project(s) return self + (proj - self)*2 def distance(self, s): # ????????¨??????s????????¢????¨?????????? if Vector.dot(s.p2-s.p1, self-s.p1) < 0.0: return abs(self - s.p1) if Vector.dot(s.p1-s.p2, self-s.p2) < 0.0: return abs(self - s.p2) return abs(Vector.cross(s.p2-s.p1, self-s.p1) / abs(s.p2-s.p1)) class Vector(Point): def __init__(self, x=0.0, y=0.0): if isinstance(x, tuple): self.x = x[0] self.y = x[1] elif isinstance(x, Point): self.x = x.x self.y = x.y else: self.x = x self.y = y # ???????????? def __add__(self, other): return Vector(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector(self.x - other.x, self.y - other.y) def __mul__(self, other): return Vector(other * self.x, other * self.y) def __truediv__(self, other): return Vector(other / self.x, other / self.y) @classmethod def dot(cls, a, b): return a.x * b.x + a.y * b.y @classmethod def cross(cls, a, b): return a.x * b.y - a.y * b.x @classmethod def is_orthogonal(cls, a, b): return Vector.dot(a, b) == 0.0 @classmethod def is_parallel(cls, a, b): return Vector.cross(a, b) == 0.0 class Segment(object): def __init__(self, p1=Point(), p2=Point()): if isinstance(p1, Point): self.p1 = p1 self.p2 = p2 elif isinstance(p1, tuple): self.p1 = Point(p1[0], p1[1]) self.p2 = Point(p2[0], p2[1]) def intersect(self, s): # ????????¨?????????????????????????????????????????????????????? ans1 = s.p1.ccw(self.p1, self.p2) * s.p2.ccw(self.p1, self.p2) ans2 = self.p1.ccw(s.p1, s.p2) * self.p2.ccw(s.p1, s.p2) return ans1 <= 0 and ans2 <= 0 def cross_point(self, s): # ????????¨??????????????????????????????????????§?¨?????±??????? base = s.p2 - s.p1 d1 = abs(Vector.cross(base, self.p1-s.p1)) d2 = abs(Vector.cross(base, self.p2-s.p1)) t = d1 / (d1 + d2) return self.p1 + (self.p2 - self.p1) * t def distance(self, s): # ????????¨?????????????????????????????¢????±??????? if self.intersect(s): return 0.0 d1 = s.p1.distance(self) d2 = s.p2.distance(self) d3 = self.p1.distance(s) d4 = self.p2.distance(s) return min(d1, d2, d3, d4) @classmethod def is_orthogonal(cls, s1, s2): a = Vector(s1.p2 - s1.p1) b = Vector(s2.p2 - s2.p1) return Vector.is_orthogonal(a, b) @classmethod def is_parallel(cls, s1, s2): a = Vector(s1.p2 - s1.p1) b = Vector(s2.p2 - s2.p1) return Vector.is_parallel(a, b) class Line(Segment): pass class Cirle(object): def __init__(self, x, y=Point(), r=1.0): if isinstance(x, Point): self.c = x self.r = y elif isinstance(x, tuple): self.c = Point(x[0], x[1]) self.r = r def cross_points(self, s): if isinstance(s, Segment): pr = self.c.project(s) e = (s.p2 - s.p1) / abs(s.p2 - s.p1) base = sqrt(self.r * self.r - (pr - self.c).norm()) return pr + e * base, pr - e * base elif isinstance(s, Cirle): c2 = s d = abs(self.c - c2.c) a = acos((self.r * self.r + d * d - c2.r * c2.r) / (2 * self.r * d)) t = atan2(c2.c.y - self.c.y, c2.c.x - self.c.x) temp1 = Point(cos(t+a)*self.r, sin(t+a)*self.r) temp2 = Point(cos(t-a)*self.r, sin(t-a)*self.r) return self.c + temp1, self.c + temp2 def main(args): x1, y1, r1 = map(int, input().split()) c1 = Cirle(Point(x1, y1), r1) x2, y2, r2 = map(int, input().split()) c2 = Cirle(Point(x2, y2), r2) ans1, ans2 = c1.cross_points(c2) if ans1.x < ans2.x: print('{:.8f} {:.8f} {:.8f} {:.8f}'.format(ans1.x, ans1.y, ans2.x, ans2.y)) elif ans1.x == ans2.x and ans1.y <= ans2.y: print('{:.8f} {:.8f} {:.8f} {:.8f}'.format(ans1.x, ans1.y, ans2.x, ans2.y)) else: print('{:.8f} {:.8f} {:.8f} {:.8f}'.format(ans2.x, ans2.y, ans1.x, ans1.y)) if __name__ == '__main__': main(sys.argv[1:]) ```
output
1
30,934
23
61,869
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,935
23
61,870
"Correct Solution: ``` import math from typing import Union class Point(object): __slots__ = ['x', 'y'] def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Point(self.x + other.x, self.y + other.y) def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def __mul__(self, other: Union[int, float]): return Point(self.x * other, self.y * other) def norm(self): return pow(self.x, 2) + pow(self.y, 2) def abs(self): return math.sqrt(self.norm()) def __repr__(self): return f"({self.x},{self.y})" class Vector(Point): __slots__ = ['x', 'y', 'pt1', 'pt2'] def __init__(self, pt1: Point, pt2: Point): super().__init__(pt2.x - pt1.x, pt2.y - pt1.y) self.pt1 = pt1 self.pt2 = pt2 def dot(self, other): return self.x * other.x + self.y * other.y def cross(self, other): return self.x * other.y - self.y * other.x def __repr__(self): return f"{self.pt1},{self.pt2}" class Segment(Vector): __slots__ = ['x', 'y', 'pt1', 'pt2'] def __init__(self, pt1: Point, pt2: Point): super().__init__(pt1, pt2) def projection(self, pt: Point)-> Point: t = self.dot(Vector(self.pt1, pt)) / self.norm() return self.pt1 + self * t def reflection(self, pt: Point) -> Point: return self.projection(pt) * 2 - pt def is_intersected_with(self, other) -> bool: if (self.point_geometry(other.pt1) * self.point_geometry(other.pt2)) <= 0\ and other.point_geometry(self.pt1) * other.point_geometry(self.pt2) <= 0: return True else: return False def point_geometry(self, pt: Point) -> int: """ [-2:"Online Back", -1:"Counter Clockwise", 0:"On Segment", 1:"Clockwise", 2:"Online Front"] """ vec_pt1_to_pt = Vector(self.pt1, pt) cross = self.cross(vec_pt1_to_pt) if cross > 0: return -1 # counter clockwise elif cross < 0: return 1 # clockwise else: # cross == 0 dot = self.dot(vec_pt1_to_pt) if dot < 0: return -2 # online back else: # dot > 0 if self.abs() < vec_pt1_to_pt.abs(): return 2 # online front else: return 0 # on segment def cross_point(self, other) -> Point: d1 = abs(self.cross(Vector(self.pt1, other.pt1))) # / self.abs() d2 = abs(self.cross(Vector(self.pt1, other.pt2))) # / self.abs() t = d1 / (d1 + d2) return other.pt1 + other * t def distance_to_point(self, pt: Point) -> Union[int, float]: vec_pt1_to_pt = Vector(self.pt1, pt) if self.dot(vec_pt1_to_pt) <= 0: return vec_pt1_to_pt.abs() vec_pt2_to_pt = Vector(self.pt2, pt) if Vector.dot(self * -1, vec_pt2_to_pt) <= 0: return vec_pt2_to_pt.abs() return (self.projection(pt) - pt).abs() def distance_to_segment(self, other) -> Union[int, float]: if self.is_intersected_with(other): return 0.0 else: return min( self.distance_to_point(other.pt1), self.distance_to_point(other.pt2), other.distance_to_point(self.pt1), other.distance_to_point(self.pt2) ) def __repr__(self): return f"{self.pt1},{self.pt2}" class Circle(Point): __slots__ = ['x', 'y', 'r'] def __init__(self, x, y, r): super().__init__(x, y) self.r = r def cross_point_with_circle(self, other): vec_self_to_other = Vector(self, other) vec_abs = vec_self_to_other.abs() t = ((pow(self.r, 2) - pow(other.r, 2)) / pow(vec_abs, 2) + 1) / 2 pt = (other - self) * t abs_from_pt = math.sqrt(pow(self.r, 2) - pt.norm()) inv = Point(vec_self_to_other.y / vec_abs, - vec_self_to_other.x / vec_abs) * abs_from_pt pt_ = self + pt return (pt_ + inv), (pt_ - inv) def __repr__(self): return f"({self.x},{self.y}), {self.r}" def main(): c1x, c1y, c1r = map(int, input().split()) c2x, c2y, c2r = map(int, input().split()) pt1, pt2 = Circle(c1x, c1y, c1r).cross_point_with_circle(Circle(c2x, c2y, c2r)) if pt1.x > pt2.x or (pt1.x == pt2.x and pt1.y > pt2.y): tmp = pt1 pt1 = pt2 pt2 = tmp print(" ".join(map('{:.10f}'.format, [pt1.x, pt1.y, pt2.x, pt2.y]))) return main() ```
output
1
30,935
23
61,871
Provide a correct Python 3 solution for this coding contest problem. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000
instruction
0
30,936
23
61,872
"Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 0 0 2 2 0 2 output: 1.00000000 -1.73205080 1.00000000 1.73205080 """ import sys from math import sin, cos, atan2, acos from operator import attrgetter class Circle(object): __slots__ = ('centre', 'radius') def __init__(self, centre=float('inf'), radius=-1): self.centre = complex(centre) self.radius = float(radius) def arg(p_vector): return atan2(p_vector.imag, p_vector.real) def polar(a, r): return a * cos(r) + a * sin(r) * 1j def get_circles_cross_points(c1, c2): centre_distance = abs(c1.centre - c2.centre) a = acos((pow(c1.radius, 2) + pow(centre_distance, 2) - pow(c2.radius, 2)) / (2 * c1.radius * centre_distance)) t = arg(c2.centre - c1.centre) ans = [c1.centre + polar(c1.radius, t + a), c1.centre + polar(c1.radius, t - a)] ans.sort(key=attrgetter('real', 'imag')) return ans def solve(_circle_info): for i, circle in enumerate(_circle_info): cx, cy, r = map(int, circle) circles[i].centre = cx + cy * 1j circles[i].radius = r cp1, cp2 = get_circles_cross_points(*circles) print('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag)) return None if __name__ == '__main__': _input = sys.stdin.readlines() circle_info = map(lambda x: x.split(), _input) circles = [Circle() for _ in range(2)] solve(circle_info) ```
output
1
30,936
23
61,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` import sys from operator import itemgetter, attrgetter from itertools import starmap import cmath from math import isinf, sqrt, acos, atan2 readline = sys.stdin.readline EPS = 1e-9 ONLINE_FRONT = -2 CLOCKWISE = -1 ON_SEGMENT = 0 COUNTER_CLOCKWISE = 1 ONLINE_BACK = 2 class Circle(object): __slots__ = ('c', 'r') def __init__(self, c, r): self.c = c self.r = r class Segment(object): __slots__ = ('fi', 'se') def __init__(self, fi, se): self.fi = fi self.se = se Line = Segment def cross(a, b): return a.real * b.imag - a.imag * b.real def dot(a, b): return a.real * b.real + a.imag * b.imag def norm(base): return abs(base) ** 2 def project(s, p2): base = s.fi - s.se r = dot(p2 - s.fi, base) / norm(base) return s.fi + base * r def reflect(s, p): return p + (project(s, p) - p) * 2.0 def ccw(p1, p2, p3): a = p2 - p1 b = p3 - p1 if cross(a, b) > EPS: return 1 if cross(a, b) < -EPS: return -1 if dot(a, b) < -EPS: return 2 if norm(a) < norm(b): return -2 return 0 def intersect4(p1, p2, p3, p4): return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0) def intersect2(s1, s2): return intersect4(s1.fi, s1.se, s2.fi, s2.se) def getDistance(a, b): return abs(a - b) def getDistanceLP(l, p): return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi)) def getDistanceSP(s, p): if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi) if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se) return getDistanceLP(s, p) def getDistances(s1, s2): if intersect2(s1, s2): return 0.0 return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se), getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se)) def getCrossPoint(s1, s2): base = s2.se - s2.fi d1 = abs(cross(base, s1.fi - s2.fi)) d2 = abs(cross(base, s1.se - s2.fi)) t = d1 / (d1 + d2) return s1.fi + (s1.se - s1.fi) * t def getCrossPoints(c, l): pr = project(l, c.c) e = (l.se - l.fi) / abs(l.se - l.fi) base = sqrt(c.r * c.r - norm(pr - c.c)) return Segment(pr + e * base, pr - e * base) def getCrossPointsCL(c, l): pr = project(l, c.c) e = (l.se - l.fi) / abs(l.se - l.fi) base = sqrt(c.r * c.r - norm(pr - c.c)) return Segment(pr + e * base, pr - e * base) def getCrossPointsCC(c1, c2): d = abs(c1.c - c2.c) a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2.0 * c1.r * d)) t = cmath.phase(c2.c - c1.c) return Segment(c1.c + cmath.rect(c1.r, t + a), c1.c + cmath.rect(c1.r, t - a)) x, y, r = map(int, readline().split()) c1 = Circle(complex(x, y), r) x, y, r = map(int, readline().split()) c2 = Circle(complex(x, y), r) cpc = getCrossPointsCC(c1, c2) if cpc.se.real < cpc.fi.real or (cpc.se.real == cpc.fi.real and cpc.se.imag < cpc.fi.imag): cpc.fi, cpc.se = cpc.se, cpc.fi print(*map('{:.10f}'.format, (cpc.fi.real, cpc.fi.imag, cpc.se.real, cpc.se.imag))) ```
instruction
0
30,937
23
61,874
Yes
output
1
30,937
23
61,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` x1,y1,r1 = map(float,input().split()) x2,y2,r2 = map(float,input().split()) a,b = x2-x1,y2-y1 d = (a**2+b**2+r1**2-r2**2)/2 x = (d*a+b*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2) y = (d*b-a*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2) z = (d*a-b*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2) w = (d*b+a*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2) if x < z: print(x1+x,y1+y,end=' ') print(x1+z,y1+w) elif x > z: print(x1+z,y1+w,end=' ') print(x1+x,y1+y) elif y < w: print(x1+x,y1+y,end=' ') print(x1+z,y1+w) else: print(x1+z,y1+w,end=' ') print(x1+x,y1+y) ```
instruction
0
30,938
23
61,876
Yes
output
1
30,938
23
61,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` c1x, c1y, c1r = map(int, input().split()) c2x, c2y, c2r = map(int, input().split()) dx, dy = c2x - c1x, c2y - c1y s2 = dx ** 2 + dy ** 2 a = (s2 + c1r ** 2 - c2r ** 2) / 2 df = (s2 * c1r ** 2 - a ** 2) ** 0.5 ix1, ix2 = (a * dx + dy * df) / s2, (a * dx - dy * df) / s2 iy1, iy2 = (a * dy - dx * df) / s2, (a * dy + dx * df) / s2 if (ix1, iy1) > (ix2, iy2): ix1, ix2 = ix2, ix1 iy1, iy2 = iy2, iy1 print(ix1 + c1x, iy1 + c1y, ix2 + c1x, iy2 + c1y) ```
instruction
0
30,939
23
61,878
Yes
output
1
30,939
23
61,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` import math EPS = 1e-10 def equals(a, b): return abs(a - b) < EPS class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def __add__(self, p): return Point(self.x + p.x, self.y + p.y) def __sub__(self, p): return Point(self.x - p.x, self.y - p.y) def __mul__(self, a): return Point(self.x * a, self.y * a) def __rmul__(self, a): return self * a def __truediv__(self, a): return Point(self.x / a, self.y / a) def norm(self): return self.x * self.x + self.y * self.y def abs(self): return math.sqrt(self.norm()) def __lt__(self, p): if self.x != p.x: return self. x < p.x else: return self.y < p.y def __eq__(self, p): return equals(self.x, p.x) and equals(self.y, p.y) class Segment: def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 class Circle: def __init__(self, c=Point(), r=0): self.c = c self.r = r def dot(a, b): return a.x * b.x + a.y * b.y def cross(a, b): return a.x * b.y - a.y * b.x def arg(p): return math.atan2(p.y, p.x) def polar(r, a): return Point(math.cos(a) * r, math.sin(a) * r) def getCrossPoints(c1, c2): d = (c1.c - c2.c).abs() a = math.acos((c1.r*c1.r + d*d - c2.r*c2.r) / (2 * c1.r * d)) t = arg(c2.c - c1.c) return (c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)) if __name__ == '__main__': c1x, c1y, c1r = [int(v) for v in input().split()] c2x, c2y, c2r = [int(v) for v in input().split()] c1 = Circle(Point(c1x, c1y), c1r) c2 = Circle(Point(c2x, c2y), c2r) v1, v2 = getCrossPoints(c1, c2) if v2 < v1: v1, v2 = v2, v1 ans = [v1.x, v1.y, v2.x, v2.y] print('{0[0]:.8f} {0[1]:.8f} {0[2]:.8f} {0[3]:.8f}'.format(ans)) ```
instruction
0
30,940
23
61,880
Yes
output
1
30,940
23
61,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` from sys import stdin from math import sqrt from operator import attrgetter readline = stdin.readline def normal(a): return complex(a.imag, a.real) def unit(a): return a / abs(a) # http://atmsp.aisantec.com/atmspark/images/b-plus/pwqa/info/kousiki/enen.htm def main(): ax, ay, ar = map(int, readline().split()) bx, by, br = map(int, readline().split()) a, b = complex(ax, ay), complex(bx, by) ab = abs(b - a) ac = (ar ** 2 + ab ** 2 - br ** 2) / (2 * ab) c = a + (b - a) * (ac / ab) pc = sqrt(ar ** 2 - ac ** 2) normal_unit = unit(normal(b - a)) p, q = c + pc * normal_unit, c - pc * normal_unit p, q = sorted([p, q], key=attrgetter('real', 'imag')) print('{:.10f} {:.10f} {:.10f} {:.10f}'.format(p.real, p.imag, q.real, q.imag)) main() ```
instruction
0
30,941
23
61,882
No
output
1
30,941
23
61,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` import math class Vector: def __init__(self, x=None, y=None): self.x = x self.y = y def __add__(self, other): return Vector(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector(self.x - other.x, self.y - other.y) def __mul__(self, k): return Vector(self.x * k, self.y * k) def __truediv__(self, k): return Vector(self.x / k, self.y / k) def __gt__(self, other): return self.x > other.x and self.y > other.yb def __lt__(self, other): return self.x < other.x and self.y < other.yb def __eq__(self, other): return self.x == other.x and self.y == other.y def dot(self, other): return self.x * other.x + self.y * other.y # usually cross operation return Vector but it returns scalor def cross(self, other): return self.x * other.y - self.y * other.x def norm(self): return self.x * self.x + self.y * self.y def abs(self): return math.sqrt(self.norm()) def rotate(self, theta): return Vector(self.x * math.cos(theta) - self.y * math.sin(theta), self.x * math.sin(theta) + self.y * math.cos(theta)) class Point(Vector): def __init__(self, *args, **kargs): return super().__init__(*args, **kargs) class Segment: def __init__(self, p1=Point(0, 0), p2=Point(1, 1)): self.p1 = p1 self.p2 = p2 class Line(Segment): def __init__(self, *args, **kargs): return super().__init__(*args, **kargs) class Circle: def __init__(self, c=Point(0, 0), r=1): self.c = c self.r = r def get_cross_point(c1, c2): v = c2.c - c1.c d = v.abs() assert d <= (c1.r + c2.r) a = math.acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)) return v.rotate(a) * (c1.r/d), v.rotate(-a) * (c1.r/d) x1, y1, r1 = [ int(i) for i in input().split() ] c1 = Circle(Point(x1, y1), r1) x2, y2, r2 = [ int(i) for i in input().split() ] c2= Circle(Point(x2, y2), r2) p1, p2 = get_cross_point(c1, c2) x1, y1 = min((p1.x, p1.y), (p2.x, p2.y)) x2, y2 = max((p1.x, p1.y), (p2.x, p2.y)) print("{0:0.8f} {1:0.8f} {2:0.8f} {3:0.8f}".format(x1, y1, x2, y2)) ```
instruction
0
30,942
23
61,884
No
output
1
30,942
23
61,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` from sys import stdin from math import sqrt from operator import attrgetter readline = stdin.readline def herons_formula(a, b, c): s = (a + b + c) * 0.5 return sqrt(s * (s - a) * (s - b) * (s - c)) def unit(a): return a / abs(a) def main(): c1x, c1y, c1r = map(int, readline().split()) c2x, c2y, c2r = map(int, readline().split()) c1, c2 = complex(c1x, c1y), complex(c2x, c2y) base = abs(c1 - c2) s = herons_formula(c1r, c2r, base) h = 2 * s / base v1 = sqrt(c1r ** 2 - h ** 2) v2 = sqrt(c2r ** 2 - h ** 2) unit_c1_c2 = unit(c2 - c1) m = c1 + (c2 - c1) * v1 / (v1 + v2) normal_unit = complex(unit_c1_c2.imag, unit_c1_c2.real) intersection = [m + h * normal_unit, m - h * normal_unit] intersection.sort(key=attrgetter('real', 'imag')) pre, post = intersection print(pre.real, pre.imag, post.real, post.imag) main() ```
instruction
0
30,943
23
61,886
No
output
1
30,943
23
61,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. Constraints * The given circle have at least one cross point and have different center coordinates. * $-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$ * $1 \leq c1r, c2r \leq 10,000$ Input The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. Output Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Examples Input 0 0 2 2 0 2 Output 1.00000000 -1.73205080 1.00000000 1.73205080 Input 0 0 2 0 3 1 Output 0.00000000 2.00000000 0.00000000 2.00000000 Submitted Solution: ``` from sys import stdin from math import sqrt from operator import attrgetter readline = stdin.readline def herons_formula(a, b, c): s = (a + b + c) * 0.5 return sqrt(s * (s - a) * (s - b) * (s - c)) def unit(a): return a / abs(a) def main(): c1x, c1y, c1r = map(int, readline().split()) c2x, c2y, c2r = map(int, readline().split()) c1, c2 = complex(c1x, c1y), complex(c2x, c2y) base = abs(c1 - c2) s = herons_formula(c1r, c2r, base) h = 2 * s / base v1 = sqrt(c1r ** 2 - h ** 2) v2 = sqrt(c2r ** 2 - h ** 2) m = c1 + (c2 - c1) * v1 / base * (1 if v2 < base else -1) intersection = [m + h * unit(c2 - c1) * 1j, m + h * unit(c2 - c1) * -1j] intersection.sort(key=attrgetter('real', 'imag')) pre, post = intersection print('{:.7f} {:.7f} {:.7f} {:.7f}'.format(pre.real, pre.imag, post.real, post.imag)) main() ```
instruction
0
30,944
23
61,888
No
output
1
30,944
23
61,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) flag = [0, 0] for i in a: flag[i%2] = 1 if sum(flag) == 2: print('NO') continue print("YES") ```
instruction
0
31,127
23
62,254
Yes
output
1
31,127
23
62,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b, f = a[0] & 1, True for i in range(1, n): if (a[i]&1) != b: f = False break print("YES" if f else "NO") ```
instruction
0
31,128
23
62,256
Yes
output
1
31,128
23
62,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` print("\n".join([["NO","YES"][[0,int(input())].count(sum([int(x)%2 for x in input().split()]))] for c in range(int(input()))])) ```
instruction
0
31,129
23
62,258
Yes
output
1
31,129
23
62,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` import sys input = sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) tests = inp() testcount = 0 while testcount < tests: columns = inp() tetris = inlt() arr = [] i = 1 while i < columns: arr.append((tetris[i]-tetris[i-1])%2) i += 1 if len(arr) == 0: print('YES') elif max(arr) == 1: print('NO') else: print('YES') testcount += 1 ```
instruction
0
31,130
23
62,260
Yes
output
1
31,130
23
62,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` import sys try: sys.stdin = open(sys.path[0] + '\\input.txt', 'r') sys.stdout = open(sys.path[0] + '\\output.txt', 'w') except Exception as e: pass for tc in range(int(input())): n = int(input()) arr = list(map(int, input().split())) mini, maxi = min(arr), max(arr) diff = (maxi - mini) % 2 if diff == 0: print('YES') else: print('NO') ```
instruction
0
31,131
23
62,262
No
output
1
31,131
23
62,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) a = sorted(list(set(map(int, input().split()))), reverse=True) if len(a) > 1: if (a[0] - a[1]) % 2 == 0: print('YES') else: print('NO') else: print('YES') ```
instruction
0
31,132
23
62,264
No
output
1
31,132
23
62,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` t= int(input()) for i in range(t): n = int(input()) k = list(map(int,input().split())) if n==1: print("YES") else: l = [False if i%2==0 else True for i in k] if all(l): print("YES") else: p = [True for i in k if i%2==0] if all(p): print("YES") else: print("NO") ```
instruction
0
31,133
23
62,266
No
output
1
31,133
23
62,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Your task is to say if you can clear the whole field by placing such figures. More formally, the problem can be described like this: The following process occurs while at least one a_i is greater than 0: 1. You place one figure 2 × 1 (choose some i from 1 to n and replace a_i with a_i + 2); 2. then, while all a_i are greater than zero, replace each a_i with a_i - 1. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2t lines describe test cases. The first line of the test case contains one integer n (1 ≤ n ≤ 100) — the number of columns in the Tetris field. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial height of the i-th column of the Tetris field. Output For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise. Example Input 4 3 1 1 3 4 1 1 2 1 2 11 11 1 100 Output YES NO YES YES Note The first test case of the example field is shown below: <image> Gray lines are bounds of the Tetris field. Note that the field has no upper bound. One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0, 0, 0]. And the second test case of the example field is shown below: <image> It can be shown that you cannot do anything to end the process. In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0, 0]. In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process. Submitted Solution: ``` import sys # infilename = 'input.txt' # sys.stdin = open(infilename, 'r') # outfilename = 'output.txt' # sys.stdout = open(outfilename, 'w') def main(): import functools n = int(input()) for _ in range(n): input() r = map(int, input().split()) print('YES\n') if functools.reduce(lambda a, b: a + b, r) else print('NO\n') if __name__ == '__main__': main() ```
instruction
0
31,134
23
62,268
No
output
1
31,134
23
62,269
Provide a correct Python 3 solution for this coding contest problem. A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck. Your task is to write a program that reports how many possible ways to spread tatami mats of the same size on a floor of given height and width. Input The input consists of multiple datasets. Each dataset cosists of a line which contains two integers H and W in this order, separated with a single space. H and W are the height and the width of the floor respectively. The length of the shorter edge of a tatami mat is regarded as a unit length. You may assume 0 < H, W ≤ 20. The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the number of possible ways to spread tatami mats in one line. Example Input 3 4 4 4 0 0 Output 4 2
instruction
0
31,743
23
63,486
"Correct Solution: ``` def solve(): H, W = map(int, input().split()) if H == 0: return False if H*W % 2 == 1: print(0) return True state = [[-1]*W for i in range(H)] def dfs(k): if k == H*W: return 1 i, j = divmod(k, W) if state[i][j] != -1: return dfs(k+1) if i > 0 and j > 0 and state[i-1][j-1] != state[i-1][j] != state[i][j-1] != state[i-1][j-1]: return 0 r = 0 state[i][j] = k if i+1 < H: state[i+1][j] = k r += dfs(k+1) state[i+1][j] = -1 if j+1 < W and state[i][j+1] == -1: state[i][j+1] = k r += dfs(k+1) state[i][j+1] = -1 state[i][j] = -1 return r print(dfs(0)) return True while solve(): ... ```
output
1
31,743
23
63,487
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,814
23
63,628
Tags: brute force, strings Correct Solution: ``` from collections import defaultdict import sys n, m = [int(item) for item in sys.stdin.readline().strip().split()] s = [] for _ in range(m): s.append(sorted([int(item) for item in sys.stdin.readline().strip().split()])) rights = defaultdict(set) for l, r in s: rights[l].add(r) rights[r].add(l) divs = set() for i in range(1, n): if n % i == 0: divs.add(i) def solve(): for v in divs: ok = True for l, r in s: ok &= ((r + v - 1) % n + 1 in rights[(l + v - 1) % n + 1]) if ok: return True return False print("Yes" if solve() else "No") ```
output
1
31,814
23
63,629
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,815
23
63,630
Tags: brute force, strings Correct Solution: ``` n, m = map(int, input().split()) a = set() for i in range(m): c, d = map(int, input().split()) c %= n d %= n a.add((min(c, d), max(c, d))) def comprobar(x): global a, n b = set() for c, d in a: c += x d += x c %= n d %= n if (min(c, d), max(c, d)) not in a: return False #print("COMPARACION", x) #print(a) #print(b) return True for i in range(1, n): if n%i == 0: if comprobar(i): print("Yes") exit() print("No") ```
output
1
31,815
23
63,631
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,816
23
63,632
Tags: brute force, strings Correct Solution: ``` from collections import defaultdict import sys n, m = [int(item) for item in sys.stdin.readline().strip().split()] s = [] for line in sys.stdin.readlines(): s.append([int(item) for item in line.strip().split()]) divs = [] for i in range(1, n): if n % i == 0: divs.append(i) def gcd(a, b): while b: a, b = b, a % b return a def isSubArray(A, B): n, m = len(A), len(B) i = 0 j = 0 while (i < n and j < m): if (A[i] == B[j]): i += 1 j += 1 if (j == m): return True else: i += 1 j = 0 return False def check(a, v): new = [(x + v - 1) % n + 1 for x in a] # print(new, a) return sorted(new) == sorted(a) def get_value(a): if len(a) == 1: return -1 p = len(a) for v in divs: if check(a, v): return v return -1 def solve(): if n == 2: return True d = defaultdict(list) for l, r in s: d[min(abs(l - r), n - abs(l - r))].extend([l, r]) # for x in d: # d[x].sort() # print(dict(d)) verdict = True values = [] for x in d: values.append(get_value(d[x])) if -1 in values: return False v = values[0] for x in values[1:]: v = v * x // gcd(v, x) if v < n: return True return False # print(get_value([1, 2, 4, 5, 7, 8, 10, 11])) sys.stdout.write("Yes" if solve() else "No") ```
output
1
31,816
23
63,633
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,817
23
63,634
Tags: brute force, strings Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) 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") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=-10**6, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(50001)] pp=[] def SieveOfEratosthenes(n=50000): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * p, n+1, p): prime[i] = False p += 1 for i in range(50001): if prime[i]: pp.append(i) #---------------------------------running code------------------------------------------ n,m=map(int,input().split()) a=[] for i in range (m): x,y=map(int,input().split()) x,y=x-1,y-1 a.append((min(x,y),max(x,y))) div=[1] for i in range (2,1+int(math.sqrt(n))): if n%i==0: div.append(i) if i*i!=n: div.append(n//i) div.sort() ch=0 s=set(a) for k in div: c=1 for i in range (m): x=(a[i][0]+k)%n y=(a[i][1]+k)%n if (min(x,y),max(x,y)) not in s: c=0 break #print(sorted(temp)) if c: ch=1 break if ch: print("Yes") else: print("No") ```
output
1
31,817
23
63,635
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,818
23
63,636
Tags: brute force, strings Correct Solution: ``` def gcd(x,y): while y: x,y = y,x%y return x def lcm(a,b): return (a*b)//gcd(a,b) import io,os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline kk=lambda:map(int,input().split()) k2=lambda:map(lambda x:int(x)-1, input().split()) ll=lambda:list(kk()) n,m=kk() nodes = [[] for _ in range(n)] for _ in range(m): n1,n2=k2() nodes[n1].append((n2-n1)%n) nodes[n2].append((n1-n2)%n) seen = {} nextv=0 lists = [] node2,used = [0]*n, [False]*n for i,no in enumerate(nodes): t = tuple(sorted(no)) if not t in seen: seen[t],nextv = nextv,nextv+1 lists.append([]) lists[seen[t]].append(i) node2[i] = seen[t] lists.sort(key=len) valids = set() for i in range(nextv-1): cl = lists[i] n0 = cl[0] continueing = True while continueing: continueing = False for j in range(1,len(cl)): if used[cl[j]]: continue dist = cl[j]-n0 if n%dist != 0: continue for k in range(n0, n+n0, dist): k = k%n if used[k] or node2[k] != node2[n0]: break else: # we found a working one. valids.add(dist) for k in range(n0, n+n0, dist): k = k%n used[k]=True cl = [x for x in cl if (x-n0)%dist != 0] n0 = cl[0] if cl else 0 continueing= True break if len(cl) > 0: print("NO") exit() lc =1 for value in valids: lc = lcm(lc, value) print("YES" if lc< n else "NO") ```
output
1
31,818
23
63,637
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,819
23
63,638
Tags: brute force, strings Correct Solution: ``` """ Satwik_Tiwari ;) . 30th july , 2020 - Thursday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import * from copy import * from collections import deque from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl #If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect #If the element is already present in the list, # the right most position where element has to be inserted is returned #============================================================================================== #fast I/O region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts mod = 1000000007 def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) # def graph(vertex): return [[] for i in range(0,vertex+1)] def zerolist(n): return [0]*n def nextline(): out("\n") #as stdout.write always print sring. def testcase(t): for p in range(t): solve() def printlist(a) : for p in range(0,len(a)): out(str(a[p]) + ' ') def lcm(a,b): return (a*b)//gcd(a,b) def power(a,b): ans = 1 while(b>0): if(b%2==1): ans*=a a*=a b//=2 return ans def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True #=============================================================================================== # code here ;)) def solve(): n,m = sep() div =[] for i in range(1,floor(n**(0.5))+1): if(n%i==0): div.append(i) if((n//i)!=n and (n//i)!=i): div.append(n//i) graph = set() for i in range(m): a,b=sep() a-=1 b-=1 a,b = min(a,b),max(a,b) graph.add((a,b)) for i in range(len(div)): f = True for j in graph: a,b = (j[0]+div[i])%n , (j[1]+div[i])%n a,b = min(a,b),max(a,b) if((a,b) not in graph): f = False break if(f): print('Yes') return print('No') testcase(1) # testcase(int(inp())) ```
output
1
31,819
23
63,639
Provide tags and a correct Python 3 solution for this coding contest problem. Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
instruction
0
31,820
23
63,640
Tags: brute force, strings Correct Solution: ``` #!/usr/bin/env python """<https://github.com/cheran-senthil/PyRival>""" from __future__ import division, print_function import os import sys from collections import Counter from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip else: _str = str str = lambda x=b"": x if type(x) is bytes else _str(x).encode() def gcd(x, y): """greatest common divisor of x and y""" while y: x, y = y, x % y return x mod_add = lambda x, y, m: x + y if x + y < m else x + y - m def memodict(f): """memoization decorator for a function taking a single argument""" class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ def pollard_rho(n): """returns a random factor of n""" if n & 1 == 0: return 2 if n % 3 == 0: return 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): prev = p p = (p * p) % n if p == 1: return gcd(prev - 1, n) if p == n - 1: break else: for i in range(2, n): x, y = i, (i * i + 1) % n f = gcd(abs(x - y), n) while f == 1: x, y = (x * x + 1) % n, (y * y + 1) % n y = (y * y + 1) % n f = gcd(abs(x - y), n) if f != n: return f return n @memodict def prime_factors(n): """returns a Counter of the prime factorization of n""" if n <= 1: return Counter() f = pollard_rho(n) return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f) def main(): n, m = map(int, input().split()) p = [(0, 0)] * m for i in range(m): x, y = map(int, input().split()) p[i] = (min(x - 1, y - 1), max(x - 1, y - 1)) p.sort() for factor in prime_factors(n): factor = n // factor fp = [(0, 0)] * m for i in range(m): x, y = p[i] x, y = mod_add(x, factor, n), mod_add(y, factor, n) fp[i] = (min(x, y), max(x, y)) fp.sort() if p == fp: print('Yes') return print('No') return # region template BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._buffer = BytesIO() self._fd = file.fileno() 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): if self._buffer.tell(): return self._buffer.read() return os.read(self._fd, os.fstat(self._fd).st_size) 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 ostream: def __lshift__(self, a): if a is endl: sys.stdout.write(b"\n") sys.stdout.flush() else: sys.stdout.write(str(a)) return self def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", b"\n")) if kwargs.pop("flush", False): file.flush() sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) cout, endl = ostream(), object() readline = sys.stdin.readline readlist = lambda var=int: [var(n) for n in readline().split()] input = lambda: readline().rstrip(b"\r\n") # endregion if __name__ == "__main__": main() ```
output
1
31,820
23
63,641