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. Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given. Circle inside a rectangle Constraints * $ -100 \leq x, y \leq 100$ * $ 0 < W, H, r \leq 100$ Input Five integers $W$, $H$, $x$, $y$ and $r$ separated by a single space are given in a line. Output Print "Yes" if the circle is placed inside the rectangle, otherwise "No" in a line. Examples Input 5 4 2 2 1 Output Yes Input 5 4 2 4 1 Output No Submitted Solution: ``` def mondai(W, H, x, y, r): if (x + r < 0 or x + r > W or y + r < 0 or y + r > H): print('No') else: print('Yes') W, H, x, y, r = [int(x) for x in input().split()] mondai(W, H, x, y, r) ```
instruction
0
63,979
23
127,958
No
output
1
63,979
23
127,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given. Circle inside a rectangle Constraints * $ -100 \leq x, y \leq 100$ * $ 0 < W, H, r \leq 100$ Input Five integers $W$, $H$, $x$, $y$ and $r$ separated by a single space are given in a line. Output Print "Yes" if the circle is placed inside the rectangle, otherwise "No" in a line. Examples Input 5 4 2 2 1 Output Yes Input 5 4 2 4 1 Output No Submitted Solution: ``` W , H, x, y、r = map(int, input().split()) if r <= x and x <= (W -r) and r <= y and y<= (H -r): print("Yes") else: print("No") ```
instruction
0
63,980
23
127,960
No
output
1
63,980
23
127,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is given an integer k and a grid 2^k Γ— 2^k with some numbers written in its cells, cell (i, j) initially contains number a_{ij}. Grid is considered to be a torus, that is, the cell to the right of (i, 2^k) is (i, 1), the cell below the (2^k, i) is (1, i) There is also given a lattice figure F, consisting of t cells, where t is odd. F doesn't have to be connected. We can perform the following operation: place F at some position on the grid. (Only translations are allowed, rotations and reflections are prohibited). Now choose any nonnegative integer p. After that, for each cell (i, j), covered by F, replace a_{ij} by a_{ij}βŠ• p, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). More formally, let F be given by cells (x_1, y_1), (x_2, y_2), ..., (x_t, y_t). Then you can do the following operation: choose any x, y with 1≀ x, y ≀ 2^k, any nonnegative integer p, and for every i from 1 to n replace number in the cell (((x + x_i - 1)mod 2^k) + 1, ((y + y_i - 1)mod 2^k) + 1) with a_{((x + x_i - 1)mod 2^k) + 1, ((y + y_i - 1)mod 2^k) + 1}βŠ• p. Our goal is to make all the numbers equal to 0. Can we achieve it? If we can, find the smallest number of operations in which it is possible to do this. Input The first line contains a single integer k (1 ≀ k ≀ 9). The i-th of the next 2^k lines contains 2^k integers a_{i1}, a_{i2}, ..., a_{i2^k} (0 ≀ a_{ij} < 2^{60}) β€” initial values in the i-th row of the grid. The next line contains a single integer t (1≀ t ≀ min(99, 4^k), t is odd) β€” number of cells of figure. i-th of next t lines contains two integers x_i and y_i (1 ≀ x_i, y_i ≀ 2^k), describing the position of the i-th cell of the figure. It is guaranteed that all cells are different, but it is not guaranteed that the figure is connected. Output If it is impossible to make all numbers in the grid equal to 0 with these operations, output -1. Otherwise, output a single integer β€” the minimal number of operations needed to do this. It can be shown that if it is possible to make all numbers equal 0, it is possible to do so in less than 10^{18} operations. Example Input 2 5 5 5 5 2 6 2 3 0 0 2 0 0 0 0 0 5 1 1 1 2 1 3 1 4 2 4 Output 3 Note The figure and the operations for the example are shown above: <image> Submitted Solution: ``` n = int(input()) if n==2: print("3") else: print("And I still loving you...") ```
instruction
0
64,099
23
128,198
No
output
1
64,099
23
128,199
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,430
23
128,860
Tags: constructive algorithms, implementation Correct Solution: ``` from sys import stdin a, b, c, d, e, f = map(int, stdin.read().split()) res = [3] for _ in 0, 1: if a == c == e: res.append(1) for _ in range(3): if a == c and not (b < f < d or b > f > d): res.append(2) a, b, c, d, e, f = c, d, e, f, a, b a, b, c, d, e, f = b, a, d, c, f, e print(min(res)) ```
output
1
64,430
23
128,861
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,431
23
128,862
Tags: constructive algorithms, implementation Correct Solution: ``` def f(a,b,c): if a>min(b,c) and a<max(c,b): return True x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) if (x1==x2 and x2==x3) or (y1==y2 and y2==y3): print(1) elif (x1==x2 or x2==x3 or x1==x3 or y1==y2 or y1==y3 or y2==y3): if(x1==x2 and f(y3,y1,y2)): print(3) elif(x2==x3 and(f(y1,y2,y3))): print(3) elif(x1==x3 and(f(y2,y1,y3))): print(3) elif(y1==y2 and f(x3,x1,x2)): print(3) elif(y2==y3 and(f(x1,x2,x3))): print(3) elif(y1==y3 and(f(x2,x3,x1))): print(3) else: print(2) else: print(3) ```
output
1
64,431
23
128,863
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,432
23
128,864
Tags: constructive algorithms, implementation Correct Solution: ``` #!/usr/bin/python3 (x1, y1) = tuple(map(int, input().split())) (x2, y2) = tuple(map(int, input().split())) (x3, y3) = tuple(map(int, input().split())) if (x1 == x2 and x2 == x3) or (y1 == y2 and y2 == y3): print("1") elif (x1 == x2 and y3 >= max(y1, y2)) or (x1 == x2 and y3 <= min(y1, y2)) or (x1 == x3 and y2 >= max(y1, y3)) or (x1 == x3 and y2 <= min(y1, y3)) or (x2 == x3 and y1 >= max(y2, y3)) or (x2 == x3 and y1 <= min(y2, y3)): print("2") elif (y1 == y2 and x3 >= max(x1, x2)) or (y1 == y2 and x3 <= min(x1, x2)) or (y1 == y3 and x2 >= max(x1, x3)) or (y1 == y3 and x2 <= min(x1, x3)) or (y2 == y3 and x1 >= max(x2, x3)) or (y2 == y3 and x1 <= min(x2, x3)): print("2") else: print("3") ```
output
1
64,432
23
128,865
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,433
23
128,866
Tags: constructive algorithms, implementation Correct Solution: ``` def min_polyline(p1, p2, p3): if p1[0] != p2[0] and p1[1] != p2[1]: if p1[0] == p3[0] or p1[1] == p3[1]: p2, p3 = p3, p2 elif p2[0] == p3[0] or p2[1] == p3[1]: p1, p3 = p3, p1 else: return 3 if p1[0] == p2[0]: if p3[0] == p1[0]: return 1 elif p3[1] <= min(p1[1], p2[1]) or p3[1] >= max(p1[1], p2[1]): return 2 else: return 3 else: # p1[1] == p2[1] if p3[1] == p1[1]: return 1 elif p3[0] <= min(p1[0], p2[0]) or p3[0] >= max(p1[0], p2[0]): return 2 else: return 3 if __name__ == '__main__': print(min_polyline(*(tuple(map(int, input().split())) for _ in range(3)))) ```
output
1
64,433
23
128,867
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,434
23
128,868
Tags: constructive algorithms, implementation Correct Solution: ``` p = [tuple(map(int, input().split())) for i in range(3)] if p[0][0] == p[1][0] and p[1][0] == p[2][0] or p[0][1] == p[1][1] and p[1][1] == p[2][1]: print(1) exit() p.sort() if p[0][0] == p[1][0]: print(3 if p[2][1] in range(min(p[0][1], p[1][1]) + 1, max(p[0][1], p[1][1])) else 2) exit() if p[1][0] == p[2][0]: print(3 if p[0][1] in range(min(p[1][1], p[2][1]) + 1, max(p[1][1], p[2][1])) else 2) exit() p = sorted((y, x) for (x, y) in p) if p[0][0] == p[1][0]: print(3 if p[2][1] in range(min(p[0][1], p[1][1]) + 1, max(p[0][1], p[1][1])) else 2) exit() if p[1][0] == p[2][0]: print(3 if p[0][1] in range(min(p[1][1], p[2][1]) + 1, max(p[1][1], p[2][1])) else 2) exit() print(3) ```
output
1
64,434
23
128,869
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,435
23
128,870
Tags: constructive algorithms, implementation Correct Solution: ``` x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) v1 = len(set([x1, x2, x3])) v2 = len(set([y1, y2, y3])) if(v1>v2): v1, v2=v2, v1 # print(v1, v2) if(v1==1): if(v2==1): print(0) else: print(1) elif(v1==2): if(v2==2): print(2) else: u1 = len(set([x1, x2, x3])) u2 = len(set([y1, y2, y3])) if(u2==2): x1, y1 = y1, x1 x2, y2 = y2, x2 x3, y3 = y3, x3 if (x2==x3): x3, x1=x1, x3 y3, y1=y1, y3 elif (x1==x3): x3, x2=x2, x3 y3, y2=y2, y3 if(y3>=y1 and y3<=y2) or (y3>=y2 and y3<=y1): print(3) else: print(2) else: print(3) ```
output
1
64,435
23
128,871
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,436
23
128,872
Tags: constructive algorithms, implementation Correct Solution: ``` x, y = zip(*[map(int, input().split(' ')) for i in range(3)]) def getCnt(a): if a[0] == a[1] == a[2]: return 3 if a[0] == a[1] or a[0] == a[2] or a[1]==a[2] : return 2 return 1 similar = max(getCnt(x), getCnt(y)) if similar == 3: print(1) elif similar == 2: if getCnt(x) == 2: if x[0] == x[1]: a, b, c = 0, 1, 2 elif x[1] == x[2]: a, b, c = 1,2,0 else: a, b, c = 2,0,1 if (y[c] > y[a] and y[c] < y[b]) or (y[c] > y[b] and y[c] < y[a]): print(3) else: print(2) else: if y[0] == y[1]: a, b, c = 0, 1, 2 elif y[1] == y[2]: a, b, c = 1,2,0 else: a, b, c = 2,0,1 if (x[c] > x[a] and x[c] < x[b]) or (x[c] > x[b] and x[c] < x[a]): print(3) else: print(2) else: print(3) ```
output
1
64,436
23
128,873
Provide tags and a correct Python 3 solution for this coding contest problem. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image>
instruction
0
64,437
23
128,874
Tags: constructive algorithms, implementation Correct Solution: ``` read = lambda: map(int, input().split()) bet = lambda a, b, c: a <= c <= b or b <= c <= a f = lambda A, B, C: (C[0] == A[0] or C[0] == B[0]) and bet(A[1], B[1], C[1]) or (C[1] == A[1] or C[1] == B[1]) and bet(A[0], B[0], C[0]) A, B, C = tuple(read()), tuple(read()), tuple(read()) ans = 3 if f(A, B, C) or f(A, C, B) or f(B, C, A): ans = 2 if A[0] == B[0] == C[0] or A[1] == B[1] == C[1]: ans = 1 print(ans) ```
output
1
64,437
23
128,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` x = [0]*3 y = [0]*3 for i in range(3): x[i],y[i] = [int(x) for x in input().split()] def is_between(a,b,c): return min(a, b) <= c and c <= max(a, b) def f(i,j,k): return (x[k] == x[i] or x[k] == x[j]) and is_between(y[i], y[j], y[k]) or (y[k] == y[i] or y[k] == y[j]) and is_between(x[i], x[j], x[k]) if (x[1] == x[2] and x[2] == x[0]) or (y[1] == y[2] and y[2] == y[0]): print("1") elif f(0,1,2) or f(0,2,1) or f(1,2,0): print("2") else: print("3") ```
instruction
0
64,438
23
128,876
Yes
output
1
64,438
23
128,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` #!/usr/bin/env python3 from collections import namedtuple from itertools import permutations Point = namedtuple("Point", "x y") try: while True: p = [Point(*map(int, input().split())) for i in range(3)] a, b, c = p if a.x == b.x == c.x or a.y == b.y == c.y: print(1) else: for a, b, c in permutations(p): if a.x == b.x and not a.y < c.y < b.y and not b.y < c.y < a.y: print(2) break if a.y == b.y and not a.x < c.x < b.x and not b.x < c.x < a.x: print(2) break else: print(3) except EOFError: pass ```
instruction
0
64,439
23
128,878
Yes
output
1
64,439
23
128,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) if (a[0] == b[0] and b[0] == c[0]) or (a[1] == b[1] and b[1] == c[1]): print(1) exit() if (a[0] == b[0] and ((c[1] >= a[1] and c[1] >= b[1]) or (c[1] <= a[1] and c[1] <= b[1]))) or \ (a[0] == c[0] and ((b[1] >= a[1] and b[1] >= c[1]) or (b[1] <= a[1] and b[1] <= c[1]))) or \ (c[0] == b[0] and ((a[1] >= c[1] and a[1] >= b[1]) or (a[1] <= b[1] and a[1] <= c[1]))) or \ (a[1] == b[1] and ((c[0] >= a[0] and c[0] >= b[0]) or (c[0] <= a[0] and c[0] <= b[0]))) or \ (a[1] == c[1] and ((b[0] >= a[0] and b[0] >= c[0]) or (b[0] <= a[0] and b[0] <= c[0]))) or \ (b[1] == c[1] and ((a[0] >= c[0] and a[0] >= b[0]) or (a[0] <= b[0] and a[0] <= c[0]))): print(2) exit() print(3) ```
instruction
0
64,440
23
128,880
Yes
output
1
64,440
23
128,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` import os import sys from io import BytesIO, IOBase from collections import Counter import math as mt # #MAXN = int(1e7 + 1) # # spf = [0 for i in range(MAXN)] # # # def sieve(): # spf[1] = 1 # for i in range(2, MAXN): # spf[i] = i # for i in range(4, MAXN, 2): # spf[i] = 2 # # for i in range(3, mt.ceil(mt.sqrt(MAXN))): # if (spf[i] == i): # for j in range(i * i, MAXN, i): # if (spf[j] == j): # spf[j] = i # # # def getFactorization(x): # ret = 0 # while (x != 1): # k = spf[x] # ret += 1 # # ret.add(spf[x]) # while x % k == 0: # x //= k # # return ret # Driver code # precalculating Smallest Prime Factor # sieve() BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) def totalPrimeFactors(n): count = 0 if (n % 2) == 0: count += 1 while (n % 2) == 0: n //= 2 i = 3 while i * i <= n: if (n % i) == 0: count += 1 while (n % i) == 0: n //= i i += 2 if n > 2: count += 1 return count def countPairs(G, L): if L % G != 0: return 0 div = int(L / G) return 1 << getFactorization(div) def main(): a = [] b=[] for i in range(3): a.append(list(map(int, input().split()))) #b.append([a[i][1], a[i][0]]) if a[0][0]==a[1][0]==a[2][0] or a[0][1]==a[1][1]==a[2][1]: print(1) else: f=0 for i in range(3): for j in range(3): k=3-i-j if i!=j: for t in range(2): if a[i][t]==a[j][t] and (a[k][1^t]<=min(a[i][1^t], a[j][1^t]) or a[k][1^t]>=max(a[i][1^t], a[j][1^t])): f=1 if f: print(2) else: print(3) return if __name__ == "__main__": main() ```
instruction
0
64,441
23
128,882
Yes
output
1
64,441
23
128,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) if (x1==x2 and x1==x3) or (y1==y2 and y1==y3): print(1) elif (x1==x2 and (y1==y3 or y2==y3)) or( y1==y2 and (x1==x3 or x2==x3)): print(2) else: print(3) ```
instruction
0
64,442
23
128,884
No
output
1
64,442
23
128,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` x, y = zip(*[map(int, input().split(' ')) for i in range(3)]) def getCnt(a): if a[0] == a[1] == a[2]: return 3 if a[0] == a[1] or a[0] == a[2] or a[1]==a[2] : return 2 return 1 similar = max(getCnt(x), getCnt(y)) if similar == 3: print(1) elif similar == 2: print(2) else: print(3) ```
instruction
0
64,443
23
128,886
No
output
1
64,443
23
128,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` x = [0] * 3 y = [0] * 3 for i in range(3): x[i], y[i] = map(int,input().split()) if x[0] == x[1] == x[2] or y[0] == y[1] == y[2]: print(1) elif x[0] == x[1] and (y[2]>=x[0] or y[2]>=y[1]): print(2) elif x[0] == x[2] and (y[1]>=x[0] or y[1]>=y[2]): print(2) elif x[1] == x[2] and (y[0]>=x[1] or y[0]>=y[2]): print(2) elif y[0] == y[1] and (x[2]>=y[0] or x[2]>=x[1]): print(2) elif y[0] == y[2] and (x[1]>=y[0] or x[1]>=x[2]): print(2) elif y[1] == y[2] and (x[0]>=y[1] or x[0]>=x[2]): print(2) else: print(3) ```
instruction
0
64,444
23
128,888
No
output
1
64,444
23
128,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. Input Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≀ xi, yi ≀ 109) β€” the coordinates of the i-th point. It is guaranteed that all points are distinct. Output Print a single number β€” the minimum possible number of segments of the polyline. Examples Input 1 -1 1 1 1 2 Output 1 Input -1 -1 -1 3 4 3 Output 2 Input 1 1 2 3 3 2 Output 3 Note The variant of the polyline in the first sample: <image> The variant of the polyline in the second sample: <image> The variant of the polyline in the third sample: <image> Submitted Solution: ``` R = lambda : map(int, input().split()) px,py = [],[] for _ in range(3): x,y=R() px.append((x,y)) py.append((y,x)) px=sorted(px) py=sorted(py) def solve(p): if p[0][0]==p[2][0]: return 1 if p[0][0]==p[1][0] and (p[2][1]<=p[0][1] or p[2][1]>=p[1][1]): return 2 if p[1][0]==px[2][0] and (p[0][1]<=p[1][1] or p[0][1]>=p[2][1]): return 2 return 3 print(min(solve(px),solve(py))) ```
instruction
0
64,445
23
128,890
No
output
1
64,445
23
128,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. Input You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. Output Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. Examples Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO Submitted Solution: ``` a = [] for i in range(10): a.append(input()) def valid(x, y): if 0 <= x <= 9 and 0 <= y <= 9: return True return False def check(x, y, direction): ans = 1 curr_x = x + direction[0] curr_y = y + direction[1] while valid(curr_x, curr_y) and a[curr_x][curr_y] == 'X': ans += 1 curr_x += direction[0] curr_y += direction[1] curr_x = x - direction[0] curr_y = y - direction[1] while valid(curr_x, curr_y) and a[curr_x][curr_y] == 'X': ans += 1 curr_x -= direction[0] curr_y -= direction[1] return ans curr = 0 for i in range(10): for j in range(10): if a[i][j] == '.': for direction in [[1, 0], [0, 1], [1, 1], [1, -1]]: curr = max(curr, check(i, j, direction)) if curr >= 5: print('YES') else: print('NO') ```
instruction
0
64,513
23
129,026
Yes
output
1
64,513
23
129,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. Input You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. Output Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. Examples Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO Submitted Solution: ``` import sys import math def check(s): dot = s.count('.') # x = s.count('X') o = s.count('O') if o != 0: return False if dot in [0, 1]: return True arr = [] for _ in range(10): arr.append(sys.stdin.readline().strip()) for i in range(10): for j in range(6): st = arr[i][j:j+5] # print(st) if check(st): sys.stdout.write("YES") exit() for i in range(10): for j in range(6): st = '' for k in range(j, j+5): st += arr[k][i] if check(st): sys.stdout.write("YES") exit() for i in range(6): rw, cl = i, 0 m_s = '' while rw<10 and cl<10: m_s += arr[rw][cl] rw += 1 cl += 1 n = len(m_s) for k in range(n-5): st = m_s[k:k+5] if check(st): sys.stdout.write("YES") exit() rw, cl = 0, i while rw<10 and cl<10: m_s += arr[rw][cl] rw += 1 cl += 1 n = len(m_s) for k in range(n-5): st = m_s[k:k+5] if check(st): sys.stdout.write("YES") exit() for i in range(4, 10): rw, cl = 0, i m_s = '' while rw<10 and cl>=0: m_s += arr[rw][cl] rw += 1 cl -= 1 n = len(m_s) # print(n) for k in range(n-5): st = m_s[k:k+5] if check(st): sys.stdout.write("YES") exit() rw, cl = 10-i, 9 while rw<10 and cl>=0: m_s += arr[rw][cl] rw += 1 cl -= 1 n = len(m_s) for k in range(n-5): st = m_s[k:k+5] if check(st): sys.stdout.write("YES") exit() sys.stdout.write('NO') ```
instruction
0
64,518
23
129,036
No
output
1
64,518
23
129,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. Input You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. Output Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. Examples Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO Submitted Solution: ``` #!/usr/bin/env python3 def solve(): grid = [list(get(str)) for i in range(10)] s = set() for i in range(10): for j in range(10): s.add(tuple(grid[i][j:j+5])) # print(''.join(tuple(grid[i][j:j+5]))) if i + 5 < 10: s.add(tuple([grid[i+x][j] for x in range(5)])) # print(''.join(tuple([grid[i+x][j] for x in range(5)]))) if j + 5 < 10: # print(''.join(tuple([grid[i+x][j+x] for x in range(5)]))) s.add(tuple([grid[i+x][j+x] for x in range(5)])) if i - 5 >= 0: s.add(tuple([grid[i-x][j] for x in range(5)])) # print(''.join(tuple([grid[i+x][j] for x in range(5)]))) if j - 5 >= 0: # print(''.join(tuple([grid[i+x][j+x] for x in range(5)]))) s.add(tuple([grid[i-x][j-x] for x in range(5)])) s = set(''.join(val) for val in s) s2 = set('.XXXX X.XXX XX.XX XXX.X XXXX.'.split()) # print(s) if len(s2 & s) > 0: return 'YES' else: return 'NO' _testcases = """ XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... YES XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... NO """.strip() # ======================= B O I L E R P L A T E ======================= # # Practicality beats purity import re import sys import math import heapq from heapq import heapify, heappop, heappush import bisect from bisect import bisect_left, bisect_right import operator from operator import itemgetter, attrgetter import itertools import collections inf = float('inf') sys.setrecursionlimit(10000) def tree(): return collections.defaultdict(tree) def cache(func): # Decorator for memoizing a function cache_dict = {} def _cached_func(*args, _get_cache=False): if _get_cache: return cache_dict if args in cache_dict: return cache_dict[args] cache_dict[args] = func(*args) return cache_dict[args] return _cached_func def equal(x, y, epsilon=1e-6): # https://code.google.com/codejam/kickstart/resources/faq#real-number-behavior if -epsilon <= x - y <= epsilon: return True if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon: return False return (-epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon) def get(_type): # For easy input if type(_type) == list: if len(_type) == 1: _type = _type[0] return list(map(_type, input().strip().split())) else: return [_type[i](inp) for i, inp in enumerate(input().strip().split())] else: return _type(input().strip()) if __name__ == '__main__': print(solve()) ```
instruction
0
64,519
23
129,038
No
output
1
64,519
23
129,039
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,568
23
129,136
Tags: geometry, implementation Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- quadrate1 = list(map(int, input().split())) quadrate2 = list(map(int, input().split())) def sq2_treug(x1,y1, x2,y2, x3,y3) -> int: ''' doubled square of triangle with sign. ''' return (x3-x1)*(y2-y1) - (y3-y1)*(x2-x1) def point_in_square(x,y, x1,y1, x2,y2, x3,y3, x4,y4, sq2) -> bool: sq1 = abs(sq2_treug(x,y, x1,y1, x2,y2)) \ + abs(sq2_treug(x,y, x2,y2, x3,y3)) \ + abs(sq2_treug(x,y, x3,y3, x4,y4)) \ + abs(sq2_treug(x,y, x4,y4, x1,y1)) return sq2 == sq1 # doubled squares of quadrates sq21 = 2 * (max(quadrate1[::2]) - min(quadrate1[::2])) \ * (max(quadrate1[1::2]) - min(quadrate1[1::2])) sq22 = (max(quadrate2[::2]) - min(quadrate2[::2])) \ * (max(quadrate2[1::2]) - min(quadrate2[1::2])) inter = any([ point_in_square(quadrate1[2*i], quadrate1[2*i+1], *quadrate2, sq22) for i in range(4) ]) or any([ point_in_square(quadrate2[2*i], quadrate2[2*i+1], *quadrate1, sq21) for i in range(4) ]) or point_in_square( (max(quadrate1[::2]) + min(quadrate1[::2])) // 2, (max(quadrate1[1::2]) + min(quadrate1[1::2])) // 2, *quadrate2, sq22 ) or point_in_square( (max(quadrate2[::2]) + min(quadrate2[::2])) // 2, (max(quadrate2[1::2]) + min(quadrate2[1::2])) // 2, *quadrate1, sq21 ) print("YES" if inter else "NO") ```
output
1
64,568
23
129,137
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,569
23
129,138
Tags: geometry, implementation Correct Solution: ``` a = list(map(int, input().split())) b = list(map(int, input().split())) x1 = min(a[0], a[2], a[4], a[6]) x2 = max(a[0], a[2], a[4], a[6]) y1 = min(a[1], a[3], a[5], a[7]) y2 = max(a[1], a[3], a[5], a[7]) d1 = min(b[0] - b[1], b[2] - b[3], b[4] - b[5], b[6] - b[7]) d2 = max(b[0] - b[1], b[2] - b[3], b[4] - b[5], b[6] - b[7]) s1 = min(b[0] + b[1], b[2] + b[3], b[4] + b[5], b[6] + b[7]) s2 = max(b[0] + b[1], b[2] + b[3], b[4] + b[5], b[6] + b[7]) for x in range(-100, 101): for y in range(-100, 101): d = x - y s = x + y if x1 <= x <= x2 and y1 <= y <= y2 and s1 <= s <= s2 and d1 <= d <= d2: print("YES") exit(0) print("NO") ```
output
1
64,569
23
129,139
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,570
23
129,140
Tags: geometry, implementation Correct Solution: ``` s = list(map(int, input().split())) s = [s[i:i+2] for i in range(0,8,2)] s.sort() t = list(map(int, input().split())) t = [t[i:i+2] for i in range(0,8,2)] t.sort() for i in t: if s[0][0] <= i[0] <= s[3][0] and s[0][1] <= i[1] <= s[3][1]: print('YES'); exit() for i in s: if sum(t[0]) <= sum(i) <= sum(t[3]) and t[0][0]-t[0][1] <= i[0]-i[1] <= t[3][0]-t[3][1]: print('YES'); exit() O = [(t[0][0]+t[3][0])//2,(t[0][1]+t[3][1])//2] if s[0][0] <= O[0] <= s[3][0] and s[0][1] <= O[1] <= s[3][1]: print('YES'); exit() print('NO') ```
output
1
64,570
23
129,141
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,571
23
129,142
Tags: geometry, implementation Correct Solution: ``` a = list(map(int, input().split())) b = list(map(int, input().split())) xa = a[0::2] ya = a[1::2] xb = b[0::2] yb = b[1::2] miny = min(yb) maxy = max(yb) for i in range(miny, (miny + maxy) // 2 + 1): for j in range(xb[yb.index(miny)] - (abs(i - miny)), xb[yb.index(miny)] + (abs(i - miny)) + 1): if min(xa) <= j <= max(xa) and min(ya) <= i <= max(ya): print("YES") exit(0) for i in range(maxy, (miny + maxy) // 2, -1): for j in range(xb[yb.index(miny)] - (abs(i - maxy)), xb[yb.index(miny)] + (abs(i - maxy)) + 1): if min(xa) <= j <= max(xa) and min(ya) <= i <= max(ya): print("YES") exit(0) print("NO") ```
output
1
64,571
23
129,143
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,572
23
129,144
Tags: geometry, implementation Correct Solution: ``` def cp(a, b): return a[0]*b[1] - a[1]*b[0] def sub(b, a): return (b[0]-a[0], b[1]-a[1]) def ccw(a, b, c): r = cp(sub(b,a), sub(c,a)) if r == 0: return 0 elif r > 0: return 1 else: return -1 def sortpts(pts): return pts if ccw(pts[0], pts[1], pts[2]) > 0 else list(reversed(pts)) def readpts(): ip = list(map(int, input().split())) return sortpts([(ip[i], ip[i+1]) for i in range(0,8,2)]) def segi(a1, a2, b1, b2): c1 = ccw(a1, a2, b1) c2 = ccw(a1, a2, b2) return c1 != c2 def segib(a1, a2, b1, b2): return segi(a1, a2, b1, b2) and segi(b1, b2, a1, a2) def checkpts(pts1, pts2): for p1 in pts1: aa = True for i in range(4): j = (i+1)%4 if ccw(pts2[i], pts2[j], p1) < 0: aa = False if aa: return True return False def checkpts2(pts1, pts2): for i in range(4): for j in range(4): if segib(pts1[i], pts1[(i+1)%4], pts2[j], pts2[(j+1)%4]): return True return False pts1 = readpts() pts2 = readpts() #print(pts1) #print(pts2) print('YES' if checkpts(pts1, pts2) or checkpts(pts2, pts1) or checkpts2(pts1, pts2) else 'NO') ```
output
1
64,572
23
129,145
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,573
23
129,146
Tags: geometry, implementation Correct Solution: ``` def check1(point): return sq1[0][0] <= point[0] <= sq1[3][0] and sq1[0][1] <= point[1] <= sq1[3][1] def check2(point): return point[0] + sq2[0][1] - sq2[0][0] >= point[1] and point[0] + sq2[3][1] - sq2[3][0] <= point[1] and -point[0] + sq2[3][1] + sq2[3][0] >= point[1] and -point[0] + sq2[0][1] + sq2[0][0] <= point[1] t = [int(i) for i in input().split()] sq1 = list(zip(t[::2], t[1::2])) sq1.sort() t = [int(i) for i in input().split()] sq2 = list(zip(t[::2], t[1::2])) sq2.sort() sq2[1], sq2[2] = sq2[2], sq2[1] for i in range(-100, 101): for j in range(-100, 101): if check1((i, j)) and check2((i, j)): print("YES") exit() print("NO") ```
output
1
64,573
23
129,147
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,574
23
129,148
Tags: geometry, implementation Correct Solution: ``` from sys import exit n = 4 a = list(map(int, input().split())) am0 = min(a[0], a[2], a[4], a[6]) am1 = max(a[0], a[2], a[4], a[6]) aM0 = min(a[1], a[3], a[5], a[7]) aM1 = max(a[1], a[3], a[5], a[7]) b = list(map(int, input().split())) bm0 = min(b[0], b[2], b[4], b[6]) bm1 = max(b[0], b[2], b[4], b[6]) bM0 = min(b[1], b[3], b[5], b[7]) bM1 = max(b[1], b[3], b[5], b[7]) for i in range(5): if i < 4: x, y = b[2 * i], b[2 * i + 1] else: x, y = (bm0 + bm1) / 2, (bM0 + bM1) / 2 if am0 <= x <= am1 and aM0 <= y <= aM1: print('YES') exit(0) b = [ (b[0] - b[1], b[0] + b[1]), (b[2] - b[3], b[2] + b[3]), (b[4] - b[5], b[4] + b[5]), (b[6] - b[7], b[6] + b[7]), ] bm0 = min(b[0][0], b[1][0], b[2][0], b[3][0]) bm1 = max(b[0][0], b[1][0], b[2][0], b[3][0]) bM0 = min(b[0][1], b[1][1], b[2][1], b[3][1]) bM1 = max(b[0][1], b[1][1], b[2][1], b[3][1]) for i in range(5): if i < 4: x, y = a[2 * i], a[2 * i + 1] else: x, y = (am0 + am1) / 2, (aM0 + aM1) / 2 x, y = x - y, x + y if bm0 <= x <= bm1 and bM0 <= y <= bM1: print('YES') exit(0) print('NO') ```
output
1
64,574
23
129,149
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image>
instruction
0
64,575
23
129,150
Tags: geometry, implementation Correct Solution: ``` from collections import defaultdict x1,y1,x2,y2,x3,y3,x4,y4 = map(int,input().split()) a1,b1,a2,b2,a3,b3,a4,b4 = map(int,input().split()) first = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)] sec = [(a1,b1),(a2,b2),(a3,b3),(a4,b4)] sec.sort() D = defaultdict(bool) y = sec[1][1]-1 for i in range(sec[1][0], sec[0][0]-1, -1): y+=1 yy = y-1 for j in range(i,i+sec[3][0] - sec[1][0] + 1): yy+=1 D[(j,yy)] = True first.sort() ok = False for i in range(first[0][0], first[2][0] + 1): for j in range(first[0][1], first[1][1] + 1): if(D[(i,j)]): ok = True break if(ok): break if(ok): print("YES") else: print("NO") ```
output
1
64,575
23
129,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` a = list(map(int, input().split())) b = list(map(int, input().split())) x = [] y = [] for i in range(8): if i % 2 == 0: if a[i] not in x: x.append(a[i]) else: if a[i] not in y: y.append(a[i]) x.sort() y.sort() f = 0 nowx = nowfx = b[2] nowy = nowfy = b[3] tarx = tarfx = b[4] tary = tarfy = b[5] gox = (-b[2] + b[0]) // abs(b[2] - b[0]) goy = (-b[3] + b[1]) // abs(b[3] - b[1]) while nowx != b[0]: #print(1) #print(nowx, nowy, tarx, tary) nowfx += gox nowfy += goy tarfx += gox tarfy += goy addx = (tarx - nowx) // abs(tarx - nowx) addy = (tary - nowy) // abs(tary - nowy) while nowx != tarx and nowy != tary: if x[0] <= nowx <= x[1] and y[0] <= nowy <= y[1]: f = 1 nowx += addx nowy += addy if x[0] <= nowx <= x[1] and y[0] <= nowy <= y[1]: f = 1 nowx += addx nowy += addy nowx = nowfx nowy = nowfy tarx = tarfx tary = tarfy #print(nowx, nowy, tarx, tary) addx = (tarx - nowx) // abs(tarx - nowx) addy = (tary - nowy) // abs(tary - nowy) while nowx != tarx and nowy != tary: if x[0] <= nowx <= x[1] and y[0] <= nowy <= y[1]: f = 1 nowx += addx nowy += addy if x[0] <= nowx <= x[1] and y[0] <= nowy <= y[1]: f = 1 nowx += addx nowy += addy print('YES' if (f) else 'NO') ```
instruction
0
64,576
23
129,152
Yes
output
1
64,576
23
129,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` a = list(map(int, input().split())) sax, bax, say, bay = min(a[0::2]), max(a[0::2]), min(a[1::2]), max(a[1::2]) b = list(map(int, input().split())) sbx, bbx, sby, bby = min(b[0::2]), max(b[0::2]), min(b[1::2]), max(b[1::2]) mp = {} ans = "No" for i in range(sax, bax + 1): for j in range(say, bay + 1): mp[(i, j)] = 1 midy = (sby + bby) >> 1 for i in range(sbx, bbx + 1): bnd = min(i - sbx, bbx - i) for j in range(midy - bnd, midy + bnd + 1): if ((i, j) in mp): ans = "Yes" print(ans) ```
instruction
0
64,577
23
129,154
Yes
output
1
64,577
23
129,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` rd = lambda: list(map(int, input().split())) z = [] for i in 'ii': a = rd() z += [a[::2], a[1::2]] for x in z: x.sort() u, v, x, y = z for i in range(u[0], u[3] + 1): for j in range(v[0], v[3] + 1): if x[0] + y[1] <= i + j <= x[3] + y[1] and y[0] - x[1] <= j - i <= y[3] - x[1]: print('YES') exit() print('NO') ```
instruction
0
64,578
23
129,156
Yes
output
1
64,578
23
129,157
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` x1, y1, x2, y2, x3, y3, x4, y4 = map(int, input().split()) a1, b1, a2, b2, a3, b3, a4, b4 = map(int, input().split()) xy = [(x1, y1), (x2, y2), (x3, y3), (x4, y4)] ab = [(a1, b1), (a2, b2), (a3, b3), (a4, b4)] t = 0 for i in range(4): if ab[i][0] >= min(x1, x2, x3, x4) and ab[i][0] <= max(x1, x2, x3, x4): if ab[i][1] >= min(y1, y2, y3, y4) and ab[i][1] <= max(y1, y2, y3, y4): t = 1 ao = (a1 + a2 + a3 + a4 - min(a1, a2, a3, a4) - max(a1, a2, a3, a4)) // 2 bo = (b1 + b2 + b3 + b4 - min(b1, b2, b3, b4) - max(b1, b2, b3, b4)) // 2 if ao >= min(x1, x2, x3, x4) and ao <= max(x1, x2, x3, x4): if bo >= min(y1, y2, y3, y4) and bo <= max(y1, y2, y3, y4): t = 1 x1, y1 = x1 + y1, x1 - y1 x2, y2 = x2 + y2, x2 - y2 x3, y3 = x3 + y3, x3 - y3 x4, y4 = x4 + y4, x4 - y4 a1, b1 = a1 + b1, a1 - b1 a2, b2 = a2 + b2, a2 - b2 a3, b3 = a3 + b3, a3 - b3 a4, b4 = a4 + b4, a4 - b4 x1, a1 = a1, x1 x2, a2 = a2, x2 x3, a3 = a3, x3 x4, a4 = a4, x4 y1, b1 = b1, y1 y2, b2 = b2, y2 y3, b3 = b3, y3 y4, b4 = b4, y4 xy = [(x1, y1), (x2, y2), (x3, y3), (x4, y4)] ab = [(a1, b1), (a2, b2), (a3, b3), (a4, b4)] for i in range(4): if ab[i][0] >= min(x1, x2, x3, x4) and ab[i][0] <= max(x1, x2, x3, x4): if ab[i][1] >= min(y1, y2, y3, y4) and ab[i][1] <= max(y1, y2, y3, y4): t = 1 ao = (a1 + a2 + a3 + a4 - min(a1, a2, a3, a4) - max(a1, a2, a3, a4)) // 2 bo = (b1 + b2 + b3 + b4 - min(b1, b2, b3, b4) - max(b1, b2, b3, b4)) // 2 if ao >= min(x1, x2, x3, x4) and ao <= max(x1, x2, x3, x4): if bo >= min(y1, y2, y3, y4) and bo <= max(y1, y2, y3, y4): t = 1 if t == 1: print("YES") else: print("NO") ```
instruction
0
64,579
23
129,158
Yes
output
1
64,579
23
129,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` def check1(point): return sq1[0][0] <= point[0] <= sq1[3][0] and sq1[0][1] <= point[1] <= sq1[3][1] def check2(point): return sq2[0][0] <= point[0] <= sq2[3][0] and sq2[1][1] <= point[1] <= sq2[2][1] t = [int(i) for i in input().split()] sq1 = list(zip(t[::2], t[1::2])) sq1.sort() t = [int(i) for i in input().split()] sq2 = list(zip(t[::2], t[1::2])) sq2.sort() # print(check1(sq2[0])) # print(sq2[0]) print("Yes" if any(check1(el) for el in sq2) or any(check2(el) for el in sq1) else "No") ```
instruction
0
64,580
23
129,160
No
output
1
64,580
23
129,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` x1,y1,x2,y2,x3,y3,x4,y4=map(int,input().split()) m =list(map(int,input().split())) a = x1 b = y1 c = x3 d = y3 def ins(x,y): global a,b,c,d return a<=x<=b and c <= y <= d class point: def __init__(self,x,y): self.x = x self.y = y def ccw(A,B,C): return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x) def intersect(A,B,C,D): return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D) for i in range(0,8,2): x,y = m[i:i+2] if ins(x,y): print('YES') break else: m+=m[:2] reg= [point(x1,y1), point(x2,y2),point(x3,y3),point(x4,y4)] new = [point(m[0], m[1]), point(m[2], m[3]),point(m[4], m[5]),point(m[6], m[7])] flag=False for p1 in reg: for p2 in reg: for q1 in new: for q2 in new: if intersect(p1, p2, q1, q2): flag = True break if flag: print('YES') else: print('NO') ```
instruction
0
64,581
23
129,162
No
output
1
64,581
23
129,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` s = list(map(int, input().split())) s = [s[i:i+2] for i in range(0,8,2)] s.sort() t = list(map(int, input().split())) t = [t[i:i+2] for i in range(0,8,2)] t.sort() print(s, t) for i in t: if s[0][0] <= i[0] <= s[3][0] and s[0][1] <= i[1] <= s[3][1]: print('YES'); exit() for i in s: if sum(t[0]) <= sum(i) <= sum(t[3]) and t[0][0]-t[0][1] <= i[0]-i[1] <= t[3][0]-t[3][1]: print('YES'); exit() print('NO') ```
instruction
0
64,582
23
129,164
No
output
1
64,582
23
129,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between -100 and 100. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Output YES Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Output NO Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Output YES Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: <image> <image> <image> Submitted Solution: ``` sqa = list(map(int, input().split())) sqb = list(map(int, input().split())) sq1 = [] sq2 = [] def get_coords(seq, dest): a,b = 0,1 for i in range(4): dest.append((seq[a], seq[b])) a += 2 b += 2 def check_pt(p1,p2,p3): if p1[0]-p2[0]==0 and p3[0]==p1[0] and abs(p3[1])<=abs(p1[1]-p2[1]): return 1 elif p1[1]-p2[1]==0 and p3[1]==p1[1] and abs(p3[0])<=abs(p1[0]-p2[0]): return 1 elif p1[0]-p2[0]!=0: m = (p2[1]-p1[1])/(p2[0]-p1[0]) if p3[1]-p1[1]==m*(p3[0]-p1[0]): return 1 else: return 0 else: return 0 def pt_in(r,P): areaRectangle = 0.5*abs(\ # y_A y_C x_D x_B\ (r[0][1]-r[2][1])*(r[3][0]-r[1][0])\ # y_B y_D x_A x_C\ + (r[1][1]-r[3][1])*(r[0][0]-r[2][0])\ ) ABP = 0.5*(\ r[0][0]*(P[1]-r[1][1])\ +P[0]*(r[1][1]-r[0][1])\ +r[1][0]*(r[0][1]-P[1])\ ) BCP = 0.5*(\ r[2][0]*(P[1]-r[1][1])\ +P[0]*(r[1][1]-r[2][1])\ +r[1][0]*(r[2][1]-P[1])\ ) CDP = 0.5*(\ r[2][0]*(P[1]-r[3][1])\ +P[0]*(r[3][1]-r[2][1])\ +r[3][0]*(r[2][1]-P[1])\ ) DAP = 0.5*(\ r[0][0]*(P[1]-r[3][1])\ +P[0]*(r[3][1]-r[0][1])\ +r[3][0]*(r[0][1]-P[1])\ ) return areaRectangle == (abs(ABP)+abs(BCP)+abs(CDP)+abs(DAP)) def mid_in(r,b): x = b[1][0] y = b[0][1] P = (x,y) return pt_in(r,P) get_coords(sqa,sq1) get_coords(sqb,sq2) def check(): flag = 0 #check point on edge for j in range(4): if check_pt(sq2[0],sq2[1],sq1[j]) or check_pt(sq2[1],sq2[2],sq1[j]) or check_pt(sq2[2],sq2[3],sq1[j]) or check_pt(sq2[0],sq2[3],sq1[j]): #print(1) flag = 1 if check_pt(sq1[0],sq1[1],sq2[j]) or check_pt(sq1[1],sq1[2],sq2[j]) or check_pt(sq1[2],sq1[3],sq2[j]) or check_pt(sq1[0],sq1[3],sq2[j]): #print(2) flag = 1 if pt_in(sq1,sq2[j]) or pt_in(sq2,sq1[j]): #print(3) flag = 1 #check mid in square: if mid_in(sq1,sq2) or mid_in(sq2,sq1): #print(4) flag = 1 if flag == 1: print("YES") else: print("NO") check() ```
instruction
0
64,583
23
129,166
No
output
1
64,583
23
129,167
Provide a correct Python 3 solution for this coding contest problem. Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler can only get a rectangular land as his field. Thus, Karnaugh should get the largest rectangular land suitable for reclamation. The map of the wasteland is represented with a 5 x 5 grid as shown in the following figures, where '1' represents a place suitable for reclamation and '0' represents a sandy place. Your task is to find the largest rectangle consisting only of 1's in the map, and to report the size of the rectangle. The size of a rectangle is defined by the number of 1's in it. Note that there may be two or more largest rectangles of the same size. <image> Figure 1. The size of the largest rectangles is 4. There are two largest rectangles (shaded). <image> Figure 2. The size of the largest rectangle is 3. There is one largest rectangle (shaded). Input The input consists of maps preceded by an integer m indicating the number of input maps. m map1 map2 map3 ... mapm Two maps are separated by an empty line. Each mapk is in the following format: p p p p p p p p p p p p p p p p p p p p p p p p p Each p is a character either '1' or '0'. Two p's in the same line are separated by a space character. Here, the character '1' shows a place suitable for reclamation and '0' shows a sandy place. Each map contains at least one '1'. Output The size of the largest rectangle(s) for each input map should be shown each in a separate line. Example Input 3 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0 1 Output 4 3 8
instruction
0
64,759
23
129,518
"Correct Solution: ``` # AOJ 1114: Get a Rectangular Field # Python3 2018.7.8 bal4u s = [[0 for c in range(6)] for r in range(6)] for k in range(int(input())): if k > 0: input() for r in range(5): a = list(map(int, input().split())) for c in range(5): s[r+1][c+1] = s[r+1][c]+a[c] ans = 0; for r in range(1, 6): for c in range(1, 6): for c2 in range(5, c-1, -1): w2 = w = c2-c+1 if w2 > s[r][c2]-s[r][c-1]: continue ans = max(ans, w2) for r2 in range(r+1, 6): if w > s[r2][c2]-s[r2][c-1]: break w2 += w ans = max(ans, w2) print(ans) ```
output
1
64,759
23
129,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler can only get a rectangular land as his field. Thus, Karnaugh should get the largest rectangular land suitable for reclamation. The map of the wasteland is represented with a 5 x 5 grid as shown in the following figures, where '1' represents a place suitable for reclamation and '0' represents a sandy place. Your task is to find the largest rectangle consisting only of 1's in the map, and to report the size of the rectangle. The size of a rectangle is defined by the number of 1's in it. Note that there may be two or more largest rectangles of the same size. <image> Figure 1. The size of the largest rectangles is 4. There are two largest rectangles (shaded). <image> Figure 2. The size of the largest rectangle is 3. There is one largest rectangle (shaded). Input The input consists of maps preceded by an integer m indicating the number of input maps. m map1 map2 map3 ... mapm Two maps are separated by an empty line. Each mapk is in the following format: p p p p p p p p p p p p p p p p p p p p p p p p p Each p is a character either '1' or '0'. Two p's in the same line are separated by a space character. Here, the character '1' shows a place suitable for reclamation and '0' shows a sandy place. Each map contains at least one '1'. Output The size of the largest rectangle(s) for each input map should be shown each in a separate line. Example Input 3 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0 1 Output 4 3 8 Submitted Solution: ``` # AOJ 1114: Get a Rectangular Field # Python3 2018.7.8 bal4u a = [[] for i in range(5)] s = [[0 for c in range(5)] for r in range(5)] for k in range(int(input())): if k > 0: input() for r in range(5): a[r] = list(map(int, input().split())) s[r][0] = a[r][0] for c in range(1, 5): s[r][c] = s[r][c-1]+a[r][c] ans = 0; for r in range(5): for c in range(5): for c2 in range(4, c-1, -1): w2 = w = c2-c+1 if w2 > s[r][c2]-s[r][c-1]: continue ans = max(ans, w2) for r2 in range(r+1, 5): if w > s[r2][c2]-s[r2][c-1]: break w2 += w ans = max(ans, w2) print(ans) ```
instruction
0
64,760
23
129,520
No
output
1
64,760
23
129,521
Provide a correct Python 3 solution for this coding contest problem. Problem Statement One day, you found an old scroll with strange texts on it. You revealed that the text was actually an expression denoting the position of treasure. The expression consists of following three operations: * From two points, yield a line on which the points lie. * From a point and a line, yield a point that is symmetric to the given point with respect to the line. * From two lines, yield a point that is the intersection of the lines. The syntax of the expression is denoted by following BNF: <expression> ::= <point> <point> ::= <point-factor> | <line> "@" <line-factor> | <line> "@" <point-factor> | <point> "@" <line-factor> <point-factor> ::= "(" <number> "," <number> ")" | "(" <point> ")" <line> ::= <line-factor> | <point> "@" <point-factor> <line-factor> ::= "(" <line> ")" <number> ::= <zero-digit> | <positive-number> | <negative-number> <positive-number> ::= <nonzero-digit> | <positive-number> <digit> <negative-number> ::= "-" <positive-number> <digit> ::= <zero-digit> | <nonzero-digit> <zero-digit> ::= "0" <nonzero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" Each <point> or <point-factor> denotes a point, whereas each <line> or <line-factor> denotes a line. The former notion of <point-factor> $(X,Y)$ represents a point which has $X$ for $x$-coordinate and $Y$ for $y$-coordinate on the $2$-dimensional plane. "@" indicates the operations on two operands. Since each operation is distinguishable from others by its operands' types (i.e. a point or a line), all of these operations are denoted by the same character "@". Note that "@" is left-associative, as can be seen from the BNF. Your task is to determine where the treasure is placed. Input The input consists of multiple datasets. Each dataset is a single line which contains an expression denoting the position of treasure. It is guaranteed that each dataset satisfies the following conditions: * The length of the string never exceeds $10^2$. * If both operands of "@" are points, their distance is greater than $1$. * If both operands of "@" are lines, they are never parallel. * The absolute values of points' coordinates never exceed $10^2$ at any point of evaluation. You can also assume that there are at most $100$ datasets. The input ends with a line that contains only a single "#". Output For each dataset, print the $X$ and $Y$ coordinates of the point, denoted by the expression, in this order. The output will be considered correct if its absolute or relative error is at most $10^{-2}$. Sample Input ((0,0)@(1,1))@((4,1)@(2,5)) ((0,0)@(3,1))@((1,-3)@(2,-1)) (0,0)@(1,1)@(4,1) (0,0)@((1,1)@(4,1)) (((0,0)@((10,20)@(((30,40)))))) ((0,0)@(3,1))@((1,-3)@(2,-1))@(100,-100)@(100,100) Output for the Sample Input 3.00000000 3.00000000 3.00000000 1.00000000 1.00000000 4.00000000 0.00000000 2.00000000 -10.00000000 10.00000000 -99.83681795 -91.92248853 Example Input ((0,0)@(1,1))@((4,1)@(2,5)) ((0,0)@(3,1))@((1,-3)@(2,-1)) (0,0)@(1,1)@(4,1) (0,0)@((1,1)@(4,1)) (((0,0)@((10,20)@(((30,40)))))) ((0,0)@(3,1))@((1,-3)@(2,-1))@(100,-100)@(100,100) # Output 3.00000000 3.00000000 3.00000000 1.00000000 1.00000000 4.00000000 0.00000000 2.00000000 -10.00000000 10.00000000 -99.83681795 -91.92248853
instruction
0
64,787
23
129,574
"Correct Solution: ``` digits = "-0123456789" def cross_point(P, Q): x0, y0, x1, y1 = P x2, y2, x3, y3 = Q dx0 = x1 - x0; dy0 = y1 - y0 dx1 = x3 - x2; dy1 = y3 - y2 s = (y0-y2)*dx1 - (x0-x2)*dy1 sm = dx0*dy1 - dy0*dx1 if s < 0: s = -s sm = -sm if s == 0: x = x0 y = y0 else: x = x0 + s*dx0/sm y = y0 + s*dy0/sm return x, y def reflection(line, point): x0, y0, x1, y1 = line p, q = point x1 -= x0; y1 -= y0 p -= x0; q -= y0 cv = p*x1 + q*y1 sv = p*y1 - q*x1 cv2 = cv**2 - sv**2 sv2 = 2*cv*sv dd = (p**2 + q**2)*(x1**2 + y1**2) if dd == 0: return x0 + p, y0 + q return x0 + (cv2 * p - sv2 * q) / dd, y0 + (sv2 * p + cv2 * q) / dd def parse(S): S = S + "$" cur = 0 def expr(): nonlocal cur res = None while S[cur] == '(': cur += 1 # '(' if S[cur] in digits: x = number() cur += 1 # ',' y = number() r = (0, x, y) else: r = expr() cur += 1 # ')' if res is None: res = r else: if res[0] == r[0] == 0: # (point)@(point) res = (1, res[1], res[2], r[1], r[2]) elif res[0] == r[0] == 1: # (line)@(line) x, y = cross_point(res[1:], r[1:]) res = (0, x, y) else: # (line)@(point) or (point)@(line) point, line = (res, r) if r[0] else (r, res) x, y = reflection(line[1:], point[1:]) res = (0, x, y) if S[cur] != '@': break cur += 1 # '@' return res def number(): nonlocal cur v = 0; mns = 0 if S[cur] == '-': mns = 1 cur += 1 # '-' while S[cur] in digits: v = 10*v + int(S[cur]) cur += 1 return -v if mns else v return expr() def solve(): s = input() if s == '#': return False res = parse(s) print("%.16f %.16f" % res[1:]) return True while solve(): ... ```
output
1
64,787
23
129,575
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja has an n Γ— m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h Γ— w, then the component must contain exactly hw cells. A connected component of the same values is a set of cells of the table that meet the following conditions: * every two cells of the set have the same value; * the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table); * it is impossible to add any cell to the set unless we violate the two previous conditions. Can Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case? Input The first line contains integers n, m and k (1 ≀ n, m ≀ 100; 1 ≀ k ≀ 10). Next n lines describe the table a: the i-th of them contains m integers ai1, ai2, ..., aim (0 ≀ ai, j ≀ 1) β€” the values in the cells of the i-th row. Output Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed. Examples Input 5 5 2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Output 1 Input 3 4 1 1 0 0 0 0 1 1 1 1 1 1 0 Output -1 Input 3 4 1 1 0 0 1 0 1 1 0 1 0 0 1 Output 0
instruction
0
65,173
23
130,346
Tags: bitmasks, greedy Correct Solution: ``` from functools import * read_line = lambda: [int(i) for i in input().split()] n, m, k = read_line() a = [read_line() for i in range(n)] if n < m: n, m, a = m, n, zip(*a) xs = [reduce(lambda x, b: 2 * x + b, y) for y in a] minm = lambda a: min(a, m - a) work = lambda y: sum(minm(bin(x ^ y).count('1')) for x in xs) ans = min(map(work, xs if m > k else range(1<<m))) print(ans if ans <= k else -1) # Made By Mostafa_Khaled ```
output
1
65,173
23
130,347
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja has an n Γ— m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h Γ— w, then the component must contain exactly hw cells. A connected component of the same values is a set of cells of the table that meet the following conditions: * every two cells of the set have the same value; * the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table); * it is impossible to add any cell to the set unless we violate the two previous conditions. Can Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case? Input The first line contains integers n, m and k (1 ≀ n, m ≀ 100; 1 ≀ k ≀ 10). Next n lines describe the table a: the i-th of them contains m integers ai1, ai2, ..., aim (0 ≀ ai, j ≀ 1) β€” the values in the cells of the i-th row. Output Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed. Examples Input 5 5 2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Output 1 Input 3 4 1 1 0 0 0 0 1 1 1 1 1 1 0 Output -1 Input 3 4 1 1 0 0 1 0 1 1 0 1 0 0 1 Output 0
instruction
0
65,174
23
130,348
Tags: bitmasks, greedy Correct Solution: ``` from functools import * read_line = lambda: [int(i) for i in input().split()] n, m, k = read_line() a = [read_line() for i in range(n)] if n < m: n, m, a = m, n, zip(*a) xs = [reduce(lambda x, b: 2 * x + b, y) for y in a] minm = lambda a: min(a, m - a) work = lambda y: sum(minm(bin(x ^ y).count('1')) for x in xs) ans = min(map(work, xs if m > k else range(1<<m))) print(ans if ans <= k else -1) ```
output
1
65,174
23
130,349
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja has an n Γ— m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h Γ— w, then the component must contain exactly hw cells. A connected component of the same values is a set of cells of the table that meet the following conditions: * every two cells of the set have the same value; * the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table); * it is impossible to add any cell to the set unless we violate the two previous conditions. Can Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case? Input The first line contains integers n, m and k (1 ≀ n, m ≀ 100; 1 ≀ k ≀ 10). Next n lines describe the table a: the i-th of them contains m integers ai1, ai2, ..., aim (0 ≀ ai, j ≀ 1) β€” the values in the cells of the i-th row. Output Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed. Examples Input 5 5 2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Output 1 Input 3 4 1 1 0 0 0 0 1 1 1 1 1 1 0 Output -1 Input 3 4 1 1 0 0 1 0 1 1 0 1 0 0 1 Output 0
instruction
0
65,175
23
130,350
Tags: bitmasks, greedy Correct Solution: ``` read_line = lambda: [int(i) for i in input().split()] n, m, k = read_line() a = [read_line() for i in range(n)] if n < m: n, m, a = m, n, zip(*a) xs = [] for y in a: x = 0 for b in y: x = 2 * x + b xs.append(x) def work(y): tot = 0 for x in xs: c = bin(x ^ y).count('1') tot += min(c, m - c) return tot ans = min(map(work, xs if m > k else range(1<<m))) print(ans if ans <= k else -1) ```
output
1
65,175
23
130,351
Provide tags and a correct Python 3 solution for this coding contest problem. On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city. The city is an n Γ— m rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are denoted by character '.', occupied squares are denoted by character '#'. The pipe must meet the following criteria: * the pipe is a polyline of width 1, * the pipe goes in empty squares, * the pipe starts from the edge of the field, but not from a corner square, * the pipe ends at the edge of the field but not in a corner square, * the pipe has at most 2 turns (90 degrees), * the border squares of the field must share exactly two squares with the pipe, * if the pipe looks like a single segment, then the end points of the pipe must lie on distinct edges of the field, * for each non-border square of the pipe there are exacly two side-adjacent squares that also belong to the pipe, * for each border square of the pipe there is exactly one side-adjacent cell that also belongs to the pipe. Here are some samples of allowed piping routes: ....# ....# .*..# ***** ****. .***. ..#.. ..#*. ..#*. #...# #..*# #..*# ..... ...*. ...*. Here are some samples of forbidden piping routes: .**.# *...# .*.*# ..... ****. .*.*. ..#.. ..#*. .*#*. #...# #..*# #*.*# ..... ...*. .***. In these samples the pipes are represented by characters ' * '. You were asked to write a program that calculates the number of distinct ways to make exactly one pipe in the city. The two ways to make a pipe are considered distinct if they are distinct in at least one square. Input The first line of the input contains two integers n, m (2 ≀ n, m ≀ 2000) β€” the height and width of Berland map. Each of the next n lines contains m characters β€” the map of the city. If the square of the map is marked by character '.', then the square is empty and the pipe can through it. If the square of the map is marked by character '#', then the square is full and the pipe can't through it. Output In the first line of the output print a single integer β€” the number of distinct ways to create a pipe. Examples Input 3 3 ... ..# ... Output 3 Input 4 2 .. .. .. .. Output 2 Input 4 5 #...# #...# ###.# ###.# Output 4 Note In the first sample there are 3 ways to make a pipe (the squares of the pipe are marked by characters ' * '): .*. .*. ... .*# **# **# .*. ... .*.
instruction
0
65,189
23
130,378
Tags: binary search, brute force, combinatorics, dp, implementation Correct Solution: ``` n, m = [int(x) for x in input().split()] a = [[int(c == '.') for c in input()] for i in range(n)] def rotate(a): n = len(a) m = len(a[0]) b = [[0] * n for i in range(m)] for i in range(n): for j in range(m): b[j][n - 1 - i] = a[i][j] return b def calc(a): n = len(a) m = len(a[0]) alive = a[0][:] alive[0], alive[m - 1] = 0, 0 ans_l, ans_r, ans_u = 0, 0, 0 ans_bs = [0] * m for i in range(1, n - 1): s = 0 for j in range(1, m - 1): if a[i][j]: if alive[j]: ans_u += s - alive[j - 1] ans_bs[j] += s s += alive[j] else: s = 0 ans_bs[j] = 0 alive[j] = 0 if a[i][m - 1]: ans_r += s s = 0 for j in range(m - 2, 0, -1): if a[i][j]: if alive[j]: ans_u += s - alive[j + 1] ans_bs[j] += s s += alive[j] else: s = 0 ans_bs[j] = 0 alive[j] = 0 if a[i][0]: ans_l += s ans_u //= 2 ans_b = sum(a[n - 1][i] * (ans_bs[i] + alive[i]) for i in range(1, m - 1)) return ans_l, ans_r, ans_u, ans_b ans = 0 ans_l, ans_r, ans_u, ans_b = calc(a) ans += ans_l + ans_r + ans_u + ans_b a = rotate(a) ans_l, _, ans_u, ans_b = calc(a) ans += ans_l + ans_u + ans_b a = rotate(a) ans_l, _, ans_u, _= calc(a) ans += ans_l + ans_u a = rotate(a) _, _, ans_u, _= calc(a) ans += ans_u print(ans) ```
output
1
65,189
23
130,379
Provide tags and a correct Python 3 solution for this coding contest problem. On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle <image> (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value <image> should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. Input First and only line contains two space-separated integers n and a (3 ≀ n ≀ 105, 1 ≀ a ≀ 180) β€” the number of vertices in the polygon and the needed angle, in degrees. Output Print three space-separated integers: the vertices v1, v2, v3, which form <image>. If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order. Examples Input 3 15 Output 1 2 3 Input 4 67 Output 2 1 3 Input 4 68 Output 4 1 2 Note In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
instruction
0
65,341
23
130,682
Tags: constructive algorithms, geometry, math Correct Solution: ``` n,a=map(int,input().split()) s=180*(n-2) c=s/n k=(180-c)/2 ugl=[] for i in range(1,n-1): ugl.append(k*i) mi=abs(ugl[0]-a) v=3 for i in range(len(ugl)): if abs(ugl[i]-a)<mi: mi=abs(ugl[i]-a) v=i+3 print('2 1',v) ```
output
1
65,341
23
130,683
Provide tags and a correct Python 3 solution for this coding contest problem. On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle <image> (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value <image> should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. Input First and only line contains two space-separated integers n and a (3 ≀ n ≀ 105, 1 ≀ a ≀ 180) β€” the number of vertices in the polygon and the needed angle, in degrees. Output Print three space-separated integers: the vertices v1, v2, v3, which form <image>. If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order. Examples Input 3 15 Output 1 2 3 Input 4 67 Output 2 1 3 Input 4 68 Output 4 1 2 Note In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
instruction
0
65,342
23
130,684
Tags: constructive algorithms, geometry, math Correct Solution: ``` n, a = input().split() n = int(n) a = int(a) u = -1 m = 10000 for i in range(1, n-1): if abs(180/n*i-a) < m: m=abs(180/n*i-a) u = i print(1+u, u+2, 1) ```
output
1
65,342
23
130,685
Provide tags and a correct Python 3 solution for this coding contest problem. On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle <image> (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value <image> should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. Input First and only line contains two space-separated integers n and a (3 ≀ n ≀ 105, 1 ≀ a ≀ 180) β€” the number of vertices in the polygon and the needed angle, in degrees. Output Print three space-separated integers: the vertices v1, v2, v3, which form <image>. If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order. Examples Input 3 15 Output 1 2 3 Input 4 67 Output 2 1 3 Input 4 68 Output 4 1 2 Note In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
instruction
0
65,343
23
130,686
Tags: constructive algorithms, geometry, math Correct Solution: ``` #!/usr/bin/env python3 import sys def main(): n, a = map(int, sys.stdin.readline().split()) sum_angles = 180 * (n - 2) if a >= sum_angles / n: print("2 1 {}".format(n)) return div = (n - 2) * n lo = 1 hi = n - 1 while lo + 1 < hi: mid = (lo + hi) // 2 angle = sum_angles * mid / div if angle <= a: lo = mid else: hi = mid #print("vals", lo, hi, file=sys.stderr) if (hi + lo) * sum_angles / div - 2 * a > 0: print("2 1 {}".format(lo + 2)) else: print("2 1 {}".format(hi + 2)) if __name__ == '__main__': main() ```
output
1
65,343
23
130,687
Provide tags and a correct Python 3 solution for this coding contest problem. On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle <image> (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value <image> should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. Input First and only line contains two space-separated integers n and a (3 ≀ n ≀ 105, 1 ≀ a ≀ 180) β€” the number of vertices in the polygon and the needed angle, in degrees. Output Print three space-separated integers: the vertices v1, v2, v3, which form <image>. If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order. Examples Input 3 15 Output 1 2 3 Input 4 67 Output 2 1 3 Input 4 68 Output 4 1 2 Note In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
instruction
0
65,344
23
130,688
Tags: constructive algorithms, geometry, math Correct Solution: ``` s,a=map(int,input().split()) print(2,1,min(2+max(1,(a*s+90)//180),s)) # Made By Mostafa_Khaled ```
output
1
65,344
23
130,689
Provide tags and a correct Python 3 solution for this coding contest problem. On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle <image> (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value <image> should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. Input First and only line contains two space-separated integers n and a (3 ≀ n ≀ 105, 1 ≀ a ≀ 180) β€” the number of vertices in the polygon and the needed angle, in degrees. Output Print three space-separated integers: the vertices v1, v2, v3, which form <image>. If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order. Examples Input 3 15 Output 1 2 3 Input 4 67 Output 2 1 3 Input 4 68 Output 4 1 2 Note In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
instruction
0
65,345
23
130,690
Tags: constructive algorithms, geometry, math Correct Solution: ``` # _ ##################################################################################################################### def main(): return bestAngle_sVertices(*map(int, input().split())) def bestAngle_sVertices(nVertices, angle): angle *= nVertices if angle < 180: return '2 1 3' angle /= 180 angle += 2 if angle > nVertices: return f'2 1 {nVertices}' return f'2 1 {round(angle)}' if __name__ == '__main__': print(main()) ```
output
1
65,345
23
130,691