message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
276
109k
cluster
float64
23
23
__index_level_0__
int64
552
217k
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above.
instruction
0
106,467
23
212,934
Tags: geometry Correct Solution: ``` mas = list(map(int, input().split())) w = mas[0] h = mas[1] alf = mas[2] import math sina = abs(math.sin(alf/180*math.pi)) cosa = abs(math.cos(alf/180*math.pi)) sinb = h / ((w ** 2 + h ** 2) ** 0.5) cosb = w / ((w ** 2 + h ** 2) ** 0.5) sin2b = 2 * sinb * cosb #print(w,h,alf) if (sin2b >= sina): #print(sina, cosa) diskr = (cosa + 1) ** 2 - sina ** 2 disc = w * (cosa + 1) - h * (sina) disf = h * (cosa + 1) - w * (sina) c = disc / diskr f = disf / diskr res = w * h - (c ** 2 + f ** 2) * sina * cosa elif(alf == 90): res = min(w, h) ** 2 else: res = min((h ** 2) / sina, (w ** 2) / sina) print(res) ```
output
1
106,467
23
212,935
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` from math import cos, pi, sin, atan W, H, b = map(float, input().split()) a = (b/180)*pi if (W < H): X = W W = H H = X if (a > 0.5*pi): a = 0.5*pi - (a - 0.5*pi) opp = W*H if (a == 0): eindopp = W*H else: if a > (atan(H/W)*2): Schuin = H/sin(a) eindopp = Schuin*H else: y = -2*cos(a)-cos(a)**2-1+sin(a)**2 hks = (W*sin(a)-H*cos(a)-H)/y hgs = (H-hks-hks*cos(a))/sin(a) eindopp = opp - hks*sin(a)*hks*cos(a) - hgs*sin(a)*hgs*cos(a) print(round(eindopp,9)) ```
instruction
0
106,468
23
212,936
Yes
output
1
106,468
23
212,937
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` from math import sin,cos,tan,pi [w,h,a] =[int(i) for i in input().split()] if h > w: h,w = w,h if a > 90: a = 180 - a if a==0: print(w*h) else: b = (a*pi)/180 w = w/2.0 h = h/2.0 if tan(b/2) >= h/w: print (4*h*h/sin(b)) else: ans = 4*w*h m = -1 / tan(b) c = w*sin(b) + w*cos(b) / tan(b) ans = ans - (h - m*w - c)*(w - (h - c)/m) m = tan(b) c = h*cos(b) + h*sin(b)*tan(b) ans = ans - (h + m*w - c)*((h - c)/m + w) print (ans) ```
instruction
0
106,469
23
212,938
Yes
output
1
106,469
23
212,939
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` from math import * from sys import stdin, stdout io = stdin.readline().split() w = float(io[0]) h = float(io[1]) a = float(io[2]) if (a > 90): a = 180 - a if (a == 0) : print(w * h) elif (a == 90) : print(min(w, h) ** 2) else : a = a * pi / 180.0 if (w < h) : w, h = h, w corner_x = cos(a) * (w / 2.0) + sin(a) * (h / 2.0) if (corner_x >= w / 2 ) : x0 = w / 2.0 + (h / 2.0 - (h / 2.0) / cos(a)) * (cos(a) / sin(a)) y0 = h / 2.0 - (tan(a) * (- w / 2.0) + (h / 2.0) / cos(a)) x1 = w / 2.0 - (h / 2.0 - (w / 2.0) / sin(a)) * (-tan(a)) y1 = h / 2.0 - ((-cos(a) / sin(a)) * (w / 2.0) + (w / 2.0) / sin(a)) print(w * h - x1 * y1 - x0 * y0) else : y = tan(a) * (w / 2.0) - (h / 2.0) / cos(a) + h / 2.0 y0 = y - h x0 = y * tan(pi / 2.0 - a) print(w * h - (y0 * tan(pi / 2.0 - a) + x0) * h) ```
instruction
0
106,470
23
212,940
Yes
output
1
106,470
23
212,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` import math w, h, a = map(int, input().strip().split()) if h > w: w, h = h, w if a > 90: a = 90 - (a - 90) a = math.radians(a) if a < 2 * math.atan2(h, w): area = w * h s = (w / 2) - (h / 2 * math.tan(a / 2)) bigger_area = 0.5 * s * s * math.tan(a) s = (h / 2) - (w / 2 * math.tan(a / 2)) lower_area = 0.5 * s * s * math.tan(a) print(area - 2 * bigger_area - 2 * lower_area) else: print(h * h / math.sin(a)) ```
instruction
0
106,471
23
212,942
Yes
output
1
106,471
23
212,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` mas = list(map(int, input().split())) w = mas[0] h = mas[1] alf = mas[2] import math sina = abs(math.sin(alf/180*math.pi)) cosa = abs(math.cos(alf/180*math.pi)) sinb = h / ((w ** 2 + h ** 2) ** 0.5) cosb = w / ((w ** 2 + h ** 2) ** 0.5) sin2b = 2 * sinb * cosb print(w,h,alf) if (sin2b >= sina): print(sina, cosa) diskr = (cosa + 1) ** 2 - sina ** 2 disc = w * (cosa + 1) - h * (sina) disf = h * (cosa + 1) - w * (sina) c = disc / diskr f = disf / diskr res = w * h - (c ** 2 + f ** 2) * sina * cosa elif(alf == 90): res = min(w, h) ** 2 else: res = min((h ** 2) / sina, (w ** 2) / sina) print(res) ```
instruction
0
106,472
23
212,944
No
output
1
106,472
23
212,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` from math import cos,sin,pi,tan,atan w,h,a=map(float,input().split()) if a==90: print(w*w) else: a=a*pi/180 print ((w * h - (w * w + h * h) * tan(a / 2) / 2) / cos(a) if a < atan(h / w) * 2 else h * h / sin(a)) ```
instruction
0
106,473
23
212,946
No
output
1
106,473
23
212,947
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` import math w, h, a = map(int, input().strip().split()) # if h > w: # w, h = h, w # # if a > 90: # a = 90 - (a - 90) a = math.radians(a) if a < 2 * math.atan2(h, w): area = w * h s = (w / 2) - (h / 2 * math.tan(a / 2)) bigger_area = 0.5 * s * s * math.tan(a) s = (h / 2) - (w / 2 * math.tan(a / 2)) lower_area = 0.5 * s * s * math.tan(a) print(area - 2 * bigger_area - 2 * lower_area) else: print(h * h / math.sin(a)) ```
instruction
0
106,474
23
212,948
No
output
1
106,474
23
212,949
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. <image> Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture. Input The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees. Output In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. Examples Input 1 1 45 Output 0.828427125 Input 6 4 30 Output 19.668384925 Note The second sample has been drawn on the picture above. Submitted Solution: ``` #!/usr/bin/python3 from math import * w,h,alpha = [int(x) for x in input().strip().split()] if alpha == 0: print(w*h) exit(0) if alpha > 90 : alpha = 180-alpha if w < h: w,h = h,w c = 1+cos(alpha*pi/180.0) s = sin(alpha*pi/180.0) x = (w/s - h/c)/(c/s - s/c) y = (w/c - h/s)/(s/c - c/s) print(h*h/s) if tan(alpha/2) > h/w else print(w*h - x*x*(c-1)*s - y*y*(c-1)*(s)) ```
instruction
0
106,475
23
212,950
No
output
1
106,475
23
212,951
Provide a correct Python 3 solution for this coding contest problem. Example Input 3 0 2 7 2 0 4 5 8 0 Output 11
instruction
0
106,976
23
213,952
"Correct Solution: ``` import sys def main(): n = int(input()) edges = [] for i in range(n): edges.append( list(map(int, sys.stdin.readline().split())) ) # ?±?????????????????????????????????°?????? # ????????????????????°?????????????????????????????????????????¨???????????? # ??????????????????????????¨????¨?????????????????????§????´?????°???????????????????????????°?????? ans = 0 for i in range(n - 1): for j in range(i + 1, n): ans += min(edges[i][j], edges[j][i]) print(ans) if __name__ == '__main__': main() ```
output
1
106,976
23
213,953
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,047
23
214,094
Tags: brute force, geometry, math Correct Solution: ``` lati = sorted([int(x) for x in input().split()]) if (lati[0]+lati[1] > lati[2]): print("0") else: print(lati[2]-lati[1]-lati[0]+1) ```
output
1
107,047
23
214,095
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,048
23
214,096
Tags: brute force, geometry, math Correct Solution: ``` a=list(map(int,input().split())) a.sort() x=a[0] y=a[1] z=a[2]+1 ans=max(0,z-x-y) print(ans) ```
output
1
107,048
23
214,097
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,050
23
214,100
Tags: brute force, geometry, math Correct Solution: ``` ai = list(map(int,input().split())) ai.sort() print(max(0,ai[2] - ai[1] - ai[0] + 1)) ```
output
1
107,050
23
214,101
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,051
23
214,102
Tags: brute force, geometry, math Correct Solution: ``` a,b,c = map(int,input().split()) l = [a,b,c] a1 = [] k = 0 max1 = max(l) if a == b == c: print(0) exit() for i in l: if i == max1 and k == 0: k = 1 pass else: a1.append(i) if sum(a1) > max1: print(0) exit() if max1 - sum(a1) >= 0: print((max1 - sum(a1))+1) else: print(0) ```
output
1
107,051
23
214,103
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,052
23
214,104
Tags: brute force, geometry, math Correct Solution: ``` sides = list(map(int, input().split())) sides.sort() print("0" if sides[2] < sides[1] + sides[0] else str(sides[2] - sides[1] - sides[0] + 1)) ```
output
1
107,052
23
214,105
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,053
23
214,106
Tags: brute force, geometry, math Correct Solution: ``` string = input() arr = string.split() fir = int(arr[0]) sec = int(arr[1]) thir = int(arr[2]) res = 1 f_summ = sec + fir + thir if fir + sec > thir: res = res else: fir += (thir - fir - sec + 1) if fir + thir > sec: res = res else: fir += (sec - fir - thir + 1) if sec + thir > fir: res = res else: sec += (fir - thir - sec + 1) summ = sec + fir + thir print(summ - f_summ) ```
output
1
107,053
23
214,107
Provide tags and a correct Python 3 solution for this coding contest problem. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
instruction
0
107,054
23
214,108
Tags: brute force, geometry, math Correct Solution: ``` a=[] a=list(map(int,input().split())) a.sort() if a[0]+a[1]>a[2]: print("0") elif a[0]+a[1]==a[2]: print("1") else: print(a[2]-a[1]-a[0]+1) ```
output
1
107,054
23
214,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` s=input() s=s.split() a=int(s[0]) b=int(s[1]) c=int(s[2]) if(a+b>c and a+c>b and b+c>a): print("0") exit(0) ct=[] if(a+b<=c): x=(c+1)-(a+b) ct.append(x) if(a+c<=b): x=(b+1)-(a+c) ct.append(x) if(b+c<=a): x=(a+1)-(c+b) ct.append(x) print(min(ct)) ```
instruction
0
107,055
23
214,110
Yes
output
1
107,055
23
214,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` l=list(map(int, input().split())) l.sort() v=l[0]+l[1] res=(l[2]-v) if res>=0: print(res+1) else: print('0') ```
instruction
0
107,056
23
214,112
Yes
output
1
107,056
23
214,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` from math import fabs arr=list(map(int,input().split())) arr.sort() if arr[2]>=arr[1]+arr[0]: print(int((fabs(arr[2]-(arr[0]+arr[1]))+1))) else: print(0) ```
instruction
0
107,057
23
214,114
Yes
output
1
107,057
23
214,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` '''input 10 10 100 ''' from sys import stdin, stdout arr = list(map(int, stdin.readline().split())) arr.sort() SUM = arr[0] + arr[1] if SUM > arr[2]: print(0) else: print(arr[2] - SUM + 1) ```
instruction
0
107,058
23
214,116
Yes
output
1
107,058
23
214,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` a, b, c = list(map(int, input().split())) x = min(a,b) y = min(b,c) if (x + y > max(a,b,c)): print(0) else: print(max(a,b,c) - (x+y) + 1) ```
instruction
0
107,059
23
214,118
No
output
1
107,059
23
214,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` def checktriangle(a,b,c): if a+b > c and b+c > a and a+c > b: return True else: return False inp=input("input:") splt=inp.split() a=int(splt[0]) b=int(splt[1]) c=int(splt[2]) step=0 while not checktriangle(a,b,c): step +=1 if min(a,b,c)==a: a+=1 elif min(a,b,c)==b: b+=1 elif min(a,b,c)==c: c+=1 print(step) ```
instruction
0
107,060
23
214,120
No
output
1
107,060
23
214,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` if __name__ == '__main__': a,b,c = [int(i) for i in input().split(' ')] #print(a,b,c) if a >= b + c: print( max(0, a - (b+c -1))) elif b >= a + c: print( max(0, b - (a+c-1))) elif c >= a + b: print( max(0, c - (a+b-1))) print(0) ```
instruction
0
107,061
23
214,122
No
output
1
107,061
23
214,123
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices. Input The only line contains tree integers a, b and c (1 ≤ a, b, c ≤ 100) — the lengths of sticks Masha possesses. Output Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks. Examples Input 3 4 5 Output 0 Input 2 5 3 Output 1 Input 100 10 10 Output 81 Note In the first example, Masha can make a triangle from the sticks without increasing the length of any of them. In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters. In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster. Submitted Solution: ``` a = list(map(int,input().split())) a.sort() if (a[2]-a[0]-a[1])>0: print(a[2]-a[0]-a[1]+1) else: print(0) ```
instruction
0
107,062
23
214,124
No
output
1
107,062
23
214,125
Provide tags and a correct Python 3 solution for this coding contest problem. One drew a closed polyline on a plane, that consisted only of vertical and horizontal segments (parallel to the coordinate axes). The segments alternated between horizontal and vertical ones (a horizontal segment was always followed by a vertical one, and vice versa). The polyline did not contain strict self-intersections, which means that in case any two segments shared a common point, that point was an endpoint for both of them (please consult the examples in the notes section). Unfortunately, the polyline was erased, and you only know the lengths of the horizonal and vertical segments. Please construct any polyline matching the description with such segments, or determine that it does not exist. Input The first line contains one integer t (1 ≤ t ≤ 200) —the number of test cases. The first line of each test case contains one integer h (1 ≤ h ≤ 1000) — the number of horizontal segments. The following line contains h integers l_1, l_2, ..., l_h (1 ≤ l_i ≤ 1000) — lengths of the horizontal segments of the polyline, in arbitrary order. The following line contains an integer v (1 ≤ v ≤ 1000) — the number of vertical segments, which is followed by a line containing v integers p_1, p_2, ..., p_v (1 ≤ p_i ≤ 1000) — lengths of the vertical segments of the polyline, in arbitrary order. Test cases are separated by a blank line, and the sum of values h + v over all test cases does not exceed 1000. Output For each test case output Yes, if there exists at least one polyline satisfying the requirements, or No otherwise. If it does exist, in the following n lines print the coordinates of the polyline vertices, in order of the polyline traversal: the i-th line should contain two integers x_i and y_i — coordinates of the i-th vertex. Note that, each polyline segment must be either horizontal or vertical, and the segments should alternate between horizontal and vertical. The coordinates should not exceed 10^9 by their absolute value. Examples Input 2 2 1 1 2 1 1 2 1 2 2 3 3 Output Yes 1 0 1 1 0 1 0 0 No Input 2 4 1 1 1 1 4 1 1 1 1 3 2 1 1 3 2 1 1 Output Yes 1 0 1 1 2 1 2 2 1 2 1 1 0 1 0 0 Yes 0 -2 2 -2 2 -1 1 -1 1 0 0 0 Input 2 4 1 4 1 2 4 3 4 5 12 4 1 2 3 6 2 1 3 Output Yes 2 0 2 3 3 3 3 7 4 7 4 12 0 12 0 0 No Note In the first test case of the first example, the answer is Yes — for example, the following picture illustrates a square that satisfies the requirements: <image> In the first test case of the second example, the desired polyline also exists. Note that, the polyline contains self-intersections, but only in the endpoints: <image> In the second test case of the second example, the desired polyline could be like the one below: <image> Note that the following polyline is not a valid one, since it contains self-intersections that are not endpoints for some of the segments: <image>
instruction
0
107,233
23
214,466
Tags: constructive algorithms, dp, geometry Correct Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): t = int(input()) for _ in range(t): if _ != 0: input() h = int(input()) l1 = list(map(int,input().split())) v = int(input()) l2 = list(map(int,input().split())) hKnap = [1] vKnap = [1] if h != v or sum(l1) % 2 != 0 or sum(l2) % 2 != 0: print("No") continue for elem in l1: hKnap.append((hKnap[-1] << elem) | hKnap[-1]) for elem in l2: vKnap.append((vKnap[-1] << elem) | vKnap[-1]) hSet = [] hSet2 = [] vSet = [] vSet2 = [] if hKnap[-1] & 1 << (sum(l1) // 2): curSum = sum(l1) // 2 for i in range(h - 1, -1, -1): if curSum >= l1[i] and hKnap[i] & (1 << (curSum - l1[i])): curSum -= l1[i] hSet.append(l1[i]) else: hSet2.append(l1[i]) if vKnap[-1] & 1 << (sum(l2) // 2): curSum = sum(l2) // 2 for i in range(v - 1, -1, -1): if curSum >= l2[i] and vKnap[i] & (1 << (curSum - l2[i])): curSum -= l2[i] vSet.append(l2[i]) else: vSet2.append(l2[i]) if not hSet or not vSet: print("No") else: print("Yes") if len(hSet) < len(hSet2): hTupleS = tuple(sorted(hSet)) hTupleL = tuple(sorted(hSet2)) else: hTupleS = tuple(sorted(hSet2)) hTupleL = tuple(sorted(hSet)) if len(vSet) < len(vSet2): vTupleS = tuple(sorted(vSet)) vTupleL = tuple(sorted(vSet2)) else: vTupleS = tuple(sorted(vSet2)) vTupleL = tuple(sorted(vSet)) currentLoc = [0,0] isHS = True isHL = False isVS = False isVL = True hIndex = len(hTupleS)-1 vIndex = 0 for i in range(h): if isHS: currentLoc[0] += hTupleS[hIndex] hIndex -= 1 if hIndex < 0: hIndex = len(hTupleL) - 1 isHS = False isHL = True elif isHL: currentLoc[0] -= hTupleL[hIndex] hIndex -= 1 print(str(currentLoc[0]) + " " + str(currentLoc[1])) if isVL: currentLoc[1] += vTupleL[vIndex] vIndex += 1 if vIndex >= len(vTupleL): vIndex = 0 isVL = False isVH = True elif isHL: currentLoc[1] -= vTupleS[vIndex] vIndex += 1 print(str(currentLoc[0]) + " " + str(currentLoc[1])) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
107,233
23
214,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One drew a closed polyline on a plane, that consisted only of vertical and horizontal segments (parallel to the coordinate axes). The segments alternated between horizontal and vertical ones (a horizontal segment was always followed by a vertical one, and vice versa). The polyline did not contain strict self-intersections, which means that in case any two segments shared a common point, that point was an endpoint for both of them (please consult the examples in the notes section). Unfortunately, the polyline was erased, and you only know the lengths of the horizonal and vertical segments. Please construct any polyline matching the description with such segments, or determine that it does not exist. Input The first line contains one integer t (1 ≤ t ≤ 200) —the number of test cases. The first line of each test case contains one integer h (1 ≤ h ≤ 1000) — the number of horizontal segments. The following line contains h integers l_1, l_2, ..., l_h (1 ≤ l_i ≤ 1000) — lengths of the horizontal segments of the polyline, in arbitrary order. The following line contains an integer v (1 ≤ v ≤ 1000) — the number of vertical segments, which is followed by a line containing v integers p_1, p_2, ..., p_v (1 ≤ p_i ≤ 1000) — lengths of the vertical segments of the polyline, in arbitrary order. Test cases are separated by a blank line, and the sum of values h + v over all test cases does not exceed 1000. Output For each test case output Yes, if there exists at least one polyline satisfying the requirements, or No otherwise. If it does exist, in the following n lines print the coordinates of the polyline vertices, in order of the polyline traversal: the i-th line should contain two integers x_i and y_i — coordinates of the i-th vertex. Note that, each polyline segment must be either horizontal or vertical, and the segments should alternate between horizontal and vertical. The coordinates should not exceed 10^9 by their absolute value. Examples Input 2 2 1 1 2 1 1 2 1 2 2 3 3 Output Yes 1 0 1 1 0 1 0 0 No Input 2 4 1 1 1 1 4 1 1 1 1 3 2 1 1 3 2 1 1 Output Yes 1 0 1 1 2 1 2 2 1 2 1 1 0 1 0 0 Yes 0 -2 2 -2 2 -1 1 -1 1 0 0 0 Input 2 4 1 4 1 2 4 3 4 5 12 4 1 2 3 6 2 1 3 Output Yes 2 0 2 3 3 3 3 7 4 7 4 12 0 12 0 0 No Note In the first test case of the first example, the answer is Yes — for example, the following picture illustrates a square that satisfies the requirements: <image> In the first test case of the second example, the desired polyline also exists. Note that, the polyline contains self-intersections, but only in the endpoints: <image> In the second test case of the second example, the desired polyline could be like the one below: <image> Note that the following polyline is not a valid one, since it contains self-intersections that are not endpoints for some of the segments: <image> Submitted Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): t = int(input()) for _ in range(t): if _ != 0: input() h = int(input()) l1 = list(map(int,input().split())) v = int(input()) l2 = list(map(int,input().split())) hKnap = [1] vKnap = [1] if h != v or sum(l1) % 2 != 0 or sum(l2) % 2 != 0: print("No") continue for elem in l1: hKnap.append((hKnap[-1] << elem) | hKnap[-1]) for elem in l2: vKnap.append((vKnap[-1] << elem) | vKnap[-1]) hSet = [] hSet2 = [] vSet = [] vSet2 = [] if hKnap[-1] & 1 << (sum(l1) // 2): curSum = sum(l1) // 2 for i in range(h - 1, -1, -1): if curSum >= l1[i] and hKnap[i] & (1 << (curSum - l1[i])): curSum -= l1[i] hSet.append(l1[i]) else: hSet2.append(l1[i]) if vKnap[-1] & 1 << (sum(l2) // 2): curSum = sum(l2) // 2 for i in range(v - 1, -1, -1): if curSum >= l2[i] and vKnap[i] & (1 << (curSum - l2[i])): curSum -= l2[i] vSet.append(l2[i]) else: vSet2.append(l2[i]) if not hSet or not vSet: print("No") else: print("Yes") if len(hSet) < len(hSet2): hTupleS = tuple(sorted(hSet)) hTupleL = tuple(sorted(hSet2)) else: hTupleS = tuple(sorted(hSet2)) hTupleL = tuple(sorted(hSet)) if len(vSet) < len(vSet2): vTupleS = tuple(sorted(vSet)) vTupleL = tuple(sorted(vSet2)) else: vTupleS = tuple(sorted(vSet2)) vTupleL = tuple(sorted(vSet)) currentLoc = [0,0] isHS = True isHL = False isVS = False isVL = True hIndex = len(hTupleS)-1 vIndex = 0 for i in range(h): if isHS: currentLoc[0] += hTupleS[hIndex] hIndex -= 1 if hIndex < 0: hIndex = 0 isHS = False isHL = True elif isHL: currentLoc[0] -= hTupleL[hIndex] hIndex += 1 print(str(currentLoc[0]) + " " + str(currentLoc[1])) if isVL: currentLoc[1] += vTupleL[vIndex] vIndex += 1 if vIndex >= len(vTupleL): vIndex = len(vTupleS) - 1 isVL = False isVH = True elif isHL: currentLoc[1] -= vTupleS[vIndex] vIndex -= 1 print(str(currentLoc[0]) + " " + str(currentLoc[1])) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
instruction
0
107,234
23
214,468
No
output
1
107,234
23
214,469
Provide tags and a correct Python 3 solution for this coding contest problem. Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct. The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates. All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values. Output Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 4 3 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 -1 Output 1.41421356237309514547 1.00000000000000000000 0.00000000000000000000
instruction
0
107,401
23
214,802
Tags: geometry Correct Solution: ``` def main(): from math import hypot n, m = map(int, input().split()) vertices = list(tuple(map(float, input().split())) for _ in range(n)) ax, ay = vertices[-1] for i, (bx, by) in enumerate(vertices): vertices[i], ax, ay = (bx, by, bx - ax, by - ay), bx, by for _ in range(m): x0, y0, x1, y1 = map(float, input().split()) x1 -= x0 y1 -= y0 bx, by = vertices[-1][:2] tmp = (bx - x0) * y1 - (by - y0) * x1 t = -1 if tmp < 0 else 1 if tmp > 0 else 0 res = [] for bx, by, abx, aby in vertices: s, tmp = t, (bx - x0) * y1 - (by - y0) * x1 t = -1 if tmp < 0 else 1 if tmp > 0 else 0 if s != t: res.append((((bx - x0) * aby - (by - y0) * abx) / (x1 * aby - y1 * abx), s - t)) res.sort() t, w = 0, 0. for i, (tmp, s) in enumerate(res, -1): if t: w += tmp - res[i][0] t += s print(w * hypot(x1, y1)) if __name__ == '__main__': main() ```
output
1
107,401
23
214,803
Provide tags and a correct Python 3 solution for this coding contest problem. Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct. The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates. All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values. Output Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 4 3 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 -1 Output 1.41421356237309514547 1.00000000000000000000 0.00000000000000000000
instruction
0
107,402
23
214,804
Tags: geometry Correct Solution: ``` import math eps = 1e-9 def sign(n): if n > eps: return 1 if n < -eps: return -1 return 0 def cross(a, b): return a.x * b.y - a.y * b.x class Vector: def __init__(self, x, y): self.x = x self.y = y def __add__(self, v): return Vector(self.x + v.x, self.y + v.y) def __sub__(self, v): return Vector(self.x - v.x, self.y - v.y) def length(self): return math.hypot(self.x, self.y) def solve(polygon, p, q): intersections = [] for (a, b) in zip(polygon, polygon[1:] + polygon[:1]): ss = sign(cross(a - p, q - p)) es = sign(cross(b - p, q - p)) if ss == es: continue t = cross(a - p, a - b) / cross(q - p, a - b) intersections.append((t, es - ss)) intersections = sorted(intersections) total_t, previous_t, count = [0] * 3 for t, order in intersections: if (count > 0): total_t += t - previous_t previous_t = t count += order # print(total_t) print(total_t * (q - p).length()) n, m = map(int, input().split()) polygon = [] for i in range(n): x, y = map(float, input().split()) polygon.append(Vector(x, y)) area = sum(map(lambda x: cross(x[0], x[1]), zip(polygon, polygon[1:] + polygon[:1]))) if (area < 0): polygon.reverse() for i in range(m): x1, y1, x2, y2 = map(float, input().split()) solve(polygon, Vector(x1, y1), Vector(x2, y2)) ```
output
1
107,402
23
214,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct. The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates. All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values. Output Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 4 3 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 -1 Output 1.41421356237309514547 1.00000000000000000000 0.00000000000000000000 Submitted Solution: ``` from math import fsum, hypot def main(): n, m = map(int, input().split()) ax = ay = 0 segments = [] myint = lambda s: int(float(s) * 1e2 + .1) for _ in range(n): bx, by = map(myint, input().split()) segments.append((ax, ay, bx, by)) ax, ay = bx, by _, _, bx, by = segments[0] segments[0] = (ax, ay, bx, by) for _ in range(m): l = [] cx, cy, dx, dy = map(myint, input().split()) linex, liney = dx - cx, dy - cy for ax, ay, bx, by in segments: segx, segy = bx - ax, by - ay den = liney * segx - linex * segy if den: nom = (ay - cy) * linex - (ax - cx) * liney t = nom / den u, v = ax + segx * t, ay + segy * t if ax <= u <= bx and ay <= v <= by or bx <= u <= ax and by <= v <= bx: l.append((u, v)) else: if segx * (cy - ay) == segy * (cx - ax): l.append((ax, ay)) l.append((bx, by)) res = [] for (bx, by), (ax, ay) in zip(l[::2], l[1::2]): res.append(hypot(bx - ax, by - ay)) print(fsum(res) * .01) print() if __name__ == '__main__': main() ```
instruction
0
107,403
23
214,806
No
output
1
107,403
23
214,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct. The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates. All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values. Output Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 4 3 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 -1 Output 1.41421356237309514547 1.00000000000000000000 0.00000000000000000000 Submitted Solution: ``` import sys # sys.stdin = open('ivo.in') EPSYLON = 1e-9 def sign(x): if x > EPSYLON: return 1 if x < -EPSYLON: return -1 return 0 class Point: def __init__(self, x, y): self.x = x self.y = y def dist2(self, point): return (self.x - point.x) * (self.x - point.x) + (self.y - point.y) * (self.y - point.y) def dist(self, point): return self.dist2(point) ** 0.5 def area(a, b, c): return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x class Line: def __init__(self, A, B, C): self.A = A self.B = B self.C = C def __init__(self, a, b): self.A = a.y - b.y self.B = b.x - a.x self.C = a.x * b.y - a.y * b.x def has(self, p): return sign(self.A * p.x + self.B * p.y + self.C) == 0 def intersect(a, b): denom = b.A * a.B - a.A * b.B if sign(denom) == 0: return False x = (a.C * b.B - b.C * a.B) / denom y = (b.C * a.A - a.C * b.A) / denom return Point(x, y) class Segment: def __init__(self, a, b): self.a = a self.b = b def get(self, p): if sign(self.a.x - self.b.x) == 0: return (p.y - self.b.y) / (self.a.y - self.b.y) else: return (p.x - self.b.x) / (self.a.x - self.b.x) n, m = map(int, sys.stdin.readline().split()) poly = [] for i in range(n): x, y = map(float, sys.stdin.readline().split()) if i > 2 and sign(area(poly[-2], poly[-1], Point(x, y))) == 0: continue poly.append(Point(x, y)) lines = [] for i in range(m): x1, y1, x2, y2 = map(float, sys.stdin.readline().split()) lines.append(Line(Point(x1, y1), Point(x2, y2))) n = len(poly) for l in lines: intersections = [] for i in range(n): if l.has(poly[i]) and l.has(poly[(i + 1) % n]): intersections.append(poly[i]) continue s = Segment(poly[i], poly[(i + 1) % n]) line = Line(s.a, s.b) p = intersect(line, l) if not p: continue r = s.get(p) if sign(r) <= 0 or sign(r - 1) > 0: continue intersections.append(p) intersections.sort(key=lambda x:(x.x, x.y)) sum = 0.0 for i in range(0, len(intersections) - 1, 2): if i + 1 < len(intersections): sum += intersections[i].dist(intersections[i + 1]) print(sum) ```
instruction
0
107,404
23
214,808
No
output
1
107,404
23
214,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct. The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates. All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values. Output Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 4 3 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 -1 Output 1.41421356237309514547 1.00000000000000000000 0.00000000000000000000 Submitted Solution: ``` from math import * class pvs: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return pvs(self.x + other.x, self.y + other.y) def __iadd__(self, other): self.x += other.x self.y += other.y return self def __sub__(self, other): return pvs(self.x - other.x, self.y - other.y) def __isub__(self, other): self.x -= other.x self.y -= other.y return self def __neg__(self): return pvs(-self.x, -self.y) def __abs__(self): return sqrt(self.x * self.x + self.y * self.y) def __mul__(self, other): return pvs(self.x * other, self.y * other) def __rmul__(self, other): return self * other def __imul__(self, other): self.x *= other self.y *= other return self def __truediv__(self, other): return pvs(self.x / other, self.y / other) def __idiv__(self, other): self.x /= other self.y /= other return self def __pow__(self, other): """ cos """ return self.x * other.x + self.y * other.y def __xor__(self, other): """ sin """ return self.x * other.y - other.x * self.y def __eq__(self, other): if type(self) is type(other): return self.x == other.x \ and self.y == other.y return False def __str__(self): return '{}:{}'.format(self.x, self.y) def copy(self): return pvs(self.x, self.y) class line: def __init__(self, *args): if len(args) == 0: self.point = pvs(0, 0) self.vector = pvs(1, 0) return if len(args) == 1 and type(args[0]) is line: self.point = args[0].point.copy() self.vector = args[0].vector.copy() return if len(args) == 2 and all(type(arg) is pvs for arg in args): self.point = args[0].copy() self.vector = args[1].copy() return if len(args) == 3: a, b, c = args if a != 0 and b != 0: self.point = pvs(-c / a, 0) self.vector = pvs(c / a, -c / b) elif a == 0: self.point = pvs(0, -c / b) self.vector = pvs(1, 0) else: self.point = pvs(-c / a, 0) self.vector = pvs(0, 1) return exit('line.__init__:\n\tline not constructed!\n\targs : {}'.format(' '.join(*map(str, args)))) def rand(self): self.point -= self.vector * (2**(1/2)) def __str__(self): return '{} {}'.format(self.point, self.vector) def side(self, p): return self.vector ^ (p - self.point) def include_(self, p: pvs): return (p - self.point) ^ self.vector == 0 def copy(self): return line(self.point.copy(), self.vector.copy()) class segment: def __init__(self, a: pvs, b: pvs): self.a = a self.b = b def __len__(self): return abs(self.b - self.a) def copy(self): return segment(self.a.copy(), self.b.copy()) def angle_test(m): ans = 0 MOD = 2*pi for i in range(len(m)): ans += ( atan2(m[i - 1].y - m[i - 2].y, m[i - 1].x - m[i - 2].x) - atan2(m[i].y - m[i - 1].y, m[i].x - m[i - 1].x) + MOD ) % MOD return ans class rectangle: def __init__(self, m): if not all(type(el) is pvs for el in m): exit("rectangle.__init__:\n\tValueError") self.m = [] for i in range(len(m)): if (m[i - 2] - m[i - 1]) ^ (m[i - 1] - m[i]): self.m.append(m[i - 1]) if angle_test(self.m) < 0: self.m.reverse() def line_key(vect: pvs): def take_x(self): return self.x def take_y(self): return self.y return take_x if abs(vect.y) < abs(vect.x) else take_y class __intersectoin: def __init__(self, rect: rectangle, ln: line): last_V = rect.m[-2] q_Int = rect.m[-1] if ln.include_(rect.m[-1]) else None ans = [] for i in range(len(rect.m)): it = intersectoin(ln, segment(rect.m[i - 1], rect.m[i])) if it is not None: # (m[i - 2] - m[i - 1]) ^ (m[i - 1] - m[i]) if it == "||": continue if q_Int is None: if ln.include_(rect.m[i]): q_Int = rect.m[i] else: ans.append(it) else: if q_Int == rect.m[i-1]: if ln.side(rect.m[i]) * ln.side(last_V) < 0: ans.append(it) else: if (q_Int - last_V) ^ (rect.m[i - 1] - q_Int) > 0: ans.append(q_Int) if (rect.m[i-1] - q_Int) ^ (rect.m[i] - rect.m[i-1]) > 0: ans.append(rect.m[i-1]) q_Int = None last_V = rect.m[i - 1] ans.sort(key=line_key(ln.vector)) self.ans = ans def size(self): print(*self.ans) ans = 0 for p1, p2 in zip(self.ans[::2], self.ans[1::2]): ans += abs(p1 - p2) return ans def intersectoin(a, b): if type(a) is line and type(b) is line: p = b.point - a.point k2 = (a.vector ^ p) / (a.vector ^ b.vector) return b.point - (k2 * b.vector) if type(a) is segment and type(b) is line: a, b = b, a if type(a) is line and type(b) is segment: ans = (a.vector ^ (b.a - a.point)), (a.vector ^ (b.b - a.point)) if ans[0] == 0 and ans[1] == 0: return "||" ans = ans[0]*ans[1] if ans <= 0: return intersectoin(a, line(b.a, b.a - b.b)) else: return None if type(a) is rectangle and type(b) is line: return __intersectoin(a, b) exit("cant intersect {} and {}".format(type(a), type(b))) def main(): n, t = map(int, input().split()) rect = rectangle([pvs(*map(float, input().split())) for i in range(n)]) for i in range(t): x1, y1, x2, y2 = map(float, input().split()) p1, p2 = pvs(x1, y1), pvs(x2, y2) ln = line(p1, p2 - p1) ln.rand() print(intersectoin(rect, ln).size()) if __name__ == '__main__': main() ```
instruction
0
107,405
23
214,810
No
output
1
107,405
23
214,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct. The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates. All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values. Output Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 4 3 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 -1 Output 1.41421356237309514547 1.00000000000000000000 0.00000000000000000000 Submitted Solution: ``` from collections import deque from itertools import combinations from math import fsum, hypot def myint(s): return int(float(s) * 100. + 1e-6) def main(): n, m = map(int, input().split()) vertices = list(tuple(map(myint, input().split())) for _ in range(n)) area, (x1, y1) = 0, vertices[-1] for x2, y2 in vertices: area += x2 * y1 - x1 * y2 x1, y1 = x2, y2 if area < 0: vertices.reverse() x0, y0 = vertices.pop() x1, y1 = vertices.pop() vertices, triangles, area = deque(vertices), [], 0 try: while True: x2, y2 = vertices.pop() if (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0) > 0: triangles.append(((x0, y0), (x1, y1), (x2, y2))) area += (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0) else: vertices.appendleft((x0, y0)) x0, y0 = x1, y1 x1, y1 = x2, y2 except IndexError: res = [] for _ in range(m): tmp, edges = [], set() x0, y0, x1, y1 = map(myint, input().split()) dx, dy = x1 - x0, y1 - y0 for t in triangles: seg = [] for e in combinations(t, 2): edge = [(x - x0, y - y0) for x, y in e] if all(dx * y == dy * x for x, y in edge): edges.add(tuple(sorted(e))) break (x2, y2), (x3, y3) = edge dz, dt = x2 - x3, y2 - y3 nom, den = y3 * dz - x3 * dt, dy * dz - dx * dt if den < 0: nom *= -1 den *= -1 if 0 <= nom <= den: seg.append((dx * nom / den, dy * nom / den)) else: if len(seg) > 1: (x2, y2), (x3, y3) = min(seg), max(seg) tmp.append(hypot(x2 - x3, y2 - y3)) for (x2, y2), (x3, y3) in edges: tmp.append(hypot(x2 - x3, y2 - y3)) res.append(str(fsum(tmp) / 1e2)) print('\n'.join(res)) if __name__ == '__main__': main() ```
instruction
0
107,406
23
214,812
No
output
1
107,406
23
214,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≤ i, j ≤ n and i ≠ j. Geometrical progression is a sequence of numbers a1, a2, ..., an where each term after first is found by multiplying the previous one by a fixed non-zero number d called the common ratio. Note that in our task d may be non-integer. For example in progression 4, 6, 9, common ratio is <image>. Two progressions a1, a2, ..., an and b1, b2, ..., bn are considered different, if there is such i (1 ≤ i ≤ n) that ai ≠ bi. Input The first and the only line cotains three integers n, l and r (1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 107). Output Print the integer K — is the answer to the problem. Examples Input 1 1 10 Output 10 Input 2 6 9 Output 12 Input 3 1 10 Output 8 Input 3 3 10 Output 2 Note These are possible progressions for the first test of examples: * 1; * 2; * 3; * 4; * 5; * 6; * 7; * 8; * 9; * 10. These are possible progressions for the second test of examples: * 6, 7; * 6, 8; * 6, 9; * 7, 6; * 7, 8; * 7, 9; * 8, 6; * 8, 7; * 8, 9; * 9, 6; * 9, 7; * 9, 8. These are possible progressions for the third test of examples: * 1, 2, 4; * 1, 3, 9; * 2, 4, 8; * 4, 2, 1; * 4, 6, 9; * 8, 4, 2; * 9, 3, 1; * 9, 6, 4. These are possible progressions for the fourth test of examples: * 4, 6, 9; * 9, 6, 4. Submitted Solution: ``` n, l, r = map(int, input().split()) m = r-l+1 if n == 1: print(m) elif n == 2: print(m*(m-1)) else: cnt = 0 for i in range(2, r): v = i**(n-1) if v > r: break kmax = r // v for j in range(1,i): u = j**(n-1) kmin = l // u + (l % u > 0) if kmin <= kmax: cnt += 2*(kmax-kmin+1) print(cnt) ```
instruction
0
107,493
23
214,986
No
output
1
107,493
23
214,987
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≤ i, j ≤ n and i ≠ j. Geometrical progression is a sequence of numbers a1, a2, ..., an where each term after first is found by multiplying the previous one by a fixed non-zero number d called the common ratio. Note that in our task d may be non-integer. For example in progression 4, 6, 9, common ratio is <image>. Two progressions a1, a2, ..., an and b1, b2, ..., bn are considered different, if there is such i (1 ≤ i ≤ n) that ai ≠ bi. Input The first and the only line cotains three integers n, l and r (1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 107). Output Print the integer K — is the answer to the problem. Examples Input 1 1 10 Output 10 Input 2 6 9 Output 12 Input 3 1 10 Output 8 Input 3 3 10 Output 2 Note These are possible progressions for the first test of examples: * 1; * 2; * 3; * 4; * 5; * 6; * 7; * 8; * 9; * 10. These are possible progressions for the second test of examples: * 6, 7; * 6, 8; * 6, 9; * 7, 6; * 7, 8; * 7, 9; * 8, 6; * 8, 7; * 8, 9; * 9, 6; * 9, 7; * 9, 8. These are possible progressions for the third test of examples: * 1, 2, 4; * 1, 3, 9; * 2, 4, 8; * 4, 2, 1; * 4, 6, 9; * 8, 4, 2; * 9, 3, 1; * 9, 6, 4. These are possible progressions for the fourth test of examples: * 4, 6, 9; * 9, 6, 4. Submitted Solution: ``` def pow(a,n): if(n==0): return 1 if(n==1): return a P = pow(a,n//2) Q=1 if(n%2==1): Q=a return P*P*Q def uf(x,y): if(x>(x//y)*y): return (x//y)+1 return x//y n, l, r = map(int,input().split(' ')) ans = 0 if(n>24): print(0) elif(n==1): print(r-l+1) else: acc_l = 1; acc_r=1; while(pow(acc_l,n-1)<l): acc_l=acc_l+1 while(pow(acc_r,n-1)<=r): acc_r=acc_r+1 acc_r = acc_r-1 if(acc_l==1 or acc_r==1): print(0) else: for i in range(acc_l,acc_r+1): ans+=max(0,((r//(pow(i,n-1)))-l+1)) for i in range(acc_l,acc_r+1): for j in range(i+1,acc_r+1): ans += max(0,(r//pow(j,n-1))-uf(l,pow(i,n-1))+1); print(ans*2) ```
instruction
0
107,494
23
214,988
No
output
1
107,494
23
214,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≤ i, j ≤ n and i ≠ j. Geometrical progression is a sequence of numbers a1, a2, ..., an where each term after first is found by multiplying the previous one by a fixed non-zero number d called the common ratio. Note that in our task d may be non-integer. For example in progression 4, 6, 9, common ratio is <image>. Two progressions a1, a2, ..., an and b1, b2, ..., bn are considered different, if there is such i (1 ≤ i ≤ n) that ai ≠ bi. Input The first and the only line cotains three integers n, l and r (1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 107). Output Print the integer K — is the answer to the problem. Examples Input 1 1 10 Output 10 Input 2 6 9 Output 12 Input 3 1 10 Output 8 Input 3 3 10 Output 2 Note These are possible progressions for the first test of examples: * 1; * 2; * 3; * 4; * 5; * 6; * 7; * 8; * 9; * 10. These are possible progressions for the second test of examples: * 6, 7; * 6, 8; * 6, 9; * 7, 6; * 7, 8; * 7, 9; * 8, 6; * 8, 7; * 8, 9; * 9, 6; * 9, 7; * 9, 8. These are possible progressions for the third test of examples: * 1, 2, 4; * 1, 3, 9; * 2, 4, 8; * 4, 2, 1; * 4, 6, 9; * 8, 4, 2; * 9, 3, 1; * 9, 6, 4. These are possible progressions for the fourth test of examples: * 4, 6, 9; * 9, 6, 4. Submitted Solution: ``` n, l, r = map(int, input().split()) m = r-l+1 if n == 1: print(m) elif n == 2: print(m*(m-1)) else: cnt = 0 drop = [] for i in range(2,r): v = i**(n-1) if v > r: break for vv in range(v,r+1,v): drop.append(vv) for i in range(2, r): v = i**(n-1) if v > r: break kmax = r // v for j in range(1,i): u = j**(n-1) kmin = l // u + (l % u > 0) if kmin <= kmax: cnt += 2*(kmax-kmin+1-sum(map(lambda x: x >= kmin and x <= kmax, drop))) #print(kmax, kmin, sum(map(lambda x: x >= kmin and x <= kmax, drop)), list(map(lambda x: x >= kmin and x <= kmax, drop)), drop) print(cnt) ```
instruction
0
107,495
23
214,990
No
output
1
107,495
23
214,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≤ i, j ≤ n and i ≠ j. Geometrical progression is a sequence of numbers a1, a2, ..., an where each term after first is found by multiplying the previous one by a fixed non-zero number d called the common ratio. Note that in our task d may be non-integer. For example in progression 4, 6, 9, common ratio is <image>. Two progressions a1, a2, ..., an and b1, b2, ..., bn are considered different, if there is such i (1 ≤ i ≤ n) that ai ≠ bi. Input The first and the only line cotains three integers n, l and r (1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 107). Output Print the integer K — is the answer to the problem. Examples Input 1 1 10 Output 10 Input 2 6 9 Output 12 Input 3 1 10 Output 8 Input 3 3 10 Output 2 Note These are possible progressions for the first test of examples: * 1; * 2; * 3; * 4; * 5; * 6; * 7; * 8; * 9; * 10. These are possible progressions for the second test of examples: * 6, 7; * 6, 8; * 6, 9; * 7, 6; * 7, 8; * 7, 9; * 8, 6; * 8, 7; * 8, 9; * 9, 6; * 9, 7; * 9, 8. These are possible progressions for the third test of examples: * 1, 2, 4; * 1, 3, 9; * 2, 4, 8; * 4, 2, 1; * 4, 6, 9; * 8, 4, 2; * 9, 3, 1; * 9, 6, 4. These are possible progressions for the fourth test of examples: * 4, 6, 9; * 9, 6, 4. Submitted Solution: ``` #!/usr/bin/env python3 def read_string(): return input() def read_strings(return_type = iter, split = None, skip = 0): return return_type(input().split(split)[skip:]) def read_lines(height, return_type = iter): return return_type(read_string() for i in range(height)) def read_number(): return int(input()) def read_numbers(return_type = iter, skip = 0): return return_type(int(i) for i in input().split()[skip:]) def read_values(*types, array = None): line = input().split() result = [] for return_type, i in zip(types, range(len(types))): result.append(return_type(line[i])) if array != None: array_type, array_contained = array result.append(array_type(array_contained(i) for i in line[len(types):])) return result def read_array(item_type = int, return_type = iter, skip = 0): return return_type(item_type(i) for i in input().split()[skip:]) def read_martix(height, **args): return_type = args["return_type"] if "return_type" in args else iter return_type_inner = args["return_type_inner"] if "return_type_inner" in args else return_type return_type_outer = args["return_type_outer"] if "return_type_outer" in args else return_type item_type = args["item_type"] if "item_type" in args else int return return_type_outer(read_array(item_type = item_type, return_type = return_type_inner) for i in range(height)) def read_martix_linear(width, skip = 0, item_type = int, skiped = None): num = read_array(item_type = item_type, skip = skip) height = len(num) / width return [num[i * width: (i + 1) * width] for i in range(height)] # (q > p) # a # ... # a * q ^ (n-1) def solve(n, amin, amax, r): if amin > amax: return 0; qn = q ** (n-1) amax = min(amax, r // qn) if amin > amax: return 0; return amax - amin + 1 def gcd(x, y): if x == 0: return y return gcd (y % x, x) def main(): n, l, r = read_numbers() if n == 1: ans = r - l + 1 elif n == 2: ans = (r - l + 1) * (r - l) else: ans = 0 for p in range(1, r + 1): pn = p ** (n - 1) if pn > r: break for q in range(p + 1, r + 1): if gcd(p, q) == 1: qn = q ** (n - 1) if qn > r: break if (r + qn - 1) // qn >= l // pn: ans += r // qn - (l + pn - 1) // pn + 1 ans *= 2 print(ans) if __name__ == '__main__': main() ```
instruction
0
107,496
23
214,992
No
output
1
107,496
23
214,993
Provide a correct Python 3 solution for this coding contest problem. There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs. Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct. Constraints * 1 \leq X \leq 100 * 1 \leq Y \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: X Y Output If there is a combination of numbers of cranes and turtles in which the statement is correct, print `Yes`; otherwise, print `No`. Examples Input 3 8 Output Yes Input 2 100 Output No Input 1 2 Output Yes
instruction
0
107,625
23
215,250
"Correct Solution: ``` x,y=map(int,input().split()) #x匹でy本 if y<2*x or 4*x<y or y%2==1: print("No") else: print("Yes") ```
output
1
107,625
23
215,251
Provide a correct Python 3 solution for this coding contest problem. There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs. Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct. Constraints * 1 \leq X \leq 100 * 1 \leq Y \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: X Y Output If there is a combination of numbers of cranes and turtles in which the statement is correct, print `Yes`; otherwise, print `No`. Examples Input 3 8 Output Yes Input 2 100 Output No Input 1 2 Output Yes
instruction
0
107,627
23
215,254
"Correct Solution: ``` x, y = map(int, input().split()) if x*2<=y and y<=x*4 and y%2==0: print('Yes') else: print('No') ```
output
1
107,627
23
215,255
Provide a correct Python 3 solution for this coding contest problem. Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate, he thought that it would be enough to measure the altitudes at only a limited number of sites and then approximate the altitudes of the rest based on them. Multiple approximations might be possible based on the same measurement results, in which case he wants to know the worst case, that is, one giving the lowest average altitude. Mr. Boat’s estate, which has a rectangular shape, is divided into grid-aligned rectangular areas of the same size. Altitude measurements have been carried out in some of these areas, and the measurement results are now at hand. The altitudes of the remaining areas are to be approximated on the assumption that altitudes of two adjoining areas sharing an edge differ at most 1. In the first sample given below, the land is divided into 5 × 4 areas. The altitudes of the areas at (1, 1) and (5, 4) are measured 10 and 3, respectively. In this case, the altitudes of all the areas are uniquely determined on the assumption that altitudes of adjoining areas differ at most 1. In the second sample, there are multiple possibilities, among which one that gives the lowest average altitude should be considered. In the third sample, no altitude assignments satisfy the assumption on altitude differences. <image> Your job is to write a program that approximates the average altitude of his estate. To be precise, the program should compute the total of approximated and measured altitudes of all the mesh-divided areas. If two or more different approximations are possible, the program should compute the total with the severest approximation, that is, one giving the lowest total of the altitudes. Input The input consists of a single test case of the following format. $w$ $d$ $n$ $x_1$ $y_1$ $z_1$ . . . $x_n$ $y_n$ $z_n$ Here, $w$, $d$, and $n$ are integers between $1$ and $50$, inclusive. $w$ and $d$ are the numbers of areas in the two sides of the land. $n$ is the number of areas where altitudes are measured. The $i$-th line of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ satisfying $1 \leq x_i \leq w$, $1 \leq y_i \leq d$, and $−100 \leq z_i \leq 100$. They mean that the altitude of the area at $(x_i , y_i)$ was measured to be $z_i$. At most one measurement result is given for the same area, i.e., for $i \ne j$, $(x_i, y_i) \ne (x_j , y_j)$. Output If all the unmeasured areas can be assigned their altitudes without any conflicts with the measured altitudes assuming that two adjoining areas have the altitude difference of at most 1, output an integer that is the total of the measured or approximated altitudes of all the areas. If more than one such altitude assignment is possible, output the minimum altitude total among the possible assignments. If no altitude assignments satisfy the altitude difference assumption, output No. Sample Input 1 5 4 2 1 1 10 5 4 3 Sample Output 1 130 Sample Input 2 5 4 3 2 2 0 4 3 0 5 1 2 Sample Output 2 -14 Sample Input 3 3 3 2 1 1 8 3 3 3 Sample Output 3 No Sample Input 4 2 2 1 1 1 -100 Sample Output 4 -404 Example Input 5 4 2 1 1 10 5 4 3 Output 130
instruction
0
107,815
23
215,630
"Correct Solution: ``` def isValid(row, col, ROWS, COLS): return row >= 0 and row < ROWS and col >= 0 and col < COLS def isSteep(board, row, col, ROWS, COLS): global adjR, adjC h = board[row][col] for i in range(4): rr = row + adjR[i] cc = col + adjC[i] if isValid(rr, cc, ROWS, COLS): diff = abs(h - board[rr][cc]) if diff > 1: return True return False def update(board, row, col, ROWS, COLS): global adjR, adjC, given arr = [] h = board[row][col] for i in range(4): rr = row + adjR[i] cc = col + adjC[i] if (rr, cc) in given: continue if isValid(rr, cc, ROWS, COLS): if board[rr][cc] == None or board[rr][cc] < h - 1: board[rr][cc] = h - 1 arr.append((rr, cc)) return arr if __name__ == '__main__': COLS, ROWS, N = list(map(int, input().split())) board = [ [ None for _ in range(COLS) ] for _ in range(ROWS) ] plist = [] adjR = [-1, 0, 0, 1] adjC = [0, -1, 1, 0] given = set() for _ in range(N): c, r, h = list(map(int, input().strip().split())) board[r - 1][c - 1] = h plist.append((r-1, c-1)) given.add((r-1, c-1)) while len(plist) > 0: row, col = plist.pop(0) updated = update(board, row, col, ROWS, COLS) plist.extend(updated) isPossible = True total = 0 for r in range(ROWS): for c in range(COLS): isPossible = isPossible and not isSteep(board, r, c, ROWS, COLS) if not isPossible: break total += board[r][c] if not isPossible: break print(total if isPossible else "No") ```
output
1
107,815
23
215,631
Provide a correct Python 3 solution for this coding contest problem. Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate, he thought that it would be enough to measure the altitudes at only a limited number of sites and then approximate the altitudes of the rest based on them. Multiple approximations might be possible based on the same measurement results, in which case he wants to know the worst case, that is, one giving the lowest average altitude. Mr. Boat’s estate, which has a rectangular shape, is divided into grid-aligned rectangular areas of the same size. Altitude measurements have been carried out in some of these areas, and the measurement results are now at hand. The altitudes of the remaining areas are to be approximated on the assumption that altitudes of two adjoining areas sharing an edge differ at most 1. In the first sample given below, the land is divided into 5 × 4 areas. The altitudes of the areas at (1, 1) and (5, 4) are measured 10 and 3, respectively. In this case, the altitudes of all the areas are uniquely determined on the assumption that altitudes of adjoining areas differ at most 1. In the second sample, there are multiple possibilities, among which one that gives the lowest average altitude should be considered. In the third sample, no altitude assignments satisfy the assumption on altitude differences. <image> Your job is to write a program that approximates the average altitude of his estate. To be precise, the program should compute the total of approximated and measured altitudes of all the mesh-divided areas. If two or more different approximations are possible, the program should compute the total with the severest approximation, that is, one giving the lowest total of the altitudes. Input The input consists of a single test case of the following format. $w$ $d$ $n$ $x_1$ $y_1$ $z_1$ . . . $x_n$ $y_n$ $z_n$ Here, $w$, $d$, and $n$ are integers between $1$ and $50$, inclusive. $w$ and $d$ are the numbers of areas in the two sides of the land. $n$ is the number of areas where altitudes are measured. The $i$-th line of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ satisfying $1 \leq x_i \leq w$, $1 \leq y_i \leq d$, and $−100 \leq z_i \leq 100$. They mean that the altitude of the area at $(x_i , y_i)$ was measured to be $z_i$. At most one measurement result is given for the same area, i.e., for $i \ne j$, $(x_i, y_i) \ne (x_j , y_j)$. Output If all the unmeasured areas can be assigned their altitudes without any conflicts with the measured altitudes assuming that two adjoining areas have the altitude difference of at most 1, output an integer that is the total of the measured or approximated altitudes of all the areas. If more than one such altitude assignment is possible, output the minimum altitude total among the possible assignments. If no altitude assignments satisfy the altitude difference assumption, output No. Sample Input 1 5 4 2 1 1 10 5 4 3 Sample Output 1 130 Sample Input 2 5 4 3 2 2 0 4 3 0 5 1 2 Sample Output 2 -14 Sample Input 3 3 3 2 1 1 8 3 3 3 Sample Output 3 No Sample Input 4 2 2 1 1 1 -100 Sample Output 4 -404 Example Input 5 4 2 1 1 10 5 4 3 Output 130
instruction
0
107,816
23
215,632
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def main(): w,h,n = LI() aa = [LI() for _ in range(n)] q = [] r = [[None] * w for _ in range(h)] for x,y,z in aa: r[y-1][x-1] = z heapq.heappush(q, (-z, (y-1,x-1))) v = collections.defaultdict(bool) while len(q): k, u = heapq.heappop(q) if v[u]: continue v[u] = True y = u[0] x = u[1] for dy,dx in dd: uy = y+dy ux = x+dx if uy < 0 or uy >= h or ux < 0 or ux >= w: continue uv = (uy,ux) if v[uv]: continue vd = -k - 1 if r[uy][ux] is None: r[uy][ux] = vd heapq.heappush(q, (-vd, uv)) else: if abs(r[uy][ux] + k) > 1: return 'No' return sum(sum(_) for _ in r) print(main()) ```
output
1
107,816
23
215,633
Provide a correct Python 3 solution for this coding contest problem. Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate, he thought that it would be enough to measure the altitudes at only a limited number of sites and then approximate the altitudes of the rest based on them. Multiple approximations might be possible based on the same measurement results, in which case he wants to know the worst case, that is, one giving the lowest average altitude. Mr. Boat’s estate, which has a rectangular shape, is divided into grid-aligned rectangular areas of the same size. Altitude measurements have been carried out in some of these areas, and the measurement results are now at hand. The altitudes of the remaining areas are to be approximated on the assumption that altitudes of two adjoining areas sharing an edge differ at most 1. In the first sample given below, the land is divided into 5 × 4 areas. The altitudes of the areas at (1, 1) and (5, 4) are measured 10 and 3, respectively. In this case, the altitudes of all the areas are uniquely determined on the assumption that altitudes of adjoining areas differ at most 1. In the second sample, there are multiple possibilities, among which one that gives the lowest average altitude should be considered. In the third sample, no altitude assignments satisfy the assumption on altitude differences. <image> Your job is to write a program that approximates the average altitude of his estate. To be precise, the program should compute the total of approximated and measured altitudes of all the mesh-divided areas. If two or more different approximations are possible, the program should compute the total with the severest approximation, that is, one giving the lowest total of the altitudes. Input The input consists of a single test case of the following format. $w$ $d$ $n$ $x_1$ $y_1$ $z_1$ . . . $x_n$ $y_n$ $z_n$ Here, $w$, $d$, and $n$ are integers between $1$ and $50$, inclusive. $w$ and $d$ are the numbers of areas in the two sides of the land. $n$ is the number of areas where altitudes are measured. The $i$-th line of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ satisfying $1 \leq x_i \leq w$, $1 \leq y_i \leq d$, and $−100 \leq z_i \leq 100$. They mean that the altitude of the area at $(x_i , y_i)$ was measured to be $z_i$. At most one measurement result is given for the same area, i.e., for $i \ne j$, $(x_i, y_i) \ne (x_j , y_j)$. Output If all the unmeasured areas can be assigned their altitudes without any conflicts with the measured altitudes assuming that two adjoining areas have the altitude difference of at most 1, output an integer that is the total of the measured or approximated altitudes of all the areas. If more than one such altitude assignment is possible, output the minimum altitude total among the possible assignments. If no altitude assignments satisfy the altitude difference assumption, output No. Sample Input 1 5 4 2 1 1 10 5 4 3 Sample Output 1 130 Sample Input 2 5 4 3 2 2 0 4 3 0 5 1 2 Sample Output 2 -14 Sample Input 3 3 3 2 1 1 8 3 3 3 Sample Output 3 No Sample Input 4 2 2 1 1 1 -100 Sample Output 4 -404 Example Input 5 4 2 1 1 10 5 4 3 Output 130
instruction
0
107,817
23
215,634
"Correct Solution: ``` #!/usr/bin/python3 import os import sys def main(): W, D, N = read_ints() M = [tuple(read_ints()) for _ in range(N)] ans = solve(W, D, N, M) if ans is None: print('No') else: print(ans) def solve(W, D, N, M): INF = 999 H = [[INF] * W for _ in range(D)] hmap = {} for h in range(-210, 101): hmap[h] = set() for x, y, z in M: x -= 1 y -= 1 hmap[z].add((x, y)) H[y][x] = z for h in range(100, -210, -1): for x, y in hmap[h]: if H[y][x] == INF: H[y][x] = h elif H[y][x] > h: continue for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): nx = x + dx ny = y + dy if nx < 0 or nx >= W or ny < 0 or ny >= D: continue if H[ny][nx] < h - 1: return None if H[ny][nx] == INF: hmap[h - 1].add((nx, ny)) return sum([sum(r) for r in H]) ############################################################################### DEBUG = 'DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def dprint(*value, sep=' ', end='\n'): if DEBUG: print(*value, sep=sep, end=end) if __name__ == '__main__': main() ```
output
1
107,817
23
215,635
Provide a correct Python 3 solution for this coding contest problem. Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate, he thought that it would be enough to measure the altitudes at only a limited number of sites and then approximate the altitudes of the rest based on them. Multiple approximations might be possible based on the same measurement results, in which case he wants to know the worst case, that is, one giving the lowest average altitude. Mr. Boat’s estate, which has a rectangular shape, is divided into grid-aligned rectangular areas of the same size. Altitude measurements have been carried out in some of these areas, and the measurement results are now at hand. The altitudes of the remaining areas are to be approximated on the assumption that altitudes of two adjoining areas sharing an edge differ at most 1. In the first sample given below, the land is divided into 5 × 4 areas. The altitudes of the areas at (1, 1) and (5, 4) are measured 10 and 3, respectively. In this case, the altitudes of all the areas are uniquely determined on the assumption that altitudes of adjoining areas differ at most 1. In the second sample, there are multiple possibilities, among which one that gives the lowest average altitude should be considered. In the third sample, no altitude assignments satisfy the assumption on altitude differences. <image> Your job is to write a program that approximates the average altitude of his estate. To be precise, the program should compute the total of approximated and measured altitudes of all the mesh-divided areas. If two or more different approximations are possible, the program should compute the total with the severest approximation, that is, one giving the lowest total of the altitudes. Input The input consists of a single test case of the following format. $w$ $d$ $n$ $x_1$ $y_1$ $z_1$ . . . $x_n$ $y_n$ $z_n$ Here, $w$, $d$, and $n$ are integers between $1$ and $50$, inclusive. $w$ and $d$ are the numbers of areas in the two sides of the land. $n$ is the number of areas where altitudes are measured. The $i$-th line of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ satisfying $1 \leq x_i \leq w$, $1 \leq y_i \leq d$, and $−100 \leq z_i \leq 100$. They mean that the altitude of the area at $(x_i , y_i)$ was measured to be $z_i$. At most one measurement result is given for the same area, i.e., for $i \ne j$, $(x_i, y_i) \ne (x_j , y_j)$. Output If all the unmeasured areas can be assigned their altitudes without any conflicts with the measured altitudes assuming that two adjoining areas have the altitude difference of at most 1, output an integer that is the total of the measured or approximated altitudes of all the areas. If more than one such altitude assignment is possible, output the minimum altitude total among the possible assignments. If no altitude assignments satisfy the altitude difference assumption, output No. Sample Input 1 5 4 2 1 1 10 5 4 3 Sample Output 1 130 Sample Input 2 5 4 3 2 2 0 4 3 0 5 1 2 Sample Output 2 -14 Sample Input 3 3 3 2 1 1 8 3 3 3 Sample Output 3 No Sample Input 4 2 2 1 1 1 -100 Sample Output 4 -404 Example Input 5 4 2 1 1 10 5 4 3 Output 130
instruction
0
107,818
23
215,636
"Correct Solution: ``` from sys import stdin, stdout import math import bisect import queue w, d, n = map(int, input().strip().split()) mapper = [[-1000 for i in range(55)] for j in range(55)] step = [[0, 1], [0, -1], [1, 0], [-1, 0]] arr = [] for i in range(n): tmp = tuple(map(int, stdin.readline().strip().split())) arr.append(tmp) flag = 1 for i in range(len(arr)): for j in range(i + 1, len(arr)): if abs(arr[i][0] - arr[j][0]) + abs(arr[i][1] - arr[j][1]) < abs(arr[i][2] - arr[j][2]): flag = 0 break if flag == 0: break if flag == 0: stdout.writelines('No\n') else: for each in arr: mapper[each[0]][each[1]] = each[2] chk = [[0 for i in range(55)] for j in range(55)] chk[each[0]][each[1]] = 1 pend = queue.Queue() pend.put(each) while pend.qsize(): top = pend.get() for each in step: newpos = [top[0] - each[0], top[1] - each[1]] if newpos[0] > 0 and newpos[0] <= w and newpos[1] > 0 and newpos[1] <= d and chk[newpos[0]][newpos[1]] < 1: mapper[newpos[0]][newpos[1]] = max(mapper[newpos[0]][newpos[1]], top[2] - 1) chk[newpos[0]][newpos[1]] += 1 pend.put((newpos[0], newpos[1], mapper[newpos[0]][newpos[1]])) ans = 0 for i in range(1, w + 1): for j in range(1, d + 1): ans += mapper[i][j] stdout.writelines(str(ans) + '\n') ```
output
1
107,818
23
215,637
Provide a correct Python 3 solution for this coding contest problem. π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρος (perimeter). Recently, the government of some country decided to allow use of 3, rather than 3.14, as the approximate value of π in school (although the decision was eventually withdrawn probably due to the blame of many people). This decision is very surprising, since this approximation is far less accurate than those obtained before the common era. Ancient mathematicians tried to approximate the value of π without calculators. A typical method was to calculate the perimeter of inscribed and circumscribed regular polygons of the circle. For example, Archimedes (287–212 B.C.) proved that 223/71 < π < 22/7 using 96-sided polygons, where 223/71 and 22/7 were both accurate to two fractional digits (3.14). The resultant approximation would be more accurate as the number of vertices of the regular polygons increased. As you see in the previous paragraph, π was approximated by fractions rather than decimal numbers in the older ages. In this problem, you are requested to represent π as a fraction with the smallest possible denominator such that the representing value is not different by more than the given allowed error. If more than one fraction meets this criterion, the fraction giving better approximation is preferred. Input The input consists of multiple datasets. Each dataset has a real number R (0 < R ≤ 1) representing the allowed difference between the fraction and π. The value may have up to seven digits after the decimal point. The input is terminated by a line containing 0.0, which must not be processed. Output For each dataset, output the fraction which meets the criteria in a line. The numerator and denominator of the fraction should be separated by a slash as shown in the sample output, and those numbers must be integers. Example Input 0.15 0.05 0.0 Output 3/1 19/6
instruction
0
107,820
23
215,640
"Correct Solution: ``` from math import pi while 1: r=float(input()) if r==0:break n=d=1 while abs(n/d-pi)>r: if n/d<pi:n+=1 else: d+=1 print('%d/%d'%(n,d)) ```
output
1
107,820
23
215,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Submitted Solution: ``` n = int(input()) gh = [0 for _ in range(n)] arr = [gh[:] for _ in range(n) ] visited = [gh[:] for _ in range(n)] for i in range(n): a = input() a1 = a.split() for j in range(n): arr[i][j] = int(a1[j]) if n == 1: print( a) else: middleR = (n - 1) // 2 middleC = (n - 1 ) // 2 total = 0 for i in range(n): if visited[middleR][i] == 0: visited[middleR][i] = 1 total += arr[middleR][i] #print(visited) for i in range(n): if visited[i][middleC] == 0: visited[i][middleC] = 1 total += arr[i][middleC] #print(visited) for i in range(n): if visited[i][i] == 0: visited[i][i] = 1 total += arr[i][i] #print(visited) ku = 0 for i in range(n): kkt = n - 1 - i if visited[ku][kkt] == 0: visited[ku][kkt] = 1 total += arr[ku][kkt] ku += 1 #print(visited) print(total) ```
instruction
0
108,122
23
216,244
Yes
output
1
108,122
23
216,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Submitted Solution: ``` x = int(input()) a = [] b = [] for i in range(x): b.append(list(map(int, input().split(" ")))) c = b[x//2][x//2] b[x//2][x//2] = 0 a = a + b[x//2] for i in b: a.append(i[x//2]) for i in range(x): for j in range(x): if i == j: a.append(b[i][j]) else: pass for i in reversed(range(x)): for j in range(x): if i + j == x - 1: a.append(b[i][j]) else: pass print(sum(a) + c) ```
instruction
0
108,123
23
216,246
Yes
output
1
108,123
23
216,247
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Submitted Solution: ``` n = int(input()) res = 0 for i in range(n): row = map(int, input().split()) for j, v in enumerate(row): if i == j or i + j == n - 1 or i == n // 2 or j == n // 2: res += v print(res) ```
instruction
0
108,124
23
216,248
Yes
output
1
108,124
23
216,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Submitted Solution: ``` n = int(input()) a = [list(map(int,input().split())) for i in range(n)] ans = 0 for i in range(n): ans += a[i][i] + a[i][n - i - 1] + a[n // 2][i] + a[i][n // 2] print(ans-3*a[n//2][n//2]) ```
instruction
0
108,125
23
216,250
Yes
output
1
108,125
23
216,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Submitted Solution: ``` # matrix dimensions n = int(input()) matrix = [] for mr in range(0, n): matrix.append(list(map(int, input().split()))) # get middle row (no need for + 1 since index starts with 0) # good matrix points gmp = sum(matrix[(n//2)]) matrix[n//2] = [0] * n # get middle column gmp += sum([x[n//2] for x in matrix]) for x in range(0, n): matrix[x][n//2] = 0 # get main and secondary diagonal # since all elements already counted for middle row # and middle column are already 0 # there's no need to worry about [n/2][n/2] now for x in range(0, n): gmp += matrix[x][x] + matrix[-1 - x][-1 - x] print(gmp) ```
instruction
0
108,126
23
216,252
No
output
1
108,126
23
216,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Submitted Solution: ``` """ Author : Indian Coder Date : 29th May ,2021 """ #Imports import math import time import random start=time.time() n=int(input()) sample=0 sample1=[] for i in range(0,n): a1=list(map(int ,input().split())) sample+=(sum(a1)) sample1.append(a1) if(n<=3): print(sample) else: back_val=n back_value_list=[] for i in range(0,len(sample1)): back_value_list.append(sample1[i][back_val-1]) back_val-=1 #print(sample1) #print(back_value_list) front_valu=0 front_value_list=[] for j in range(0,len(sample1)): front_value_list.append(sample1[j][front_valu]) front_valu+=1 #print(front_value_list) middle_col_value=0 pos_add=n//2+1 for k in range(0,len(sample1)): middle_col_value+=sample1[k][pos_add-1] #print(middle_col_value) middle_row_sum=sum(sample1[pos_add-1]) print(sum(front_value_list)+sum(back_value_list)+middle_col_value+middle_row_sum-3*sample1[n//2+1][n//2]) end=time.time() #print("Time Of Execution Is",end-start) ```
instruction
0
108,127
23
216,254
No
output
1
108,127
23
216,255