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. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4
instruction
0
106,157
23
212,314
Tags: binary search, constructive algorithms, math Correct Solution: ``` n=int(input()) for i in range(1, 40000): if i*i>=n: x=i break print(n//x+i+int(n%x>0)) ```
output
1
106,157
23
212,315
Provide tags and a correct Python 3 solution for this coding contest problem. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4
instruction
0
106,158
23
212,316
Tags: binary search, constructive algorithms, math Correct Solution: ``` import math n = int(input()) q = math.sqrt(n) if q == int(q): q = int(q) print(2 * q) elif q - int(q) >= 0.5: q = int(q) + 1 print(2 * q) else: q = int(q) print(2 * q + 1) ```
output
1
106,158
23
212,317
Provide tags and a correct Python 3 solution for this coding contest problem. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4
instruction
0
106,159
23
212,318
Tags: binary search, constructive algorithms, math Correct Solution: ``` n=int(input()) from math import ceil def res(n): return ceil(2*n**0.5) print(res(n)) ```
output
1
106,159
23
212,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` print(1 + int((4 * int(input()) - 3) ** 0.5)) ```
instruction
0
106,160
23
212,320
Yes
output
1
106,160
23
212,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` n = int(input()) i = int(n**0.5) if i**2 == n: print(2*i) elif (i+1)*i>=n: print(2*i+1) else: print(2*i+2) ```
instruction
0
106,161
23
212,322
Yes
output
1
106,161
23
212,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` from math import sqrt n = int(input()) q = int(sqrt(n)) rest = n - (q*q) k = rest // q if rest%q != 0: k+=1 print(q*2 + k) ```
instruction
0
106,162
23
212,324
Yes
output
1
106,162
23
212,325
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` n = int(input()) n2 = n ** 0.5 if n2 != int(n2): n2 = int(n2) + 1 if (n2 - 1) * n2 >= n: cuts = n2 * 2 - 1 else: cuts = n2 * 2 else: cuts = int(n2 * 2) print(cuts) ```
instruction
0
106,163
23
212,326
Yes
output
1
106,163
23
212,327
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` n=int(input()) print(int((2*(n**0.5)))) ```
instruction
0
106,164
23
212,328
No
output
1
106,164
23
212,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Tue Nov 13 20:48:59 2018 @author: """ """ A = list(map(int, input().split())) print(A) """ n=int(input()) s=2+n//2 print(s) ```
instruction
0
106,165
23
212,330
No
output
1
106,165
23
212,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` n=int(input()) if n==1: print(2) elif n==2: print(3) elif n==3: print(4) elif n%2==0: print(int(n/2)+2) else: print(int(n/2)+3) ```
instruction
0
106,166
23
212,332
No
output
1
106,166
23
212,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: <image> After that, she can draw the remaining two segments, using the first two as a guide: <image> If Sofia needs to draw two squares, she will have to draw three segments using a ruler: <image> After that, she can draw the remaining four segments, using the first three as a guide: <image> Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. Input The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw. Output Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above. Examples Input 1 Output 2 Input 2 Output 3 Input 4 Output 4 Submitted Solution: ``` from math import sqrt, floor, ceil a = int(input()) b = floor(sqrt(a)) c = a - b**2 print(2*b+ceil(c/2)) ```
instruction
0
106,167
23
212,334
No
output
1
106,167
23
212,335
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,237
23
212,474
Tags: greedy, math, sortings Correct Solution: ``` x = int(input()) y = list(map(int, input().split())) a = int(x/2) b = 0 c = 0 y.sort() for i in range(a, x): b+=y[i] for i in range(a): c+=y[i] print(b**2+c**2) ```
output
1
106,237
23
212,475
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,238
23
212,476
Tags: greedy, math, sortings Correct Solution: ``` def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def li(): return list(mi()) n=ii() a=li() a.sort() x=y=0 for i in range(n//2): x+=a[i] y+=a[n-i-1] if n%2: y+=a[n//2] print(x*x+y*y) ```
output
1
106,238
23
212,477
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,239
23
212,478
Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) a.sort() mp = n // 2 sl = sum(a[:mp]) sm = sum(a[mp:]) smd = sl**2 + sm**2 print(smd) ```
output
1
106,239
23
212,479
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,240
23
212,480
Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) ar = list(map(int, input().split())) ar.sort() x, y = 0, 0 for i in range((n + 1) // 2): if i * 2 == n - 1: y += ar[i] else: x += ar[i] y += ar[n - i - 1] print(x * x + y * y) ```
output
1
106,240
23
212,481
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,241
23
212,482
Tags: greedy, math, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) a.sort() if n%2==0: d=(n//2) else: d=((n//2)+1)-1 b=sum(a[0:d]) c=sum(a[d:n]) print((b*b)+(c*c)) ```
output
1
106,241
23
212,483
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,242
23
212,484
Tags: greedy, math, sortings Correct Solution: ``` from collections import deque n = int(input()) a = deque(sorted(map(int, input().split()))) up = 0 right = 0 for i in range(n): if i % 2: up += a.popleft() else: right += a.pop() print(up * up + right * right) ```
output
1
106,242
23
212,485
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,243
23
212,486
Tags: greedy, math, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split(" "))) a.sort() sum1=0 sum2=0 for i in range (n): if(i<int(n/2)): sum1+=a[i] else: sum2+=a[i] print(sum1*sum1+sum2*sum2) ```
output
1
106,243
23
212,487
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image>
instruction
0
106,244
23
212,488
Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) u = list(map(int, input().split())) u.sort() a = sum(u[:n // 2]) b = sum(u) - a print(a * a + b * b) ```
output
1
106,244
23
212,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) l.sort() v=n//2 s1=sum(l[:v]) s=sum(l) s2=s-s1 print(pow(s2,2)+pow(s1,2)) ```
instruction
0
106,245
23
212,490
Yes
output
1
106,245
23
212,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` a = int(input()) b = list(map(int, input().split())) X = 0 Y = 0 b.sort() for i in range(0,len(b)): if (i < len(b) // 2): Y += b[i]; else: X += b[i]; print(Y**2 + X**2) ```
instruction
0
106,246
23
212,492
Yes
output
1
106,246
23
212,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` # Aaditya Upadhyay # .............. # ╭━┳━╭━╭━╮╮ # ┃┈┈┈┣▅╋▅┫┃ # ┃┈┃┈╰━╰━━━━━━╮ # ╰┳╯┈┈┈┈┈┈┈┈┈◢▉◣ # ╲┃┈┈┈┈┈┈┈┈┈┈▉▉▉ # ╲┃┈┈┈┈┈┈┈┈┈┈◥▉◤ # ╲┃┈┈┈┈╭━┳━━━━╯ # ╲┣━━━━━━┫ # ………. # .……. /´¯/)………….(\¯`\ # …………/….//……….. …\….\ # ………/….//……………....\….\ # …./´¯/…./´¯\……/¯ `\…..\¯`\ # ././…/…/…./|_…|.\….\….\…\.\ # (.(….(….(…./.)..)...(.\.).).) # .\…………….\/../…....\….\/…………/ # ..\…………….. /……...\………………../ # …..\…………… (………....)……………./ from sys import stdin,stdout from collections import * from math import gcd,floor,ceil st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 INF=float('inf') def solve(): n=inp() l=li() l.sort() i,j=0,n-1 x,y =0,0 c=1 while i<=j: if c: x+=l[j] c=0 j-=1 else: y+=l[i] c=1 i+=1 pr(x*x + y*y) for _ in range(1): solve() ```
instruction
0
106,247
23
212,494
Yes
output
1
106,247
23
212,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` #設定 import sys input = sys.stdin.buffer.readline #ライブラリインポート from collections import defaultdict INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): n = int(input()) a = getlist() a = sorted(a) x = 0 y = 0 for i in range(int(n // 2)): x += a[i] y = sum(a) - x ans = (x ** 2) + (y ** 2) print(ans) if __name__ == '__main__': main() ```
instruction
0
106,248
23
212,496
Yes
output
1
106,248
23
212,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` n = int(input('')) a = list(map(int,input('').split(' '))) a.sort() r = n//2 t = sum(a) s = 0 for i in range(n//2): s = s + a[i]**2 t = t-s print(t**2 + s**2) ```
instruction
0
106,249
23
212,498
No
output
1
106,249
23
212,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` import math n = int(input()) ar = list(sorted(list(map(int, input().split(' '))))) x = n//2 a, b = (0, 0) for idx, num in enumerate(ar): if idx < x: a += num else: b += num print(int(math.pow(a, 2) + math.pow(b, 2))) ```
instruction
0
106,250
23
212,500
No
output
1
106,250
23
212,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` # cf 1248 B 900 import math n = int(input()) A = [*map(int, input().split())] A.sort(reverse=True) w, h = 0, 0 i, j = 0, len(A) - 1 while i < j: w += A[i] i += 1 h += A[j] j -= 1 if i == j: w += A[i] print(w, h) print(w*w + h*h) ```
instruction
0
106,251
23
212,502
No
output
1
106,251
23
212,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` # B. Выращивание дерева a = int(input()) b = input().split() X = 0 Y = 0 b.sort() for i in range(0,len(b)): if (i < a / 2): Y += int(b[i]); else: X += int(b[i]); print(Y**2 + X**2) ```
instruction
0
106,252
23
212,504
No
output
1
106,252
23
212,505
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,289
23
212,578
Tags: brute force, implementation, math Correct Solution: ``` t = int(input()) for _ in range(t): a1, b1 = map(int, input().split()) a2, b2 = map(int, input().split()) x1 = min(a1, b1) + min(a2, b2) if max(a1, b1) == max(a2, b2): if x1 == max(a1, b1): print("YES") else: print("NO") else: print("NO") ```
output
1
106,289
23
212,579
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,290
23
212,580
Tags: brute force, implementation, math Correct Solution: ``` for _ in range(int(input())): a = list(map(int,input().split())) b = list(map(int,input().split())) print('YES') if min(a)==(abs(b[1]-b[0])) and max(a)==max(b) else print('NO') ```
output
1
106,290
23
212,581
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,291
23
212,582
Tags: brute force, implementation, math Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): pass # 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() def test(): r1 = sorted(map(int, input().split())) r2 = sorted(map(int, input().split())) return ['No', 'Yes'][r1[0] + r2[0] == r1[1] == r2[1]] t = int(input()) for _ in range(t): print(test()) ```
output
1
106,291
23
212,583
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,292
23
212,584
Tags: brute force, implementation, math Correct Solution: ``` num = int(input()) results = [] for T in range(num): x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] """ x[0] y[1] |--- | --| x[1] | | | y[0] |___ | __| x[0] x[1] |--------| |--------| y[0] |________| y[1] x[0] y[0] |--- | --| x[1] | | | y[1] |___ | __| x[1] y[1] |--- | --| x[0] | | | y[0] |___ | __| x[1] y[0] |--- | --| x[0] | | | y[1] |___ | __| """ result = \ ((x[1] == y[0]) and (x[1] == x[0] + y[1])) or \ ((x[1] == y[1]) and (x[1] == x[0] + y[0])) or \ ((x[0] == y[0]) and (x[0] == x[1] + y[1])) or \ ((x[0] == y[1]) and (x[0] == x[1] + y[0])) or \ ((y[1] == x[0]) and (y[1] == y[0] + x[1])) or \ ((y[1] == x[1]) and (y[1] == y[0] + x[0])) or \ ((y[0] == x[0]) and (y[0] == y[1] + x[1])) or \ ((y[0] == x[1]) and (y[0] == y[1] + x[0])) results.append(result) for result in results: print("Yes" if result else "No") ```
output
1
106,292
23
212,585
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,293
23
212,586
Tags: brute force, implementation, math Correct Solution: ``` import math n=int(input()) for i in range(n): a=list(map(int,input().split())) b=list(map(int,input().split())) if(a[0]==b[0] and a[1]+b[1]==a[0]): print("Yes") elif(a[0]==b[1] and a[1]+b[0]==a[0]): print("Yes") elif(a[1]==b[0] and a[0]+b[1]==a[1]): print("Yes") elif(a[1]==b[1] and a[0]+b[0]==a[1]): print("Yes") else: print("No") ```
output
1
106,293
23
212,587
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,294
23
212,588
Tags: brute force, implementation, math Correct Solution: ``` from itertools import combinations t = int(input()) for i in range(t): a1, b1 = input().split() a2, b2 = input().split() f = 0 if a1 == a2: if int(a1) == int(b1) + int(b2): print("YES") f = 1 if a1 == b2: if int(a1) == int(a2) + int(b1): print("YES") f = 1 if b1 == a2: if int(b1) == int(a1) + int(b2): print("YES") f = 1 if b1 == b2: if int(b1) == int(a2) + int(a1): print("YES") f = 1 if f == 0: print("NO") ```
output
1
106,294
23
212,589
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,295
23
212,590
Tags: brute force, implementation, math Correct Solution: ``` t=int(input()) for _ in range(t): arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) arr3=[i for i in arr1 for j in arr2 if i==j] c1=0 c2=0 if(len(arr3)==0): print("No") continue #print(arr3) arr3[0]=max(arr3) for i in arr1: if arr3[0]!=i: c1=i for i in arr2: if arr3[0]!=i: c2=i #print(c1,c2) if arr3[0]==c1+c2: print("Yes") else: print("No") ```
output
1
106,295
23
212,591
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No
instruction
0
106,296
23
212,592
Tags: brute force, implementation, math Correct Solution: ``` # Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. # Input # The first line contains an integer t # (1≤t≤104) — the number of test cases in the input. Then t # test cases follow. # Each test case is given in two lines. # The first line contains two integers a1 # and b1 (1≤a1,b1≤100 # ) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). # The second line contains two integers a2 # and b2 (1≤a2,b2≤100 # ) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). # Output # Print t # answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). def fun(a,b,c,d): if a ==b or c==d: return False if max(a,b)==max(c,d) and min(a,b) + min(c,d) == max(a,b): return True return False for _ in range(int(input())): a,b = list(map(int,input().split())) c,d = list(map(int,input().split())) if fun(a,b,c,d): print("Yes") else: print("No") ```
output
1
106,296
23
212,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` t = int(input()) for _ in range(t) : n = [ int(i) for i in input().split() ] m = [ int(i) for i in input().split() ] ans = False if ( n[0] == m[0] and n[1]+m[1] == n[0] ) : ans = True elif ( n[0] == m[1] and n[1]+m[0] == n[0] ) : ans = True elif ( n[1] == m[0] and n[0]+m[1] == n[1] ) : ans = True elif ( n[1] == m[1] and n[0]+m[0] == n[1] ) : ans = True if ( ans ) : print("Yes") else : print("No") ```
instruction
0
106,297
23
212,594
Yes
output
1
106,297
23
212,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` def sqr(a,b): if max(sq1)==max(sq2): if min(sq1)+min(sq2)==max(sq1): return 'YES' return 'NO' n=int(input()) ans=[] for i in range(n): sq1=list(map(int,input().split())) sq2 = list(map(int, input().split())) ans.append(sqr(sq1,sq2)) for i in ans: print(i) ```
instruction
0
106,298
23
212,596
Yes
output
1
106,298
23
212,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` t=int(input()) for i in range(t): a, b=map(int,input().split()) c, d=map(int,input().split()) if a==d and a == b+c: print("YES") elif a==c and a==b+d: print("YES") elif b==d and b==a+c: print("YES") elif b==c and b==a+d: print("YES") else: print("NO") ```
instruction
0
106,299
23
212,598
Yes
output
1
106,299
23
212,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` for i in range(int(input())): a,b=sorted(map(int,input().split())) n,m=sorted(map(int,input().split())) if a+n==b==m: print('YES') else: print('NO') ```
instruction
0
106,300
23
212,600
Yes
output
1
106,300
23
212,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` def getLines(num): inputLines = [] for i in range(0,num): line = input() if line: inputLines.append(line) else: break return inputLines def notZeroPow(num,p): return True if num >= 1 and num <= pow(10,p) else False readCount = int(input()) if notZeroPow(readCount,4): lines = getLines(readCount*2) results = [] if len(lines) > 0: for i in range(0,len(lines),2): arr = lines[i].split() arr2 = lines[i+1].split() c = ( int(arr[0]) * int(arr[1]) ) % ( int(arr2[0]) * int(arr2[1]) ) t = int(arr[0]) != int(arr[1]) and int(arr2[0]) != int(arr2[1]) results.append(t and c == 0 ) for e in results: print("Yes" if e else "No") ```
instruction
0
106,301
23
212,602
No
output
1
106,301
23
212,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` from math import sqrt as s for _ in range(int(input())): a,b = map(int,input().split()) c,d = map(int,input().split()) total = a+b+c+d temp = -1 if a==c: total = total-a-c temp=a elif a==d: total = total-a-d temp=a elif b==c: total = total-b-c temp=b elif b==d: total = total-b-d temp=b if total==temp: print('YES') else: print('NO') ```
instruction
0
106,302
23
212,604
No
output
1
106,302
23
212,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` n=int(input()) for x in range(n): l=set() a,b=map(int,input().strip().split()) c,d=map(int,input().strip().split()) s=a+b+c+d for x in range(1,int(s**(1/2)+1)): if x**2==s: print('Yes') break else: print('No') ```
instruction
0
106,303
23
212,606
No
output
1
106,303
23
212,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` x =int(input()) while(x>0): l1= input() l1.split(' ') l1a=[] l2a=[] for i in l1: if(i!=' '): l1a.append(int(i)) if(l1a[0]<=l1a[1]): min1=l1a[0] l1other=l1a[1] else: min1 = l1a[1] l1other=l1a[0] l2 = input() l2.split(' ') for i in l2: if(i!=' '): l2a.append(int(i)) if(l2a[0]<=l2a[1]): min1=l2a[0] l2other=l2a[1] else: min2 = l2a[1] l2other=l2a[0] summin=min1+min2 if(summin==l1other & l2other==summin): print("Yes\n") else: print("No\n") x-=1 ```
instruction
0
106,304
23
212,608
No
output
1
106,304
23
212,609
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,460
23
212,920
Tags: geometry Correct Solution: ``` import os import sys from io import BytesIO, IOBase import math def main(): pass BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def binary(n): return (bin(n).replace("0b", "")) def decimal(s): return (int(s, 2)) def pow2(n): p = 0 while (n > 1): n //= 2 p += 1 return (p) def primeFactors(n): l=[] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n / i if n > 2: l.append(int(n)) return (l) def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) def maxPrimeFactors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime) w,h,a=map(int,input().split()) if(a==0 or a==180): print(w*h) else: w,h=max(w,h),min(w,h) if(a>90): a=180-a a=(a*math.pi)/180 #print(h*(1+math.cos(a)),w*math.sin(a)) if(h*(1+math.cos(a))< w*math.sin(a)): print(pow(h,2)/math.sin(a)) else: #print("HEY") #print(math.sin(a)) x=h-w*((math.cos(a)+1)/math.sin(a)) t=math.tan(a)-((math.cos(a)+1)*(math.cos(a)+1)/(math.cos(a)*math.sin(a))) x=x/t x=abs(x) b2=w-x-(x/math.cos(a)) b2=abs(b2) h2=b2/math.tan(a) h2=abs(h2) h1=h-h2-(h2/math.cos(a)) h1=abs(h1) tbm=((x*h1)+(b2*h2)) #print(x,h1,h2,b2) print((h*w)-tbm) ```
output
1
106,460
23
212,921
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,461
23
212,922
Tags: geometry Correct Solution: ``` #!/usr/bin/python3 from math import sin, cos, pi, atan2 w, h, a = tuple(map(int, input().split())) if a in [0, 180]: print(w * h) elif a == 90: print(min(w, h)**2) else: a *= pi / 180 w /= 2 h /= 2 base = [(w, h), (-w, h), (-w, -h), (w, -h)] rot = [(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)) for x, y in base] pol = [] for i, j in zip(range(-1, 3), range(4)): t = (w - rot[i][0]) / (rot[j][0] - rot[i][0]) if 0 <= t <= 1: pol.append((w, rot[i][1] + (rot[j][1] - rot[i][1]) * t)) t = (-w - rot[i][0]) / (rot[j][0] - rot[i][0]) if 0 <= t <= 1: pol.append((-w, rot[i][1] + (rot[j][1] - rot[i][1]) * t)) t = (h - rot[i][1]) / (rot[j][1] - rot[i][1]) if 0 <= t <= 1: pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, h)) t = (-h - rot[i][1]) / (rot[j][1] - rot[i][1]) if 0 <= t <= 1: pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, -h)) pol.sort(key=lambda x: atan2(*x)) print('%0.9f' % (sum([abs(pol[i][0] * pol[j][1] - pol[i][1] * pol[j][0]) for i, j in zip(range(-1, len(pol) - 1), range(len(pol)))]) / 2)) ```
output
1
106,461
23
212,923
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,462
23
212,924
Tags: geometry Correct Solution: ``` import sys import math def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, 'r') w, h, a = map(int, f.readline().split()) return w, h, a def sol(w, h, a): 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) res = area - 2 * bigger_area - 2 * lower_area else: res = h * h / math.sin(a) return [f"{res}"] def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__ == '__main__': main() ```
output
1
106,462
23
212,925
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,463
23
212,926
Tags: geometry Correct Solution: ``` import math from decimal import * getcontext().prec = 40 EPS = Decimal(0.000000000000000000001) PI = Decimal(3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328) def labs(x): if x < 0: return -x return x class Point: def __init__(self, x, y): self.x = x self.y = y def Add(self, p): self.x += p.x self.y += p.y def Sub(self, p): self.x -= p.x self.y -= p.y def Scale(self, v): self.x *= v self.y *= v def Rotate(self, angle): newX = self.x * Decimal(math.cos(angle)) - self.y * Decimal(math.sin(angle)) newY = self.x * Decimal(math.sin(angle)) + self.y * Decimal(math.cos(angle)) self.x = newX self.y = newY def Equals(self, p): if Decimal(labs(p.x - self.x)) < EPS and Decimal(labs(p.y - self.y)) < EPS: return True return False class Line: def __init__(self, start, end): self.start = start self.end = end def GetIntersection(self, l): a = Point(self.start.x, self.start.y) b = Point(self.end.x, self.end.y) c = Point(l.start.x, l.start.y) d = Point(l.end.x, l.end.y) ab = Point(self.end.x, self.end.y) cd = Point(l.end.x, l.end.y) ab.Sub(a) cd.Sub(c) k = Decimal((cd.x * (a.y - c.y) + cd.y * (c.x - a.x)) / (ab.x * cd.y - ab.y * cd.x)) ab.Scale(k) a.Add(ab) return a class Polygon: def __init__(self, vertices): self.vertices = vertices def GetArea(self): area = Decimal(0) for i in range(0, len(self.vertices)): area += self.vertices[i].x * self.vertices[(i + 1) % len(self.vertices)].y - self.vertices[(i + 1) % len(self.vertices)].x * self.vertices[i].y return Decimal(labs(area)) / Decimal(2) x, y, alpha = input().split() x = Decimal(x) y = Decimal(y) if x < y: tmp = x x = y y = tmp alpha = Decimal(alpha) singleArea = x * y if alpha > 90: alpha = Decimal(180) - alpha if alpha == 0: print(singleArea) exit() alpha = alpha * PI / Decimal(180) a = Point(x / Decimal(2), y / Decimal(2)) b = Point(x / Decimal(2), -y / Decimal(2)) c = Point(-x / Decimal(2), -y / Decimal(2)) d = Point(-x / Decimal(2), y / Decimal(2)) e = Point(a.x, a.y) f = Point(b.x, b.y) g = Point(c.x, c.y) h = Point(d.x, d.y) e.Rotate(alpha) f.Rotate(alpha) g.Rotate(alpha) h.Rotate(alpha) ab = Line(a, b) bc = Line(b, c) cd = Line(c, d) da = Line(d, a) ef = Line(e, f) fg = Line(f, g) gh = Line(g, h) he = Line(h, e) area = 0 if a.Equals(f): t1 = Polygon([he.GetIntersection(da), e, f]) t2 = Polygon([fg.GetIntersection(bc), g, h]) area = singleArea - t1.GetArea() - t2.GetArea() elif f.y > a.y: p1 = Polygon([he.GetIntersection(da), e, f, fg.GetIntersection(da)]) p2 = Polygon([fg.GetIntersection(bc), g, h, he.GetIntersection(bc)]) area = singleArea - p1.GetArea() - p2.GetArea() else: t1 = Polygon([da.GetIntersection(he), e, ef.GetIntersection(da)]) t2 = Polygon([ef.GetIntersection(ab), f, fg.GetIntersection(ab)]) t3 = Polygon([fg.GetIntersection(bc), g, gh.GetIntersection(bc)]) t4 = Polygon([gh.GetIntersection(cd), h, he.GetIntersection(cd)]) area = singleArea - t1.GetArea() - t2.GetArea() - t3.GetArea() - t4.GetArea() print(area) ```
output
1
106,463
23
212,927
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,464
23
212,928
Tags: geometry Correct Solution: ``` from math import sin,cos,tan PI = 3.141592653589793238463 [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) ```
output
1
106,464
23
212,929
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,465
23
212,930
Tags: geometry Correct Solution: ``` from math import * w,h,alpha = [int(x) for x in input().strip().split()] if alpha > 90 : alpha = 180 - alpha if w < h: w,h = h,w c = cos(alpha * pi / 180.0) s = sin(alpha * pi / 180.0) t = tan(alpha * pi / 360.0) print(h * h / s) if t > h / w else print( (w * h - (w * w + h * h) / 2 * tan(alpha * pi / 360.0)) / (c)) ```
output
1
106,465
23
212,931
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,466
23
212,932
Tags: geometry Correct Solution: ``` from math import sin, cos, tan, atan, pi def main(): w, h, a = map(int, input().split()) a = min(a, 180 - a) * pi / 180 if h > w: h, w = w, h if h * (1 + cos(a)) < w * sin(a): res = h * h / sin(a) else: res = h * w - ((w - h * tan(a / 2)) ** 2 * tan(a) + (h - w * tan(a / 2)) ** 2 * tan(a)) / 4 print('{:.9f}'.format(res)) if __name__ == '__main__': main() # Made By Mostafa_Khaled ```
output
1
106,466
23
212,933