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 an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. Constraints * 1 \leq H,W \leq 50 * S_i is a string of length W consisting of `#` and `.`. Input Input is given from Standard Input in the following format: H W S_1 : S_H Output Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). Examples Input 3 5 ..... .#.#. ..... Output 11211 1#2#1 11211 Input 3 5 Output Input 6 6 . .#.## .# .#..#. .##.. .#... Output 3 8#7## 5# 4#65#2 5##21 4#310 Submitted Solution: ``` g,r=map(int,input().split()) A=["."*(r+2)] for i in range(g): w="."+input()+"." A.append(w) A.append("."*(r+2)) print(A) for i in range(1,g+1): for j in range(1,r+1): if A[i][j]==".": B=[] for m in [i-1,i,i+1]: for k in [j-1,j,j+1]: B.append(A[m][k]) print(B) print(B.count("#")) A[i]=A[i][1:r+1:].replace(".",str(B.count("#")),1) A[i]="."+A[i]+"." for i in range(1,g+1): print(A[i][1:r+1:]) ```
instruction
0
58,748
23
117,496
No
output
1
58,748
23
117,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. Constraints * 1 \leq H,W \leq 50 * S_i is a string of length W consisting of `#` and `.`. Input Input is given from Standard Input in the following format: H W S_1 : S_H Output Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). Examples Input 3 5 ..... .#.#. ..... Output 11211 1#2#1 11211 Input 3 5 Output Input 6 6 . .#.## .# .#..#. .##.. .#... Output 3 8#7## 5# 4#65#2 5##21 4#310 Submitted Solution: ``` h, w = map(int, input().split()) matrix = [[x for x in input()] for y in range(h)] def check_surround(matrix, x, y): if matrix[x][y] == '#': return '#' else: tmp = [] tmp += check_index(matrix, x-1, y-1) tmp += check_index(matrix, x, y-1) tmp += check_index(matrix, x+1, y-1) tmp += check_index(matrix, x-1, y) tmp += check_index(matrix, x, y) tmp += check_index(matrix, x+1, y) tmp += check_index(matrix, x-1, y+1) tmp += check_index(matrix, x, y+1) tmp += check_index(matrix, x+1, y+1) return str(str(tmp).count('#')) def check_index(matrix, x, y): try: return matrix[x][y] except: return str(0) for ri in range(h): s = '' for ni in range(w): s += check_surround(matrix, ri, ni) print(s) ```
instruction
0
58,749
23
117,498
No
output
1
58,749
23
117,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. Constraints * 1 \leq H,W \leq 50 * S_i is a string of length W consisting of `#` and `.`. Input Input is given from Standard Input in the following format: H W S_1 : S_H Output Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). Examples Input 3 5 ..... .#.#. ..... Output 11211 1#2#1 11211 Input 3 5 Output Input 6 6 . .#.## .# .#..#. .##.. .#... Output 3 8#7## 5# 4#65#2 5##21 4#310 Submitted Solution: ``` H, W = map(int, input().split(' ')) print("{} {}".format(H, W)) count = [['0']*W for i in range(H)] def update_count(i, j, count): count[i][j] = '#' start_i = 0 if i-1 < 0 else i-1 end_i = H if i + 2 > H else i+2 start_j = 0 if j-1 < 0 else j-1 end_j = W if j + 2 > W else j+2 for k in range(start_i, end_i): for l in range(start_j, end_j): if count[k][l] != '#': count[k][l] = str(1 + int(count[k][l])) return count for i in range(H): S = input() for j in range(W): if S[j] == '#': count = update_count(i, j, count) for i in range(H): print(''.join(count[i])) ```
instruction
0
58,750
23
117,500
No
output
1
58,750
23
117,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis holds a Geometers Anonymous Club meeting in SIS. He has prepared n convex polygons numbered from 1 to n for the club. He plans to offer members of the club to calculate Minkowski sums of these polygons. More precisely, he plans to give q tasks, the i-th of them asks to calculate the sum of Minkowski of polygons with indices from l_i to r_i inclusive. The sum of Minkowski of two sets A and B is the set C = \\{a + b : a ∈ A, b ∈ B\}. It can be proven that if A and B are convex polygons then C will also be a convex polygon. <image> Sum of two convex polygons To calculate the sum of Minkowski of p polygons (p > 2), you need to calculate the sum of Minkowski of the first p - 1 polygons, and then calculate the sum of Minkowski of the resulting polygon and the p-th polygon. For the convenience of checking answers, Denis has decided to prepare and calculate the number of vertices in the sum of Minkowski for each task he prepared. Help him to do it. Input The first line of the input contains one integer n — the number of convex polygons Denis prepared (1 ≤ n ≤ 100 000). Then n convex polygons follow. The description of the i-th polygon starts with one integer k_i — the number of vertices in the i-th polygon (3 ≤ k_i). The next k_i lines contain two integers x_{ij}, y_{ij} each — coordinates of vertices of the i-th polygon in counterclockwise order (|x_{ij}|, |y_{ij}| ≤ 10 ^ 9). It is guaranteed, that there are no three consecutive vertices lying on the same line. The total number of vertices over all polygons does not exceed 300 000. The following line contains one integer q — the number of tasks (1 ≤ q ≤ 100 000). The next q lines contain descriptions of tasks. Description of the i-th task contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n). Output For each task print a single integer — the number of vertices in the sum of Minkowski of polygons with indices from l_i to r_i. Example Input 3 3 0 0 1 0 0 1 4 1 1 1 2 0 2 0 1 3 2 2 1 2 2 1 3 1 2 2 3 1 3 Output 5 5 6 Note Description of the example: <image> First, second and third polygons from the example <image> Minkowski sums of the first and second, the second and third and all polygons correspondingly Submitted Solution: ``` print("HelloWorld") ```
instruction
0
58,912
23
117,824
No
output
1
58,912
23
117,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis holds a Geometers Anonymous Club meeting in SIS. He has prepared n convex polygons numbered from 1 to n for the club. He plans to offer members of the club to calculate Minkowski sums of these polygons. More precisely, he plans to give q tasks, the i-th of them asks to calculate the sum of Minkowski of polygons with indices from l_i to r_i inclusive. The sum of Minkowski of two sets A and B is the set C = \\{a + b : a ∈ A, b ∈ B\}. It can be proven that if A and B are convex polygons then C will also be a convex polygon. <image> Sum of two convex polygons To calculate the sum of Minkowski of p polygons (p > 2), you need to calculate the sum of Minkowski of the first p - 1 polygons, and then calculate the sum of Minkowski of the resulting polygon and the p-th polygon. For the convenience of checking answers, Denis has decided to prepare and calculate the number of vertices in the sum of Minkowski for each task he prepared. Help him to do it. Input The first line of the input contains one integer n — the number of convex polygons Denis prepared (1 ≤ n ≤ 100 000). Then n convex polygons follow. The description of the i-th polygon starts with one integer k_i — the number of vertices in the i-th polygon (3 ≤ k_i). The next k_i lines contain two integers x_{ij}, y_{ij} each — coordinates of vertices of the i-th polygon in counterclockwise order (|x_{ij}|, |y_{ij}| ≤ 10 ^ 9). It is guaranteed, that there are no three consecutive vertices lying on the same line. The total number of vertices over all polygons does not exceed 300 000. The following line contains one integer q — the number of tasks (1 ≤ q ≤ 100 000). The next q lines contain descriptions of tasks. Description of the i-th task contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n). Output For each task print a single integer — the number of vertices in the sum of Minkowski of polygons with indices from l_i to r_i. Example Input 3 3 0 0 1 0 0 1 4 1 1 1 2 0 2 0 1 3 2 2 1 2 2 1 3 1 2 2 3 1 3 Output 5 5 6 Note Description of the example: <image> First, second and third polygons from the example <image> Minkowski sums of the first and second, the second and third and all polygons correspondingly Submitted Solution: ``` import sys import math n = int(sys.stdin.readline().strip()) L = [] K = [0] * n for i in range (0, n): k = int(sys.stdin.readline().strip()) K[i] = k x = [0] * k y = [0] * k for j in range (0, k): x[j], y[j] = list(map(int, sys.stdin.readline().strip().split())) for j in range (0, k-1): u = x[j] - x[j+1] v = y[j] - y[j+1] g = math.gcd(u,v) u, v = u // g, v // g L.append([u,v,i]) u = x[k-1] - x[0] v = y[k-1] - y[0] g = math.gcd(u,v) u, v = u // g, v // g L.append([u,v,i]) First = [0] * n Last = [0] * n CFirst = [0] * n CLast = [0] * n L.sort() for i in range (0, len(L)-1): if L[i][0] != L[i+1][0] or L[i][1] != L[i+1][1]: Last[L[i][2]] = Last[L[i][2]] + 1 Last[L[len(L)-1][2]] = Last[L[len(L)-1][2]] + 1 for i in range (1, len(L)): if L[i][0] != L[i-1][0] or L[i][1] != L[i-1][1]: First[L[i][2]] = First[L[i][2]] + 1 First[L[0][2]] = First[L[0][2]] + 1 CFirst[0] = First[0] CLast[0] = Last[0] for i in range (1, n): CFirst[i] = CFirst[i-1]+First[i] CLast[i] = CLast[i-1]+Last[i] q = int(sys.stdin.readline().strip()) for i in range (0, q): l, r = list(map(int, sys.stdin.readline().strip().split())) if l != 1: print(CFirst[r-1] - CLast[l-2]) else: print(CFirst[r-1]) ```
instruction
0
58,913
23
117,826
No
output
1
58,913
23
117,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer k and n distinct points with integer coordinates on the Euclidean plane, the i-th point has coordinates (x_i, y_i). Consider a list of all the (n(n - 1))/(2) pairs of points ((x_i, y_i), (x_j, y_j)) (1 ≤ i < j ≤ n). For every such pair, write out the distance from the line through these two points to the origin (0, 0). Your goal is to calculate the k-th smallest number among these distances. Input The first line contains two integers n, k (2 ≤ n ≤ 10^5, 1 ≤ k ≤ (n(n - 1))/(2)). The i-th of the next n lines contains two integers x_i and y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the i-th point. It is guaranteed that all given points are pairwise distinct. Output You should output one number — the k-th smallest distance from the origin. Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}. Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Example Input 4 3 2 1 -2 -1 0 -1 -2 4 Output 0.707106780737 Note There are 6 pairs of points: * Line 1-2 : distance 0 from the origin * Line 1-3 : distance \frac{√{2}}{2} ≈ 0.707106781 from the origin * Line 1-4 : distance 2 from the origin * Line 2-3 : distance 1 from the origin * Line 2-4 : distance 2 from the origin * Line 3-4 : distance \frac{2}{√{29}} ≈ 0.371390676 from the origin The third smallest distance among those is approximately 0.707106781. Submitted Solution: ``` print(0.707106780737) # lmao u really thought I would try F? ```
instruction
0
59,045
23
118,090
No
output
1
59,045
23
118,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer k and n distinct points with integer coordinates on the Euclidean plane, the i-th point has coordinates (x_i, y_i). Consider a list of all the (n(n - 1))/(2) pairs of points ((x_i, y_i), (x_j, y_j)) (1 ≤ i < j ≤ n). For every such pair, write out the distance from the line through these two points to the origin (0, 0). Your goal is to calculate the k-th smallest number among these distances. Input The first line contains two integers n, k (2 ≤ n ≤ 10^5, 1 ≤ k ≤ (n(n - 1))/(2)). The i-th of the next n lines contains two integers x_i and y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the i-th point. It is guaranteed that all given points are pairwise distinct. Output You should output one number — the k-th smallest distance from the origin. Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}. Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Example Input 4 3 2 1 -2 -1 0 -1 -2 4 Output 0.707106780737 Note There are 6 pairs of points: * Line 1-2 : distance 0 from the origin * Line 1-3 : distance \frac{√{2}}{2} ≈ 0.707106781 from the origin * Line 1-4 : distance 2 from the origin * Line 2-3 : distance 1 from the origin * Line 2-4 : distance 2 from the origin * Line 3-4 : distance \frac{2}{√{29}} ≈ 0.371390676 from the origin The third smallest distance among those is approximately 0.707106781. Submitted Solution: ``` n, k = map(int, input().split()) points = [list(map(int, input().split())) for i in range(n)] ldis = [] for i in range(len(points)): x0 = points[i] for j in range(i + 1, len(points)): x1 = points[j] if x1[1] - x0[1] == 0: dis = abs(x1[1]) elif x1[0] - x0[0] == 0: dis = abs(x1[0]) else: m = (x1[1] - x0[1]) / (x1[0] - x0[0]) b = x1[1] - m * x1[0] dis = abs(b / (1 + m ** 2) ** (1 / 2)) if len(ldis) < k: ldis.append(dis) ldis = sorted(ldis) elif len(ldis) == k and ldis[k - 1] > dis: ldis[k - 1] = dis print(ldis[k-1]) ```
instruction
0
59,046
23
118,092
No
output
1
59,046
23
118,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer k and n distinct points with integer coordinates on the Euclidean plane, the i-th point has coordinates (x_i, y_i). Consider a list of all the (n(n - 1))/(2) pairs of points ((x_i, y_i), (x_j, y_j)) (1 ≤ i < j ≤ n). For every such pair, write out the distance from the line through these two points to the origin (0, 0). Your goal is to calculate the k-th smallest number among these distances. Input The first line contains two integers n, k (2 ≤ n ≤ 10^5, 1 ≤ k ≤ (n(n - 1))/(2)). The i-th of the next n lines contains two integers x_i and y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the i-th point. It is guaranteed that all given points are pairwise distinct. Output You should output one number — the k-th smallest distance from the origin. Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}. Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Example Input 4 3 2 1 -2 -1 0 -1 -2 4 Output 0.707106780737 Note There are 6 pairs of points: * Line 1-2 : distance 0 from the origin * Line 1-3 : distance \frac{√{2}}{2} ≈ 0.707106781 from the origin * Line 1-4 : distance 2 from the origin * Line 2-3 : distance 1 from the origin * Line 2-4 : distance 2 from the origin * Line 3-4 : distance \frac{2}{√{29}} ≈ 0.371390676 from the origin The third smallest distance among those is approximately 0.707106781. Submitted Solution: ``` import math n, k = map(int, input().split()) points = [list(map(int, input().split())) for i in range(n)] distances = [] for i in range(len(points)): x0 = points[i] for j in range(i + 1, len(points)): x1 = points[j] if x1[1] - x0[1] == 0: distances.append(abs(x1[1])) elif x1[0] - x0[0] == 0: distances.append(abs(x1[0])) else: m = (x1[1] - x0[1]) / (x1[0] - x0[0]) b = x1[1] - m * x1[0] distances.append(abs(b / 2 / m) * math.sqrt(1 + m ** 2)) print(sorted(distances)[k-1]) ```
instruction
0
59,047
23
118,094
No
output
1
59,047
23
118,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer k and n distinct points with integer coordinates on the Euclidean plane, the i-th point has coordinates (x_i, y_i). Consider a list of all the (n(n - 1))/(2) pairs of points ((x_i, y_i), (x_j, y_j)) (1 ≤ i < j ≤ n). For every such pair, write out the distance from the line through these two points to the origin (0, 0). Your goal is to calculate the k-th smallest number among these distances. Input The first line contains two integers n, k (2 ≤ n ≤ 10^5, 1 ≤ k ≤ (n(n - 1))/(2)). The i-th of the next n lines contains two integers x_i and y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the i-th point. It is guaranteed that all given points are pairwise distinct. Output You should output one number — the k-th smallest distance from the origin. Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}. Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Example Input 4 3 2 1 -2 -1 0 -1 -2 4 Output 0.707106780737 Note There are 6 pairs of points: * Line 1-2 : distance 0 from the origin * Line 1-3 : distance \frac{√{2}}{2} ≈ 0.707106781 from the origin * Line 1-4 : distance 2 from the origin * Line 2-3 : distance 1 from the origin * Line 2-4 : distance 2 from the origin * Line 3-4 : distance \frac{2}{√{29}} ≈ 0.371390676 from the origin The third smallest distance among those is approximately 0.707106781. Submitted Solution: ``` n, k = map(int, input().split()) points = [list(map(int, input().split())) for i in range(n)] ldis = [] for i in range(len(points)): x0 = points[i] for j in range(i + 1, len(points)): x1 = points[j] if x1[1] - x0[1] == 0: dis = abs(x1[1]) elif x1[0] - x0[0] == 0: dis = abs(x1[0]) else: m = (x1[1] - x0[1]) / (x1[0] - x0[0]) b = x1[1] - m * x1[0] dis = abs(b / (1 + m ** 2) ** (1 / 2)) if len(ldis) < k: ldis.append(dis) elif len(ldis) == k and sorted(ldis)[-1] > dis: ldis[-1] = dis print(sorted(ldis)[-1]) ```
instruction
0
59,048
23
118,096
No
output
1
59,048
23
118,097
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,147
23
118,294
Tags: constructive algorithms, implementation Correct Solution: ``` n,m=map(int,input().split()) x=min(n,m)+1 print(x) for i in range(x): print(i,x-1-i) ```
output
1
59,147
23
118,295
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,148
23
118,296
Tags: constructive algorithms, implementation Correct Solution: ``` n,m=map(int,input().split()) x=[] y=[] cnt=0 for i in range(0,min(n,m)+1): cnt+=1 x.append(i) y.append(min(n,m)-i) print(cnt) for i in range(cnt): print(x[i],y[i]) ```
output
1
59,148
23
118,297
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,149
23
118,298
Tags: constructive algorithms, implementation Correct Solution: ``` import sys inf = float("inf") # sys.setrecursionlimit(10000000) # abc='abcdefghijklmnopqrstuvwxyz' # abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod, MOD = 1000000007, 998244353 # vow=['a','e','i','o','u'] # dx,dy=[-1,1,0,0],[0,0,1,-1] # from collections import deque, Counter, OrderedDict,defaultdict # from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace # from math import ceil,floor,log,sqrt,factorial # from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n,m = get_ints() y = min(n,m) x = 0 print(y+1) while y>=0: print(x,y) x+=1 y-=1 ```
output
1
59,149
23
118,299
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,150
23
118,300
Tags: constructive algorithms, implementation Correct Solution: ``` a,b = list(map(int,input().split())) k = min(a,b) print(k+1) for i in range(k+1): print(i,k-i) ```
output
1
59,150
23
118,301
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,151
23
118,302
Tags: constructive algorithms, implementation Correct Solution: ``` # import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') n, m = map(int,input().split()) k = min(n, m) + 1 print(k) for i in range(k): print(i, min(n, m)-i) ```
output
1
59,151
23
118,303
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,152
23
118,304
Tags: constructive algorithms, implementation Correct Solution: ``` l1 = list(map(int, input().split())) m = l1[0] n = l1[1] ans = min(m,n) + 1 print(ans) for i in range(ans): print(f'{i} {ans-i-1}') ```
output
1
59,152
23
118,305
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,153
23
118,306
Tags: constructive algorithms, implementation Correct Solution: ``` a,b=map(int,input().split()) m=min(a,b); print(m+1); for i in range(m+1): print(i,m-i) ```
output
1
59,153
23
118,307
Provide tags and a correct Python 3 solution for this coding contest problem. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
instruction
0
59,154
23
118,308
Tags: constructive algorithms, implementation Correct Solution: ``` n,m=map(int,input().split()) print(min(n,m)+1) x=min(n,m) j=m i=0 while j>=0 and i<=n: print(i,j) i+=1 j-=1 ```
output
1
59,154
23
118,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` n, m = map(int,input().split()) ans = (min(m+1,n+1)) print(ans) pt = [0,ans-1] for i in range(1,ans+1): prt = " ".join([str(v) for v in pt]) print(prt) pt[0]+=1 pt[1]-=1 ```
instruction
0
59,155
23
118,310
Yes
output
1
59,155
23
118,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` from math import sqrt n,m = map(int,input().split()) def dist(x1,y1,x2,y2): d = (x1-x2)**2 + (y2-y1)**2 if sqrt(d)!=int(sqrt(d)): return True else: return False z = min(n,m) print(z+1) ans = [] ba = [] if n !=m : for i in range(z+1): if i!=0: ans.append([i,i]) else: ans.append([z,0]) for i in range(n+1): for j in range(m+1): if i!=0 or j!=0: ba.append([i,j]) if m!=n: for i in ba: x,y = i flag = 0 for j in ans: a,b = j z = dist(x,y,a,b) if z == False: flag = 1 break if flag == 0 : ans.append(i) break else: for i in ba: x,y = i flag = 0 for j in ans: a,b = j z = dist(x,y,a,b) if z == False: flag = 1 break if flag == 0 : ans.append(i) # for i in range(min(n,m)+1): print(i,min(n,m)-i) ```
instruction
0
59,156
23
118,312
Yes
output
1
59,156
23
118,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` h=min([int(x) for x in input().split(' ')]) h+=1 v=[(x,h-x-1) for x in range(h)] print(h) for c in v: print(c[0],c[1]) ```
instruction
0
59,157
23
118,314
Yes
output
1
59,157
23
118,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` def points(x,y): blanck=[] mini=min(x,y) for i in range(0,mini+1): blanck.append([i,mini-i]) print(len(blanck)) for i in blanck: print(*i) return "" a,b=map(int,input().strip().split()) print(points(a,b)) ```
instruction
0
59,158
23
118,316
Yes
output
1
59,158
23
118,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush # from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction import copy import time # import numpy as np starttime = time.time() # import numpy as np mod = int(pow(10, 9) + 7) mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] try: # sys.setrecursionlimit(int(pow(10,6))) sys.stdin = open("input.txt", "r") # sys.stdout = open("../output.txt", "w") except: pass n,m=L() if n<m: print(n+1) print(0,1) for i in range(1,n): print(i,i+1) print(n,0) else: print(m+1) print(0,1) for i in range(1,m): print(i,i+1) print(m,0) endtime = time.time() # print(f"Runtime of the program is {endtime - starttime}") ```
instruction
0
59,159
23
118,318
No
output
1
59,159
23
118,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` n,m=map(int,input().split()) mn = min(n,m)+1 print(mn) for i in range(mn): print(i,i) ```
instruction
0
59,160
23
118,320
No
output
1
59,160
23
118,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` x,y=map(int,input().split()) if(x==y): print(x+1) for i in range(x): print(i+1,i) print(0,x) elif(x>y): print(y+1) for i in range(y+1): print(i+1,i) else: print(x+1) for i in range(x+1): print(i,i+1) ```
instruction
0
59,161
23
118,322
No
output
1
59,161
23
118,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points. Input The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Output In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Examples Input 2 2 Output 3 0 1 1 2 2 0 Input 4 3 Output 4 0 3 2 1 3 0 4 2 Note Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. Submitted Solution: ``` l = [int(i) for i in input().split()] n = l[0]; m = l[1] a = min(n,m) if a==1: print(1) print(a,a) else: print(a+1) for i in range(a+1): print(i,i) ```
instruction
0
59,162
23
118,324
No
output
1
59,162
23
118,325
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,690
23
119,380
"Correct Solution: ``` def isCLKWISE(ph): a = [-ph[-3][0]+ph[-1][0],ph[-1][1]-ph[-3][1]] b = [-ph[-3][0]+ph[-2][0],ph[-2][1]-ph[-3][1]] crs = b[1]*a[0] - a[1]*b[0] if crs < 0 : return False else : return True def ConvexHullScan(P): P = sorted(P) phU = [P[0],P[1]] for p in P[2:]: phU.append(p) while(True): if isCLKWISE(phU) : break else : del phU[-2] if len(phU) == 2 : break phL = [P[-1],P[-2]] for p in P[-3::-1]: phL.append(p) while(True): if isCLKWISE(phL) : break else : del phL[-2] if len(phL) == 2 : break ph = phU + phL[1:-1] return ph n = int(input()) P = [] for i in range(n): P.append([int(x) for x in input().split()]) Q = ConvexHullScan(P) Q.reverse() print(len(Q)) idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R: print(r[0],r[1]) ```
output
1
59,690
23
119,381
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,691
23
119,382
"Correct Solution: ``` from collections import deque from functools import singledispatch import math EPS = 1e-10 COUNTER_CLOCKWISE = 1 CLOCKWISE = -1 ONLINE_BACK = 2 ONLINE_FRONT = -2 ON_SEGMENT = 0 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 class Point(): def __init__(self, x, y): self.x = x self.y = y def __add__(self, point): # + 演算子での挙動を指定 return Point(self.x+point.x, self.y+point.y) def __sub__(self, point): # - 演算子での挙動を指定 return Point(self.x-point.x, self.y-point.y) def __mul__(self, a): # * 演算子での挙動を指定 return Point(a*self.x, a*self.y) def __truediv__(self, a): # / 演算子での挙動を指定 return Point(self.x/a, self.y/a) def __abs__(self): # abs関数での挙動を指定 return math.sqrt(self.norm()) def norm(self): return self.x**2+self.y**2 def __lt__(self, p): # < 演算子での挙動を指定、これによってsortで並び替えが可能になる。 # boolean = return (self.x < p.x) if (self.x != p.x) else (self.y < p.y) def __eq__(self, p): # == 演算子での挙動を指定 return abs(self.x-p.x) < EPS and abs(self.y-p.y) <EPS 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 isOrthogonal(a, b): return dot(a, b) == 0 def isParallel(a, b): return cross(a, b) == 0 def project(s, p): #s: Segment(), p: Point() base = s.p2 - s.p1 r = dot(p-s.p1, base)/base.norm() return s.p1+base*r def reflect(s, p): return p+(project(s, p)-p)*2 @singledispatch def get_distance(a, b): return abs(a-b) def get_distance_lp(l, p): return abs(cross(l.p2-l.p1, p-l.p1)/abs(l.p2-l.p1)) def get_distance_sp(s, p): if dot(s.p2-s.p1, p-s.p1) < 0: return abs(p-s.p1) if dot(s.p1-s.p2, p-s.p2) < 0: return abs(p-s.p2) return get_distance_lp(s, p) @get_distance.register(Segment) def _(s1, s2): if intersect(s1, s2): return 0 return min([get_distance_sp(s1, s2.p1), get_distance_sp(s1, s2.p2), get_distance_sp(s2, s1.p1), get_distance_sp(s2, s1.p2)]) def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if cross(a, b) > EPS: return COUNTER_CLOCKWISE if cross(a, b) < -EPS: return CLOCKWISE if dot(a, b) < -EPS: return ONLINE_BACK if a.norm() < b.norm(): return ONLINE_FRONT return ON_SEGMENT @singledispatch 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) @intersect.register(Segment) def _(s1, s2): return intersect(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): # 次の行のコメントのコードは、新しいintersect関数を作る必要があり(おそらくpython3.7以上必須)、手間取るので割愛します。 # assert(intersect(c, l)) pr = project(l, c.c) e = (l.p2 - l.p1)/abs(l.p2-l.p1) base = (c.r**2-(pr-c.c).norm())**0.5 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_(c1, c2): # 関数名かぶるので、_つけました。 # python3.7以上でsingledispatchを使えば同じ関数名も可能ですが、 # atcoderのpython3.4も想定しているため、関数名を変えておきます。 # assert(intersect(c, c)) d = abs(c1.c-c2.c) a = math.acos((c1.r**2+d**2-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)) def contains(g, p): # gは多角形の頂点を順番に並べたリスト/タプル n = len(g) x = False for i in range(n): a = g[i]-p b = g[(i+1)%n]-p if abs(cross(a, b)) < EPS and dot(a, b) < EPS: return 1 if a.y > b.y: a, b = b, a if a.y < EPS and EPS < b.y and cross(a, b) > EPS: x = not x return 2 if x else 0 def andrewScan(s): u = deque() # Polygonクラスはキューで代用可能 l = deque() if len(s) < 3: if ccw(s[0], s[1], s[2]) != CLOCKWISE: s.reverse() return s s.sort() # Pointクラスで<演算子が使えるようにしてあるので、sortができる u.append(s[0]) u.append(s[1]) l.append(s[-1]) l.append(s[-2]) for i in range(2, len(s)): for n in range(len(u), 1, -1): if ccw(u[n-2], u[n-1], s[i]) != CLOCKWISE: break u.pop() u.append(s[i]) for i in range(len(s)-3, -1, -1): for n in range(len(l), 1, -1): if ccw(l[n-2], l[n-1], s[i]) != CLOCKWISE: break l.pop() l.append(s[i]) l.reverse() u = list(u) for i in range(len(u)-2, 0, -1): l.append(u[i]) return l if __name__ == '__main__': from sys import stdin input = stdin.readline n = int(input()) points = [0]*n for i in range(n): points[i] = Point(*map(int, input().split())) l = andrewScan(points) l.reverse() # 反時計回りにする l = list(l) # deqeuのままだと処理が面倒なのでリストに min_index = l.index(min(l, key=lambda p: (p.y, p.x))) print(len(l)) for i in l[min_index:]: print(i.x, i.y) for i in l[:min_index]: print(i.x, i.y) ```
output
1
59,691
23
119,383
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,692
23
119,384
"Correct Solution: ``` def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0) def ConvexHullScan(P): P = sorted(P) phU = [P[0],P[1]] for p in P[2:]: phU.append(p) while(True): try : if isCLKWISE(phU) : break else : del phU[-2] except IndexError : break phL = [P[-1],P[-2]] for p in P[-3::-1]: phL.append(p) while(True): try : if isCLKWISE(phL) : break else : del phL[-2] except IndexError : break ph = phU + phL[1:-1] return ph P = [[int(x) for x in input().split()] for _ in range(int(input()))] P = ConvexHullScan(P) P.reverse() print(len(P)) idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2] for p in P[idx:] + P[:idx] : print(p[0],p[1]) ```
output
1
59,692
23
119,385
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,693
23
119,386
"Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 output: 5 0 0 2 1 4 2 3 3 1 3 """ import sys from operator import attrgetter EPS = 1e-9 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 check_ccw(p0, p1, p2): a, b = p1 - p0, p2 - p0 if cross(a, b) > EPS: # print('COUNTER_CLOCKWISE') flag = 1 elif cross(a, b) < -1 * EPS: # print('CLOCKWISE') flag = -1 elif dot(a, b) < -1 * EPS: # print('ONLINE_BACK') flag = 2 elif abs(a) < abs(b): # print('ONLINE_FRONT') flag = -2 else: # print('ON_SEGMENT') flag = 0 return flag def convex_check_Andrew(_polygon): upper, lower = list(), list() _polygon.sort(key=attrgetter('real', 'imag')) upper.extend((_polygon[0], _polygon[1])) lower.extend((_polygon[-1], _polygon[-2])) for i in range(2, points): n1 = len(upper) while n1 >= 2 and check_ccw(upper[n1 - 2], upper[n1 - 1], _polygon[i]) == 1: n1 -= 1 upper.pop() upper.append(_polygon[i]) for j in range(points - 3, -1, -1): n2 = len(lower) while n2 >= 2 and check_ccw(lower[n2 - 2], lower[n2 - 1], _polygon[j]) == 1: n2 -= 1 lower.pop() lower.append(_polygon[j]) lower.reverse() # find bottom-left of the hull lower_min = min(lower, key=attrgetter('imag', 'real')) min_index = lower.index(lower_min) lower_right = lower[min_index:] lower_left = lower[:min_index] for k in range(len(upper) - 2, 0, -1): lower_right.append(upper[k]) return lower_right + lower_left if __name__ == '__main__': _input = sys.stdin.readlines() points = int(_input[0]) p_info = map(lambda x: x.split(), _input[1:]) polygon = [int(x) + int(y) * 1j for x, y in p_info] ans = convex_check_Andrew(polygon) print(len(ans)) for ele in ans: print(int(ele.real), int(ele.imag)) ```
output
1
59,693
23
119,387
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,694
23
119,388
"Correct 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) 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 COUNTER_CLOCKWISE = 1 CLOCKWISE = -1 ONLINE_BACK = 2 ONLINE_FRONT = -2 ON_SEGMENT = 0 def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if cross(a, b) > EPS: return COUNTER_CLOCKWISE if cross(a, b) < -EPS: return CLOCKWISE if dot(a, b) < -EPS: return ONLINE_BACK if a.norm() < b.norm(): return ONLINE_FRONT return ON_SEGMENT def andrewScan(s): n = len(s) if n < 3: return s u = [] l = [] s.sort() u.append(s[0]) u.append(s[1]) l.append(s[-1]) l.append(s[-2]) for i in range(2, n): for m in range(len(u), 1, -1): if ccw(u[m-2], u[m-1], s[i]) != COUNTER_CLOCKWISE: break u.pop() u.append(s[i]) for i in range(n-3, -1, -1): for m in range(len(l), 1, -1): if ccw(l[m-2], l[m-1], s[i]) != COUNTER_CLOCKWISE: break l.pop() l.append(s[i]) l.reverse() l.extend(u[-2:0:-1]) return l if __name__ == '__main__': n = int(input()) g = [] for i in range(n): x, y = [int(v) for v in input().split()] g.append(Point(x, y)) ans = andrewScan(g) minv = ans[0] mini = 0 for i in range(1, len(ans)): if ans[i].y < minv.y or (ans[i].y == minv.y and ans[i].x < minv.x): minv = ans[i] mini = i ans = ans[mini:] + ans[:mini] print(len(ans)) for v in ans: print('{0} {1}'.format(v.x, v.y)) ```
output
1
59,694
23
119,389
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,695
23
119,390
"Correct Solution: ``` # used in AOJ No.68, yukicoder No.199 # complexity: O(n^(1/2)) eps = 1e-10 def add(a, b): return 0 if abs(a + b) < eps * (abs(a) + abs(b)) else a + b class Point: def __init__(self, x, y): self.x = x self.y = y def __add__(self, p): return Point(add(self.x, p.x), add(self.y, p.y)) def __sub__(self, p): return Point(add(self.x, -p.x), add(self.y, -p.y)) def __mul__(self, d): return Point(self.x * d, self.y * d) def dot(self, p): return add(self.x * p.x, self.y * p.y) def det(self, p): return add(self.x * p.y, -self.y * p.x) def __str__(self): return "({}, {})".format(self.x, self.y) def convex_hull(ps): ps = [Point(x, y) for x, y in sorted([(p.x, p.y) for p in ps])] lower_hull = get_bounds(ps) ps = ps[::-1] upper_hull = get_bounds(ps) del upper_hull[-1] del lower_hull[-1] lower_hull.extend(upper_hull) return lower_hull def get_bounds(ps): qs = [ps[0], ps[1]] for p in ps[2:]: while len(qs) > 1 and (qs[-1] - qs[-2]).det(p - qs[-1]) < 0: del qs[-1] qs.append(p) return qs def aoj(): N = int(input()) ps = [] for _ in range(N): x, y = map(int, input().split()) ps.append(Point(x, y)) convex = convex_hull(ps) print(len(convex)) min_idx = -1 min_x, min_y = 10001, 10001 for i, p in enumerate(convex): if p.y < min_y or (p.y == min_y and p.x < min_x): min_idx = i min_x, min_y = p.x, p.y for p in convex[min_idx:]: print(p.x, p.y) for p in convex[:min_idx]: print(p.x, p.y) if __name__ == '__main__': aoj() ```
output
1
59,695
23
119,391
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,696
23
119,392
"Correct Solution: ``` def cro(a,b): return a.real * b.imag - a.imag * b.real """class Point: def __init__(self,x,y): self.x=x self.y=y def __repr__(self): return repr((self.x, self.y)) """ n = int(input()) p = [] po = [] for i in range(n): x,y=list(int(x) for x in input().split()) p.append(complex(x,y)) po=sorted(p, key=lambda x:(x.imag, x.real)) ps,j = [0]*(n+1),0 for i in range(n): while j > 1 and cro(ps[j-1]-ps[j-2],po[i]-ps[j-1]) < 0: j-=1 ps[j] = po[i] j+=1 l = j for i in reversed(range(n-1)): while j > l and cro(ps[j-1]-ps[j-2],po[i]-ps[j-1]) < 0: j-=1 ps[j] = po[i] j+=1 k = ps[0:j-1] print(len(k)) for i in k: print(int(i.real),int(i.imag)) ```
output
1
59,696
23
119,393
Provide a correct Python 3 solution for this coding contest problem. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1
instruction
0
59,697
23
119,394
"Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 output: 5 0 0 2 1 4 2 3 3 1 3 """ import sys from operator import attrgetter EPS = 1e-9 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 check_ccw(p0, p1, p2): a, b = p1 - p0, p2 - p0 if cross(a, b) > EPS: # print('COUNTER_CLOCKWISE') flag = 1 elif cross(a, b) < -1 * EPS: # print('CLOCKWISE') flag = -1 elif dot(a, b) < -1 * EPS: # print('ONLINE_BACK') flag = 2 elif abs(a) < abs(b): # print('ONLINE_FRONT') flag = -2 else: # print('ON_SEGMENT') flag = 0 return flag def convex_check_Andrew(_polygon): upper, lower = list(), list() _polygon.sort(key=attrgetter('real', 'imag')) upper.extend((_polygon[0], _polygon[1])) lower.extend((_polygon[-1], _polygon[-2])) for i in range(2, points): n1 = len(upper) while n1 >= 2 and check_ccw(upper[n1 - 2], upper[n1 - 1], _polygon[i]) == 1: n1 -= 1 upper.pop() upper.append(_polygon[i]) for j in range(points - 3, -1, -1): n2 = len(lower) while n2 >= 2 and check_ccw(lower[n2 - 2], lower[n2 - 1], _polygon[j]) == 1: n2 -= 1 lower.pop() lower.append(_polygon[j]) # change to counter-clockwise inplace lower.reverse() # find bottom-left of the hull and split the lower part lower_min = min(lower, key=attrgetter('imag', 'real')) min_index = lower.index(lower_min) lower_right = lower[min_index:] lower_left = lower[:min_index] return lower_right + upper[-2:0:-1] + lower_left if __name__ == '__main__': _input = sys.stdin.readlines() points = int(_input[0]) p_info = map(lambda x: x.split(), _input[1:]) polygon = [int(x) + int(y) * 1j for x, y in p_info] ans = convex_check_Andrew(polygon) print(len(ans)) for ele in ans: print(int(ele.real), int(ele.imag)) ```
output
1
59,697
23
119,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` def isCLKWISE(ph): if (ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) >= 0 : return True return False def ConvexHullScan(P): P = sorted(P) phU = [P[0],P[1]] for p in P[2:]: phU.append(p) while(True): if isCLKWISE(phU) : break else : del phU[-2] if len(phU) == 2 : break phL = [P[-1],P[-2]] for p in P[-3::-1]: phL.append(p) while(True): if isCLKWISE(phL) : break else : del phL[-2] if len(phL) == 2 : break ph = phU + phL[1:-1] return ph n = range(int(input())) P = [] for i in n: P.append([int(x) for x in input().split()]) Q = ConvexHullScan(P) Q.reverse() print(len(Q)) idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R : print(r[0],r[1]) ```
instruction
0
59,698
23
119,396
Yes
output
1
59,698
23
119,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` import cmath EPS = 1e-10 #外積 def OuterProduct(one, two): tmp = one.conjugate() * two return tmp.imag #3点が反時計回りか #一直線上のときの例外処理できていない→とりあえずT def CCW(p, q, r): one, two = q-p, r-q if OuterProduct(one, two) > -EPS: return True else: return False #凸包リストを返す def ConvexHull(dots): dots.sort(key=lambda x: (x.imag, x.real)) res1 = [dots[0]] for d in dots[1:]: if len(res1) == 1: res1.append(d) else: while len(res1) > 1 and not CCW(res1[-2], res1[-1], d): res1.pop() res1.append(d) dots.reverse() res2 = [dots[0]] for d in dots[1:]: if len(res2) == 1: res2.append(d) else: while len(res2) > 1 and not CCW(res2[-2], res2[-1], d): res2.pop() res2.append(d) return res1[:-1] + res2[:-1] n = int(input()) dots = [] for _ in range(n): x, y = map(int, input().split()) dots.append(complex(x, y)) ch = ConvexHull(dots) print(len(ch)) for v in ch: print(round(v.real), round(v.imag)) ```
instruction
0
59,699
23
119,398
Yes
output
1
59,699
23
119,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` import math convex_hull_list = [] def isRight_from_gaiseki(p,q,r): area = (q[0]-p[0])*(r[1]-p[1]) - (q[1]-p[1])*(r[0]-p[0]) return area if __name__ == '__main__': N_vertex = int(input()) point_pairs = [(0,0)]*N_vertex # ue to sita de tukuru convex_hull = [(10001,10001)]*(2*N_vertex) # tengun wo point_pairs he irete iku for i in range(N_vertex): x,y = map(int, input().split()) point_pairs[i] = (x,y) point_pairs = sorted(point_pairs, key=lambda x:(x[1],x[0])) if(N_vertex == 3): print(N_vertex) if(isRight_from_gaiseki(point_pairs[0],point_pairs[1],point_pairs[2]) == 0): point_pairs = sorted(point_pairs, key=lambda x:(x[0],x[1])) print("{0} {1}".format(point_pairs[0][0],point_pairs[0][1])) print("{0} {1}".format(point_pairs[1][0],point_pairs[1][1])) print("{0} {1}".format(point_pairs[2][0],point_pairs[2][1])) else: print("{0} {1}".format(point_pairs[0][0],point_pairs[0][1])) print("{0} {1}".format(point_pairs[1][0],point_pairs[1][1])) print("{0} {1}".format(point_pairs[2][0],point_pairs[2][1])) else: k = 0 # gaiseki kara tugi no lower convex_hull youso sagasite ikuzo for i in range(0,N_vertex): while(k >= 2 and isRight_from_gaiseki(convex_hull[k-2],convex_hull[k-1],point_pairs[i])<0): k = k - 1 convex_hull[k] = point_pairs[i] k = k + 1 t = k + 1 # gaiseki kara tugi no upper convex_hull youso sagasite ikuzo for i in range(N_vertex-1, 0, -1): #t = k + 1 while(k >= t and isRight_from_gaiseki(convex_hull[k-2],convex_hull[k-1],point_pairs[i-1])<0): k = k - 1 #k = k + 1 convex_hull[k] = point_pairs[i-1] k = k + 1 convex_hull_valid_num = k - 1 print(convex_hull_valid_num) # result for i in range(0,convex_hull_valid_num): print("{0} {1}".format(convex_hull[i][0],convex_hull[i][1])) ```
instruction
0
59,700
23
119,400
Yes
output
1
59,700
23
119,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` import math from typing import Union, Tuple, List 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 arg(self) -> float: return math.atan2(self.y, self.x) @staticmethod def polar(r, theta) -> Point: return Point(r * math.cos(theta), r * math.sin(theta)) def __repr__(self): return f"({self.x},{self.y})" 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) -> Tuple[Point, Point]: vec_self_to_other = Vector(self, other) vec_abs = vec_self_to_other.abs() # if vec_abs > (self.r + other.r): # raise AssertionError 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 cross_point_with_circle2(self, other) -> Tuple[Point, Point]: vec_self_to_other = Vector(self, other) vec_abs = vec_self_to_other.abs() # if vec_abs > (self.r + other.r): # raise AssertionError theta_base_to_other = vec_self_to_other.arg() theta_other_to_pt = math.acos((pow(self.r, 2) + pow(vec_abs, 2) - pow(other.r, 2)) / (2 * self.r * vec_abs)) return self + Vector.polar(self.r, theta_base_to_other + theta_other_to_pt),\ self + Vector.polar(self.r, theta_base_to_other - theta_other_to_pt) def __repr__(self): return f"({self.x},{self.y}), {self.r}" class Polygon(object): __slots__ = ['vertices', 'num_vertices'] def __init__(self, vertices): self.vertices = vertices self.num_vertices = len(vertices) def contains_point(self, pt: Point) -> int: """ The coordinates of points must be given in the order of visit of them. {0:"not contained", 1: "on a edge", 2:"contained"} """ cross_count = 0 for i in range(self.num_vertices): vec_a = Vector(pt, self.vertices[i]) vec_b = Vector(pt, self.vertices[(i+1) % self.num_vertices]) if vec_a.y > vec_b.y: vec_a, vec_b = vec_b, vec_a dot = vec_a.dot( vec_b) cross = vec_a.cross(vec_b) #print("pt", pt, "vtx", self.vertices[i], self.vertices[(i+1) % self.num_vertices], "vec", vec_a, vec_b, "dot", dot, "cross", cross) if math.isclose(cross, 0.0) and dot <= 0: return 1 # on a edge elif vec_a.y <= 0.0 < vec_b.y and cross > 0: cross_count += 1 return [0, 2][cross_count % 2] @staticmethod def can_form_convex(pt_a: Point, pt_mid: Point, pt_b: Point) -> bool: vec_a = Vector(pt_mid, pt_a) vec_b = Vector(pt_mid, pt_b) if vec_a.cross(vec_b) >= 0: return True else: return False @staticmethod def append_convex_vertex(vertices, convex_full): not_used_vertices = [] for vtx in vertices: if len(convex_full) >= 2: for j in range(1, len(convex_full))[::-1]: if Polygon.can_form_convex(convex_full[j-1], convex_full[j], vtx): break not_used_vertices.append(convex_full.pop()) convex_full.append(vtx) return not_used_vertices @staticmethod def convex_full(vertices: List[Point]) -> List[Point]: # leftmost Point vertices.sort(key=lambda pt: (pt.x, pt.y)) convex_full = [] # form upper convex full not_used_vertices = Polygon.append_convex_vertex(vertices, convex_full) # form lower convex full not_used_vertices.sort(key=lambda pt: (pt.x, pt.y), reverse=True) not_used_vertices.append(vertices[0]) #print(convex_full, not_used_vertices) _ = Polygon.append_convex_vertex(not_used_vertices, convex_full) return convex_full[:-1] def __repr__(self): return f"{self.vertices}" def main(): num_vertices = int(input()) vertices = [] for i in range(num_vertices): pt_x, pt_y = map(int, input().split()) vertices.append(Point(pt_x, pt_y)) convex_full = Polygon.convex_full(vertices) start_vtx = sorted(convex_full, key=lambda pt: (pt.y, pt.x))[0] id = convex_full.index(start_vtx) n = len(convex_full) print(n) for i in range(n): pt = convex_full[(id-i) % n] print(f'{pt.x} {pt.y}') main() ```
instruction
0
59,701
23
119,402
Yes
output
1
59,701
23
119,403
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` from math import sqrt from collections import deque def sub(a, b): return [a[0] - b[0],a[1] - b[1]] def cross(a, b): return a[0] * b[1] - a[1] * b[0] def ccw(a, b, c): x = sub(b, a) y = sub(c, a) return cross(x, y) > 0 n = int(input()) c = [list(map(int, input().split())) for i in range(n)] c.sort(key=lambda x: (x[0], x[1])) U = deque(c[:2]) for i in range(2, n): j = len(U) while j >= 2 and ccw(U[-1],U[-2],c[i]): U.pop() j -= 1 U.append(c[i]) c = c[::-1] L = deque(c[:2]) for i in range(2, n): j = len(L) while j >= 2 and ccw(L[-1], L[-2], c[i]): L.pop() j -= 1 L.append(c[i]) ans = [] for x,y in U: ans.append([x,y]) for x, y in L: if not [x,y] in U: ans.append([x,y]) print(len(ans)) first = sorted(ans, key=lambda x: (x[1], x[0]))[0] i = ans.index(first) for x,y in ans[i:] + ans[:i]: print(x, y) ```
instruction
0
59,702
23
119,404
No
output
1
59,702
23
119,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 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 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(*sorted((pr + e * base, pr - e * base)), key=attrgetter('real', 'imag')) 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(*sorted((c1.c + cmath.rect(c1.r, t + a), c1.c + cmath.rect(c1.r, t - a)), key=attrgetter('real', 'imag'))) def contains(g, p): n = len(g) x = False for i in range(n): a = g[i] - p b = g[(i + 1) % n] - p if abs(cross(a, b)) < EPS and dot(a, b) < EPS: return 1 if a.imag > b.imag: a, b = b, a if a.imag < EPS and EPS < b.imag and cross(a, b) > EPS: x = not x return 2 if x else 0 def andrewScan(s): if len(s) < 3: return s u = [] l = [] s.sort(key=attrgetter('imag')) u.append(s[0]) u.append(s[1]) l.append(s[-1]) l.append(s[-2]) _ccw = 0 for i in range(2, len(s)): for q in range(len(u), 1, -1): _ccw = ccw(u[q - 2], u[q - 1], s[i]) if not (_ccw != CLOCKWISE and _ccw != ONLINE_FRONT): break u.pop() u.append(s[i]) for i in range(len(s) - 3, -1, -1): for q in range(len(l), 1, -1): _ccw = ccw(l[q - 2], l[q - 1], s[i]) if not (_ccw != CLOCKWISE and _ccw != ONLINE_FRONT): break l.pop() l.append(s[i]) return l[::-1] + u[1:len(u) - 1:-1] n = int(readline()) pg = [complex(*map(int, readline().split())) for _ in [0] * n] ans = andrewScan(pg) print(len(ans)) for i in range(len(ans)): print(int(ans[i].real), int(ans[i].imag)) ```
instruction
0
59,703
23
119,406
No
output
1
59,703
23
119,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` from sys import stdin import math from collections import deque EPS = 1e-10 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) # can't apply "number * Vector" but "Vector * number" 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) def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if a.cross(b) > EPS: return 1 elif a.cross(b) < -EPS: return -1 elif a.dot(b) < -EPS: return 2 elif a.norm() < b.norm(): return -2 else: return 0 def convex_hull(P): n = len(P) A = sorted(P, key=lambda p: (p.x, p.y)) U = deque([]) L = deque([]) for i in range(n): if i < 2: U.append(A[i]) else: while ccw(U[-2], U[-1], A[i]) == 1: U.pop() if len(U) == 1: break U.append(A[i]) for i in range(n-1, -1, -1): if i > n-3: L.append(A[i]) else: while ccw(L[-2], L[-1], A[i]) == 1: L.pop() if len(L) == 1: break L.append(A[i]) U.pop() U.popleft() return U + L def read_polygon(n): P = [] for _ in range(n): line = stdin.readline().strip().split() p = Vector(int(line[0]), int(line[1])) P.append(p) return P def __main(): n = int(input()) P = read_polygon(n) P_rev = convex_hull(P) print(len(P_rev)) for i in reversed(P_rev): print("{0} {1}".format(i.x, i.y)) if __name__ == '__main__': __main() ```
instruction
0
59,704
23
119,408
No
output
1
59,704
23
119,409
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon. Constraints * 3 ≤ n ≤ 100000 * -10000 ≤ xi, yi ≤ 10000 * No point in the P will occur more than once. Input n x1 y1 x2 y2 : xn yn The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi. Output In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie. Examples Input 7 2 1 0 0 1 2 2 2 4 2 1 3 3 3 Output 5 0 0 2 1 4 2 3 3 1 3 Input 4 0 0 2 2 0 2 0 1 Output 4 0 0 2 2 0 2 0 1 Submitted Solution: ``` import sys def isCLKWISE(ph): if (ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0 : return False else : return True def ConvexHullScan(P): P = sorted(P) phU = [P[0],P[1]] for p in P[2:]: phU.append(p) while(True): if isCLKWISE(phU) : break else : del phU[-2] if len(phU) == 2 : break phL = [P[-1],P[-2]] for p in P[-3::-1]: phL.append(p) while(True): if isCLKWISE(phL) : break else : del phL[-2] if len(phL) == 2 : break ph = phU + phL[1:-1] return ph input = sys.stdin.readlines() n = int(input[0]) P = map(lambda x: x.split(), _input[1:]) Q = ConvexHullScan(P) Q.reverse() print(len(Q)) idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R: print(r[0],r[1]) ```
instruction
0
59,705
23
119,410
No
output
1
59,705
23
119,411
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,706
23
119,412
"Correct Solution: ``` import sys if __name__ == '__main__': n = int(input()) A = [sys.stdin.readline().split() for _ in range(n)] B = sorted(A,key=lambda x:(int(x[0]),int(x[1]))) for i in range(n): print(*B[i]) ```
output
1
59,706
23
119,413
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,707
23
119,414
"Correct Solution: ``` class Pairs: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): if self.x < other.x: return True elif self.x == other.x: return self.y < other.y else: return False def __str__(self): return "{} {}".format(self.x, self.y) n = int(input()) L = [] for i in range(n): x, y = [int(x) for x in input().split() ] L.append(Pairs(x,y)) L.sort() for i in L: print(i) ```
output
1
59,707
23
119,415
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,708
23
119,416
"Correct Solution: ``` n = int(input()) xy = [list(map(int, input().split())) for i in range(n)] xy.sort(key=lambda x:x[1]) xy.sort(key=lambda x:x[0]) for ele in xy: print(ele[0], ele[1]) ```
output
1
59,708
23
119,417
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,709
23
119,418
"Correct Solution: ``` b = int(input()) a = sorted([list(map(int,input().split())) for i in range(b)]) for c in a: print(c[0],c[1]) ```
output
1
59,709
23
119,419
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,710
23
119,420
"Correct Solution: ``` N = int(input()) P = [tuple(map(int,input().split())) for _ in range(N)] P.sort() for p in P: print(*p) ```
output
1
59,710
23
119,421
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,711
23
119,422
"Correct Solution: ``` n = int(input()) li = [] for i in range(n): l = list(map(int, input().split())) li.append(l) li = sorted(li) for i in li: print(" ".join(map(str, i))) ```
output
1
59,711
23
119,423
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,712
23
119,424
"Correct Solution: ``` from typing import List, Tuple if __name__ == "__main__": n = int(input()) coordinates: List[Tuple[int, int]] = [] for _ in range(n): (x, y) = tuple(map(lambda x: int(x), input().split())) coordinates.append((x, y)) coordinates = sorted(coordinates, key=lambda x: (x[0], x[1])) for elem in coordinates: print(f"{elem[0]} {elem[1]}") ```
output
1
59,712
23
119,425
Provide a correct Python 3 solution for this coding contest problem. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8
instruction
0
59,713
23
119,426
"Correct Solution: ``` # AOJ ITP2_5_A: Sorting Pairs # Python3 2018.6.24 bal4u ps = [] n = int(input()) for i in range(n): x, y = map(int, input().split()) ps.append((x, y)) ps.sort() for i in ps: print(*i) ```
output
1
59,713
23
119,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $x_0 \; y_0$ $x_1 \; y_1$ : $x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Example Input 5 4 7 5 5 2 3 6 8 2 1 Output 2 1 2 3 4 7 5 5 6 8 Submitted Solution: ``` def main(): n = int(input()) A = [] for _ in range(n): a,b = map(int,input().split()) A.append([a,b]) A.sort() for a,b in A:print(a,b) if __name__ == '__main__': main() ```
instruction
0
59,714
23
119,428
Yes
output
1
59,714
23
119,429