message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,163 | 23 | 112,326 |
Tags: geometry, implementation
Correct Solution:
```
import math
eps = 1e-3
def dis(p1, p2):
return math.sqrt((p1[0]-p2[0])*(p1[0]-p2[0]) + (p1[1]-p2[1])*(p1[1]-p2[1]))
def getArea(p1, p2, p3):
A = p1[0]-p2[0]
B = p1[1]-p2[1]
x = (p3[0]*A*A + p3[1]*A*B + p1[0]*B*B - p1[1]*A*B) / (A*A+B*B)
y = (p1[1]-p2[1]) * (x-p1[0]) / (p1[0]-p2[0]) + p1[1]
p4 = (x, y)
return .5 * dis(p1, p2) * dis(p3, p4)
def main():
x1,y1,x2,y2,x3,y3,x4,y4 = map(int, input().split(' '))
minX = min(x1,x2,x3,x4)
maxX = max(x1,x2,x3,x4)
minY = min(y1,y2,y3,y4)
maxY = max(y1,y2,y3,y4)
x1,y1,x2,y2,x3,y3,x4,y4 = map(int, input().split(' '))
square_area = dis((x1,y1), (x2,y2)) * dis((x1,y1), (x2,y2))
for i in range(minX, maxX+1):
for j in range(minY, maxY+1):
area1 = getArea((x1,y1), (x2,y2), (i, j))
area2 = getArea((x2,y2), (x3,y3), (i, j))
area3 = getArea((x3,y3), (x4,y4), (i, j))
area4 = getArea((x4,y4), (x1,y1), (i, j))
if ((area1 + area2 + area3 + area4) - (square_area) < eps):
print("YES")
return
print("NO")
main()
``` | output | 1 | 56,163 | 23 | 112,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,164 | 23 | 112,328 |
Tags: geometry, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(A, B):
AX = []
AY = []
BX = []
BY = []
for i in range(0, 8 , 2):
AX.append(A[i])
BX.append(B[i])
AY.append(A[i+1])
BY.append(B[i+1])
AX_MIN = min(AX)
AX_MAX = max(AX)
AY_MIN = min(AY)
AY_MAX = max(AY)
BXC = (min(BX)+max(BX))/2
BYC = (min(BY)+max(BY))/2
for i in range(4):
if AX_MIN <= BX[i] <= AX_MAX and AY_MIN <= BY[i] <= AY_MAX:
error_print('1', i)
return 'YES'
if AX_MIN <= BXC <= AX_MAX and AY_MIN <= BYC <= AY_MAX:
error_print('2', i)
return 'YES'
AX_ = [AX[i] + AY[i] for i in range(4)]
AY_ = [AX[i] - AY[i] for i in range(4)]
BX_ = [BX[i] + BY[i] for i in range(4)]
BY_ = [BX[i] - BY[i] for i in range(4)]
AX = BX_
AY = BY_
BX = AX_
BY = AY_
AX_MIN = min(AX)
AX_MAX = max(AX)
AY_MIN = min(AY)
AY_MAX = max(AY)
BXC = (min(BX)+max(BX))/2
BYC = (min(BY)+max(BY))/2
for i in range(4):
if AX_MIN <= BX[i] <= AX_MAX and AY_MIN <= BY[i] <= AY_MAX:
error_print('3', i)
return 'YES'
if AX_MIN <= BXC <= AX_MAX and AY_MIN <= BYC <= AY_MAX:
error_print('4', i)
return 'YES'
return 'NO'
def main():
A = read_int_n()
B = read_int_n()
print(slv(A, B))
if __name__ == '__main__':
main()
``` | output | 1 | 56,164 | 23 | 112,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,165 | 23 | 112,330 |
Tags: geometry, implementation
Correct Solution:
```
nor = list(map(int, input().split()))
diag = list(map(int, input().split()))
sx = min(diag[i] for i in range(0, 8, 2))
mx = max(diag[i] for i in range(0, 8, 2))
sy = min(diag[i] for i in range(1, 8, 2))
my = max(diag[i] for i in range(1, 8, 2))
nsx = min(nor[i] for i in range(0, 8, 2))
nmx = max(nor[i] for i in range(0, 8, 2))
nsy = min(nor[i] for i in range(1, 8, 2))
nmy = max(nor[i] for i in range(1, 8, 2))
dist = mx - sx
mid = (my + sy) // 2
for y in range(sy, my + 1):
ach = abs(y - mid)
for x in range(sx + ach, mx - ach + 1):
if nsx <= x <= nmx and nsy <= y <= nmy:
print("YES")
exit()
print("NO")
``` | output | 1 | 56,165 | 23 | 112,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,166 | 23 | 112,332 |
Tags: geometry, implementation
Correct Solution:
```
def dist(A,B):
return abs(A[0]-B[0]) + abs(A[1]-B[1])
A = [int(x) for x in input().split()]
XA = (A[::2])
YA = A[1::2]
Xmin,Xmax = min(XA),max(XA)
Ymin,Ymax = min(YA),max(YA)
B = [int(x) for x in input().split()]
XB = sum(B[::2])//4
YB = sum(B[1::2])//4
can = False
for i in range(0,len(B),2):
x = B[i]
y = B[i+1]
if x <= Xmax and x >= Xmin and y <= Ymax and y >= Ymin:
can = True
if XB <= Xmax and XB >= Xmin and YB <= Ymax and YB >= Ymin:
can = True
for i in range(0,len(A),2):
if dist((XB,YB),(A[i],A[i+1])) <= dist((XB,YB),(B[0],B[1])):
can = True
print("YES" if can else "NO")
``` | output | 1 | 56,166 | 23 | 112,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,167 | 23 | 112,334 |
Tags: geometry, implementation
Correct Solution:
```
one = list(map(int, input().split()))
two = list(map(int, input().split()))
one_ = sorted([(one[i], one[i + 1]) for i in range(0, 8, 2)], key=lambda x: (x[1], x[0]))
two_ = sorted([(two[i], two[i + 1]) for i in range(0, 8, 2)], key=lambda x: (x[1], x[0]))
ones = [one_[0], one_[2], one_[3], one_[1]]
twos = [two_[1], two_[3], two_[2], two_[0]]
L, D, U, R = ones[0][0], ones[0][1], ones[2][1], ones[2][0]
def in_one(point):
x, y = point
return L <= x <= R and D <= y <= U
def in_two(point):
x_0, y_0 = twos[0]
def U_p(x_):
return x_ + y_0 - x_0
def D_m(x_):
return -x_ + y_0 + x_0
x_1, y_1 = twos[2]
def U_m(x_):
return -x_ + y_1 + x_1
def D_p(x_):
return x_ + y_1 - x_1
x, y = point
return D_m(x) <= y <= U_p(x) and D_p(x) <= y <= U_m(x)
c_one = ((L + R) / 2, (U + D) / 2)
c_two = ((twos[0][0] + twos[2][0]) / 2, (twos[1][1] + twos[3][1]) / 2)
ones.append(c_one)
twos.append(c_two)
for p in ones:
if in_two(p):
print('YES')
exit()
for p in twos:
if in_one(p):
print('YES')
exit()
print('NO')
``` | output | 1 | 56,167 | 23 | 112,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,168 | 23 | 112,336 |
Tags: geometry, implementation
Correct Solution:
```
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = min(a[0::2])
d = max(a[0::2])
e = min(a[1::2])
f = max(a[1::2])
g = sum(b[0::2])//4
h = sum(b[1::2])//4
r = abs(b[0]-g)+abs(b[1]-h)
for i in range(c, d+1):
for j in range(e, f+1):
if abs(i-g)+abs(j-h) <= r:
print('YES')
exit()
print('NO')
# Made By Mostafa_Khaled
``` | output | 1 | 56,168 | 23 | 112,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,169 | 23 | 112,338 |
Tags: geometry, implementation
Correct Solution:
```
from sys import exit
from operator import itemgetter
def read():
x1, y1, x2, y2, x3, y3, x4, y4 = map(int, input().split())
return [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
a = read()
b = read()
def calc(ls):
s = 0
for i in range(len(ls)):
a = ls[i]
b = ls[(i+1)%len(ls)]
s += a[0] * b[1] - a[1] * b[0]
return abs(s) / 2
def contain(sq, po):
area = calc(sq)
s = 0
for i in range(len(sq)):
s += calc([sq[i], sq[(i+1)%len(sq)], po])
return abs(s - area) < 1e-3
for x in b:
if contain(a, x):
print("Yes")
exit(0)
for x in a:
if contain(b, x):
print("Yes")
exit(0)
x = sum(map(itemgetter(0), a)) / 4
y = sum(map(itemgetter(1), a)) / 4
if contain(b, (x, y)):
print("Yes")
exit(0)
x = sum(map(itemgetter(0), b)) / 4
y = sum(map(itemgetter(1), b)) / 4
if contain(a, (x, y)):
print("Yes")
exit(0)
print("No")
``` | output | 1 | 56,169 | 23 | 112,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image> | instruction | 0 | 56,170 | 23 | 112,340 |
Tags: geometry, implementation
Correct Solution:
```
def onseg(p,q,r):
return min(p[0], r[0]) <= q[0] <= max(p[0], r[0]) and \
min(p[1], r[1]) <= q[1] <= max(p[1], r[1])
def orientation(p,q,r):
val = (q[1] - p[1]) * (r[0] - q[0]) - \
(q[0] - p[0]) * (r[1] - q[1])
if (val == 0): return 0 # colinear
return 1 if val > 0 else 2 # clock or counterclock wise
def doint(p1, q1, p2, q2):
o1 = orientation(p1, q1, p2)
o2 = orientation(p1, q1, q2)
o3 = orientation(p2, q2, p1)
o4 = orientation(p2, q2, q1)
if o1 != o2 and o3 != o4:
return True
if o1 == 0 and onseg(p1, p2, q1): return True
if o2 == 0 and onseg(p1, q2, q1): return True
if o3 == 0 and onseg(p2, p1, q2): return True
if o4 == 0 and onseg(p2, q1, q2): return True
return False
x0,y0,x1,y1,x2,y2,x3,y3 = map(int,input().split())
x4,y4,x5,y5,x6,y6,x7,y7 = map(int,input().split())
A = x0,y0
B = x1,y1
C = x2,y2
D = x3,y3
a = x4,y4
b = x5,y5
c = x6,y6
d = x7,y7
if doint(A,B,a,b) or doint(A,C,a,b) or doint(A,D,a,b) or doint(B,C,a,b) or doint(B,D,a,b) or doint(C,D,a,b) or \
doint(A,B,a,c) or doint(A,C,a,c) or doint(A,D,a,c) or doint(B,C,a,c) or doint(B,D,a,c) or doint(C,D,a,c) or \
doint(A,B,a,d) or doint(A,C,a,d) or doint(A,D,a,d) or doint(B,C,a,d) or doint(B,D,a,d) or doint(C,D,a,d) or \
doint(A,B,b,c) or doint(A,C,b,c) or doint(A,D,b,c) or doint(B,C,b,c) or doint(B,D,b,c) or doint(C,D,b,c) or \
doint(A,B,b,d) or doint(A,C,b,d) or doint(A,D,b,d) or doint(B,C,b,d) or doint(B,D,b,d) or doint(C,D,b,d) or \
doint(A,B,c,d) or doint(A,C,c,d) or doint(A,D,c,d) or doint(B,C,c,d) or doint(B,D,c,d) or doint(C,D,c,d):
print('YES')
else:
print('NO')
``` | output | 1 | 56,170 | 23 | 112,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
def leftmost(a, b):
rx = 1000
ry = 1000
t = 0
for i in range(4):
if rx > a[i] or (rx == a[i] and ry > b[i]):
rx = a[i]
ry = b[i]
t = i
return t
x = [0] * 4
y = [0] * 4
a = [0] * 4
b = [0] * 4
p = list(map(int, input().split()))
q = list(map(int, input().split()))
for i in range(4):
x[i] = p[i * 2]
y[i] = p[i * 2 + 1]
for i in range(4):
a[i] = -q[i * 2]
b[i] = -q[i * 2 + 1]
sx = leftmost(x, y)
sa = leftmost(a, b)
if x[(sx + 1) % 4] - x[sx] == 0:
x.reverse()
y.reverse()
sx = leftmost(x, y)
if b[(sa + 1) % 4] - b[sa] > 0:
a.reverse()
b.reverse()
sa = leftmost(a, b)
rx = [0] * 9
ry = [0] * 9
rx[0] = x[sx] + a[sa]
ry[0] = y[sx] + b[sa]
a *= 2
b *= 2
x *= 2
y *= 2
j = 0
for i in range(4):
rx[j + 1] = rx[j] + a[sa + i + 1] - a[sa + i]
ry[j + 1] = ry[j] + b[sa + i + 1] - b[sa + i]
j += 1
rx[j + 1] = rx[j] + x[sx + i + 1] - x[sx + i]
ry[j + 1] = ry[j] + y[sx + i + 1] - y[sx + i]
j += 1
sum = 0
absSum = 0
for i in range(8):
absSum += abs(rx[i] * ry[i + 1] - rx[i + 1] * ry[i])
sum += rx[i] * ry[i + 1] - rx[i + 1] * ry[i]
if abs(sum) == absSum:
print("YES")
else:
print("NO")
``` | instruction | 0 | 56,171 | 23 | 112,342 |
Yes | output | 1 | 56,171 | 23 | 112,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
from sys import stdin,exit
def listinput():
return list(map(int,stdin.readline().rstrip().split()))
a = listinput()
b = listinput()
x1,y1,x2,y2 = min(a[0],a[2],a[4],a[6]),min(a[1],a[3],a[5],a[7]),max(a[0],a[2],a[4],a[6]),max(a[1],a[3],a[5],a[7])
lx,rx = min(b[0],b[2],b[4],b[6]),max(b[0],b[2],b[4],b[6])
ty,by = max(b[1],b[3],b[5],b[7]),min(b[1],b[3],b[5],b[7])
my = (ty+by)//2
mx = (lx+rx)//2
#print(x1,y1,x2,y2)
#print(lx,rx,ty,by,my,mx)
def inside(x,y):
if (y-my)<=(x-lx) and (y-ty)<=-(x-mx) and (y-by)>=(x-mx) and (y-my)>=-(x-lx):
return True
return False
for i in range(x1,x2+1):
for j in range(y1,y2+1):
if inside(i,j):
print('YES')
exit(0)
print('NO')
``` | instruction | 0 | 56,172 | 23 | 112,344 |
Yes | output | 1 | 56,172 | 23 | 112,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
import sys
from fractions import Fraction
def read_ints():
return [int(_) for _ in sys.stdin.readline().split(' ')]
def read_points():
a = read_ints()
a = [Fraction(_) for _ in a]
a = zip(a[::2], a[1::2])
a = list(a)
return a
def rotate(a):
return [(p[0] + p[1], p[0] - p[1]) for p in a]
def check(a, b):
def check_side(p, q):
t1 = Fraction(p[0] - d, p[0] - q[0])
t2 = Fraction(p[0] - 0, p[0] - q[0])
if t2 < t1:
t1, t2 = t2, t1
if t2 < 0 or t1 > 1:
return False
t1 = max(0, t1)
t2 = min(1, t2)
y1 = p[1] + t1 * (q[1] - p[1])
y2 = p[1] + t2 * (q[1] - p[1])
if y2 < y1:
y1, y2 = y2, y1
return not(y1 > d or y2 < 0)
m = min(a)
a = [(p[0] - m[0], p[1] - m[1]) for p in a]
b = [(p[0] - m[0], p[1] - m[1]) for p in b]
d = abs(a[1][1] - a[0][1] + a[1][0] - a[0][0])
if check_side(b[0], b[1]):
return True
if check_side(b[1], b[2]):
return True
if check_side(b[2], b[3]):
return True
if check_side(b[3], b[0]):
return True
return False
if __name__ == '__main__':
a = read_points()
b = read_points()
print('YES' if check(a, b) or check(rotate(b), rotate(a)) else 'NO')
``` | instruction | 0 | 56,173 | 23 | 112,346 |
Yes | output | 1 | 56,173 | 23 | 112,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
class vec():
def __init__(self, x, y=None):
if y is None:
x, y = x
self.x = x
self.y = y
def __mod__(self, other):
return self.x*other.y - self.y*other.x
def __sub__(self, other):
return vec(self.x - other.x, self.y - other.y)
def __repr__(self):
return 'vec({}, {})'.format(self.x, self.y)
def lines_cross(a, b, c, d):
ab, ac, ad = b - a, c - a, d - a
cd, ca, cb = d - c, a - c, b - c
return (ab % ac) * (ab % ad) <= 0 and (cd % ca) * (cd % cb) <= 0
def rot(a):
return vec(a.x-a.y, a.x+a.y)
ax, ay, bx, by, cx, cy, dx, dy = map(int, input().split())
kx, ky, lx, ly, mx, my, nx, ny = map(int, input().split())
c, b, d, a = map(vec, sorted([(ax, ay), (bx, by), (cx, cy), (dx, dy)]))
m, n, l, k = map(vec, sorted([(kx, ky), (lx, ly), (mx, my), (nx, ny)]))
res = False
s1 = [a, b, c, d]
s2 = [k, l, m, n]
for i in range(4):
for j in range(4):
if lines_cross(s1[i], s1[(i+1)%4], s2[j], s2[(j+1)%4]):
res = True
break
if res:
break
if all([b.x <= p.x <= a.x and c.y <= p.y <= b.y for p in [k, l, m ,n]]):
res = True
if all([rot(l).x <= rot(p).x <= rot(k).x and rot(m).y <= rot(p).y <= rot(l).y for p in [a, b, c ,d]]):
res = True
print('YES' if res else 'NO')
``` | instruction | 0 | 56,174 | 23 | 112,348 |
Yes | output | 1 | 56,174 | 23 | 112,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
# -*- coding: utf-8 -*-
from math import *
a = input().split()
b = input().split()
for i in range(len(a)):
a[i] = int(a[i])
b[i] = int(b[i])
l = False
r = False
for i in range(len(a)-1):
if a[i] >= b[i] and a[1+i] > b[i+1]:
r = True
if a[i] <= b[i] and a[1+i] < b[i+1]:
l = True
if a[i] > b[i] and a[1+i] >= b[i+1]:
r = True
if a[i] < b[i] and a[1+i] <= b[i+1]:
l = True
if a[i] == b[i] and a[1+i] == b[i+1]:
print("YES")
exit()
if l and r:
print("YES")
else:
print("NO")
``` | instruction | 0 | 56,175 | 23 | 112,350 |
No | output | 1 | 56,175 | 23 | 112,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
import math
[a1,b1,a2,b2,a3,b3,a4,b4] = [int(x) for x in input().split()]
[x1,y1,x2,y2,x3,y3,x4,y4] = [int(x) for x in input().split()]
knote = [[a1,b1],[a2,b2],[a3,b3],[a4,b4]]
xknote = [[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
ab = [[[a1,b1],[a2,b2]],[[a2,b2],[a3,b3]],[[a3,b3],[a4,b4]],[[a4,b4],[a1,b1]]]
xy = [[[x1,y1],[x2,y2]],[[x2,y2],[x3,y3]],[[x3,y3],[x4,y4]],[[x4,y4],[x1,y1]]]
def kreuz(a,b):
return a[0]*b[1] - b[0]*a[1]
def pdc(a,b):
return a[0]*b[0] + a[1]*b[1]
def vec(a,b):
return [a[0]-b[0],a[1]-b[1]]
Q = [150,y1]
flag1 = 0
flag2 = 0
flag3 = 0
for i in range(0,4):
if kreuz(vec([x1,y1],knote[i]),vec(ab[i][0],ab[i][1])) == 0 and max(ab[i][0][0],ab[i][1][0]) >= x1 >= min(ab[i][0][0],ab[i][1][0]) and max(ab[i][0][1],ab[i][1][1]) >= y1 >= min(ab[i][0][1],ab[i][1][1]):
print('YES')
flag1 = 100
break
if flag1 == 0:
if min(a1,a2,a3,a4) < x1 < max(a1,a2,a3,a4) and min(b1,b2,b3,b4) < y1 < max(b1,b2,b3,b4):
print('YES')
flag2 = 100
if flag1 != 100 and flag2 != 100:
for i in range(0,4):
for j in range(0,4):
minRX, minTX = min(ab[i][0][0],ab[i][1][0]), min(xy[j][0][0],xy[j][1][0])
minRY, minTY = min(ab[i][0][1],ab[i][1][1]), min(xy[j][0][1],xy[j][1][1])
maxRX, maxTX = max(ab[i][0][0],ab[i][1][0]), max(xy[j][0][0],xy[j][1][0])
maxRY, maxTY = max(ab[i][0][1],ab[i][1][1]), max(xy[j][0][1],xy[j][1][1])
minFX, minFY = max(minRX, minTX), max(minRY, minTY)
maxFX, maxFY = min(maxRX, maxTX), min(maxRY, maxTY)
if minFX <= maxFX and minFY <= maxFY:
if (kreuz(vec(xy[j][0],ab[i][0]),vec(ab[i][0],ab[i][1]))) * (kreuz(vec(xy[j][1],ab[i][0]),vec(ab[i][0],ab[i][1]))) <= 0:
if (kreuz(vec(ab[j][0],xy[i][0]),vec(xy[i][0],xy[i][1]))) * (kreuz(vec(ab[j][1],xy[i][0]),vec(xy[i][0],xy[i][1]))) <= 0:
flag3 = 100
print('YES')
break
if flag3 == 100:
break
if flag1 != 100 and flag2 != 100 and flag3 != 100:
a1 = 0.5*math.sqrt(2)*a1 + 0.5*math.sqrt(2)*b1
b1 = -0.5*math.sqrt(2)*a1 + 0.5*math.sqrt(2)*b1
for e in xknote:
e[0] = 0.5*math.sqrt(2)*e[0] + 0.5*math.sqrt(2)*e[1]
e[1] = -0.5*math.sqrt(2)*e[0] + 0.5*math.sqrt(2)*e[1]
if min(x1,x2,x3,x4) < a1 < max(x1,x2,x3,x4) and min(y1,y2,y3,y4) < b1 < max(y1,y2,y3,y4):
print('YES')
else:
print('NO')
``` | instruction | 0 | 56,176 | 23 | 112,352 |
No | output | 1 | 56,176 | 23 | 112,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
nor = list(map(int, input().split()))
diag = list(map(int, input().split()))
sx = min(diag[i] for i in range(1, 8, 2))
mx = max(diag[i] for i in range(1, 8, 2))
sy = min(diag[i] for i in range(0, 8, 2))
my = max(diag[i] for i in range(0, 8, 2))
nsx = min(nor[i] for i in range(1, 8, 2))
nmx = max(nor[i] for i in range(1, 8, 2))
nsy = min(nor[i] for i in range(0, 8, 2))
nmy = max(nor[i] for i in range(0, 8, 2))
dist = mx - sx
mid = (my + sy) // 2
for h in range(sy, my + 1):
ach = min(h - sy, my - h)
for i in range(0, dist - 2 * ach + 1):
x, y = sx - ach + i, h
if nsx <= x <= nmx and nsy <= y <= nmy:
print("YES")
exit()
print("NO")
``` | instruction | 0 | 56,177 | 23 | 112,354 |
No | output | 1 | 56,177 | 23 | 112,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.
All the values are integer and between -100 and 100.
Output
Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower).
Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples:
<image> <image> <image>
Submitted Solution:
```
sq1 = list(map(int, input().split()))
sq2 = list(map(int, input().split()))
a1 = min(sq1)
a2 = max(sq1)
if sq2[1] == sq2[5]:
if (a1 > sq2[0] and a1 > sq2[4]) or (a2 < sq2[0] and a2 < sq2[4]):
print("no")
elif (a1 > sq2[3] and a1 > sq2[7]) or (a2 < sq2[3] and a2 < sq2[7]):
print("no")
else:
print("yes")
else:
if (a1 > sq2[1] and a1 > sq2[5]) or (a2 < sq2[1] and a2 < sq2[5]):
print("no")
elif (a1 > sq2[2] and a1 > sq2[6]) or (a2 < sq2[2] and a2 < sq2[6]):
print("no")
else:
print("yes")
``` | instruction | 0 | 56,178 | 23 | 112,356 |
No | output | 1 | 56,178 | 23 | 112,357 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,328 | 23 | 112,656 |
"Correct Solution:
```
while True:
try:
xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = map(float, input().split())
except:
break
if max(xa2, xb2) - min(xa1, xb1) <= xa2 - xa1 + xb2 - xb1 and\
max(ya2, yb2) - min(ya1, yb1) <= ya2 - ya1 + yb2 - yb1:
print('YES')
else:
print('NO')
``` | output | 1 | 56,328 | 23 | 112,657 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,329 | 23 | 112,658 |
"Correct Solution:
```
import sys
f = sys.stdin
# a1γε·¦δΈγa2γε³δΈγ¨γγγ¦γγδΊγγγ€γ³γ
for line in f:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2 = map(float, line.split())
print('NO' if xb2 < xa1 or xa2 < xb1 or yb2 < ya1 or ya2 < yb1 else 'YES')
``` | output | 1 | 56,329 | 23 | 112,659 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,330 | 23 | 112,660 |
"Correct Solution:
```
def solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2):
if xb2<xa1 or xb1>xa2 or yb2<ya1 or yb1>ya2:
print("NO")
else:
print("YES")
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split())
solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2)
except EOFError:
break
``` | output | 1 | 56,330 | 23 | 112,661 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,331 | 23 | 112,662 |
"Correct Solution:
```
while(1):
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2 = [float(i) for i in input().split()]
if xa2 < xb1 or xb2 < xa1 or ya2 < yb1 or yb2 < ya1:
print("NO")
else:
print("YES")
except EOFError:
break
``` | output | 1 | 56,331 | 23 | 112,663 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,332 | 23 | 112,664 |
"Correct Solution:
```
while True:
try:
ls=list(map(float,input().split()))
xok=(ls[0]<=ls[4] and ls[4]<=ls[2])or (ls[0]<=ls[6] and ls[6]<=ls[2])or(ls[4]<=ls[0] and ls[2]<=ls[6])
yok=(ls[1]<=ls[5] and ls[5]<=ls[3])or (ls[1]<=ls[7] and ls[7]<=ls[3])or(ls[5]<=ls[1] and ls[3]<=ls[7])
if xok and yok:print('YES')
else :print('NO')
except:
break
``` | output | 1 | 56,332 | 23 | 112,665 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,333 | 23 | 112,666 |
"Correct Solution:
```
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split())
except EOFError:
break
if xb2<xa1 or xb1>xa2 or yb2<ya1 or yb1>ya2:
print("NO")
else:
print("YES")
``` | output | 1 | 56,333 | 23 | 112,667 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,334 | 23 | 112,668 |
"Correct Solution:
```
import sys
for x in sys.stdin:
a,b,c,d,e,f,g,h=map(float,x.split())
print(['YES','NO'][c<e or g<a or d<f or h<b])
``` | output | 1 | 56,334 | 23 | 112,669 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO | instruction | 0 | 56,335 | 23 | 112,670 |
"Correct Solution:
```
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2 = map(float,input().split())
except:
break
if (min(xa1,xa2) <= max(xb1,xb2) and max(xa1,xa2) >= min(xb1,xb2)) and (min(ya1,ya2) <= max(yb1,yb2) and max(ya1,ya2) >= min(yb1,yb2)):
print("YES")
else:
print("NO")
``` | output | 1 | 56,335 | 23 | 112,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
for s in sys.stdin:
xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = map(float, s.split())
if xb2 < xa1 or xa2 < xb1 or ya2 < yb1 or yb2 < ya1:
print('NO')
else:
print('YES')
``` | instruction | 0 | 56,336 | 23 | 112,672 |
Yes | output | 1 | 56,336 | 23 | 112,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
while 1:
try:ax, ay, bx, by, cx, cy, dx, dy = map(float, input().split())
except:break
if (ax<=dx and cx<=bx) and (ay<=dy and cy<=by):
print('YES')
else:print('NO')
``` | instruction | 0 | 56,337 | 23 | 112,674 |
Yes | output | 1 | 56,337 | 23 | 112,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2 = map(float,input().split())
if xb2 < xa1 or xa2 < xb1:
print("NO")
elif yb1 > ya2 or ya1 > yb2:
print("NO")
else:
print("YES")
except EOFError:
break
``` | instruction | 0 | 56,338 | 23 | 112,676 |
Yes | output | 1 | 56,338 | 23 | 112,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
# Aizu Problem 0059: Intersection of Rectangles
#
import sys, math, os, bisect
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def overlap(x1, y1, x2, y2, x3, y3, x4, y4):
if y3 > y2 or y4 < y1:
return False
if x4 < x1 or x3 > x2:
return False
return True
for line in sys.stdin:
x1, y1, x2, y2, x3, y3, x4, y4 = [float(_) for _ in line.split()]
print("YES" if not overlap(x1, y1, x2, y2, x3, y3, x4, y4) < 1e-10 else "NO")
``` | instruction | 0 | 56,339 | 23 | 112,678 |
Yes | output | 1 | 56,339 | 23 | 112,679 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
def solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2):
if xb2<=xa1 or xb1>=xa2 or yb2<=ya1 or yb1>=ya2:
print("NO")
else:
print("YES")
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split())
solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2)
except EOFError:
break
``` | instruction | 0 | 56,340 | 23 | 112,680 |
No | output | 1 | 56,340 | 23 | 112,681 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
def other_point(x1,y1,x2,y2):
x3,y3,x4,y4=x1,y2,x2,y1
return x3,y3,x4,y4
def Boolean(p_target,p1,p2):
if p1<=p_target<=p2:
return True
else:
return False
def solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2):
#????Β§???Β’a????????????
xa3,ya3,xa4,ya4=other_point(xa1,ya1,xa2,ya2)
#????Β§???Β’b????????????
xb3,yb3,xb4,yb4=other_point(xb1,yb1,xb2,yb2)
#xb1????????????xa1,xa2??????????????????????????Β§???yb1????????????ya1,ya2?????????????????????
#??Β¨
#xb2????????????xa1,xa2??????????????????????????Β§???yb???????????????ya1,ya2?????????????????????
#??Β¨
#xb3????????????xa1,xa2??????????????????????????Β§???yb3????????????ya1,ya2?????????????????????
#??Β¨
#xb4????????????xa1,xa2??????????????????????????Β§ yb3????????????ya1,ya2?????????????????????
#
#????Β§????a,b?????????????????????????????????
p1=Boolean(xb1,xa1,xa2) and Boolean(yb1,ya1,ya2)
#print("p1",p1)
p2=Boolean(xb2,xa1,xa2) and Boolean(yb2,ya1,ya2)
#print("p2",p2)
p3=Boolean(xb3,xa1,xa2) and Boolean(yb3,ya1,ya2)
#print("p3",p3)
p4=Boolean(xb4,xa1,xa2) and Boolean(yb4,ya1,ya2)
#print("p4",p4)
p5=Boolean(xa1,xb1,xb2) and Boolean(ya1,yb1,yb2)
#print("p5",p5)
p6=Boolean(xa2,xb1,xb2) and Boolean(ya2,yb1,yb2)
#print("p6",p6)
p7=Boolean(xa3,xb1,xb2) and Boolean(ya3,yb1,yb2)
#print("p7",p1)
p8=Boolean(xa4,xb1,xb2) and Boolean(ya4,yb1,yb2)
#print("p8",p8)
if (p1 or p2 or p3 or p4) or (p5 or p6 or p7 or p8):
print("YES")
else:
print("NO")
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split())
solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2)
except EOFError:
break
``` | instruction | 0 | 56,341 | 23 | 112,682 |
No | output | 1 | 56,341 | 23 | 112,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
while 1:
try:ax, ay, bx, by, cx, cy, dx, dy = map(float, input().split())
except:break
print(['YES','NO'][ay>dy or cy>by])
``` | instruction | 0 | 56,342 | 23 | 112,684 |
No | output | 1 | 56,342 | 23 | 112,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program that outputs YES if there is any overlap, and NO if there is no overlap at all. However, assume that rectangle A and rectangle B are not the same thing. Also, the things that are in contact are considered to overlap.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
xa1 ya1 xa2 ya2 xb1 yb1 xb2 yb2
Each value entered is between -2,000 and 2,000, and each value is given as a real number, including up to five digits after the decimal point.
The number of datasets does not exceed 50.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
Output
YES
YES
NO
Submitted Solution:
```
def other_point(x1,y1,x2,y2):
x3,y3,x4,y4=x1,y2,x2,y1
return x3,y3,x4,y4
def Boolean(p_target,p1,p2):
if p1<p_target<p2:
return True
else:
return False
def solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2):
#????Β§???Β’a????????????
xa3,ya3,xa4,ya4=other_point(xa1,ya1,xa2,ya2)
#????Β§???Β’b????????????
xb3,yb3,xb4,yb4=other_point(xa1,ya1,xa2,ya2)
#xb1????????????xa1,xa2??????????????????????????Β§???yb1????????????ya1,ya2?????????????????????
#??Β¨
#xb2????????????xa1,xa2??????????????????????????Β§???yb???????????????ya1,ya2?????????????????????
#??Β¨
#xb3????????????xa1,xa2??????????????????????????Β§???yb3????????????ya1,ya2?????????????????????
#??Β¨
#xb4????????????xa1,xa2??????????????????????????Β§ yb3????????????ya1,ya2?????????????????????
#
#????Β§????a,b?????????????????????????????????
p1=Boolean(xb1,xa1,xa2) and Boolean(yb1,ya1,ya2)
p2=Boolean(xb2,xa1,xa2) and Boolean(yb2,ya1,ya2)
p3=Boolean(xb3,xa1,xa2) and Boolean(yb3,ya1,ya2)
p4=Boolean(xb4,xa1,xa2) and Boolean(yb4,ya1,ya2)
p5=Boolean(xa1,xb1,xb2) and Boolean(ya1,yb1,yb2)
p6=Boolean(xa2,xb1,xb2) and Boolean(ya2,yb1,yb2)
p7=Boolean(xa3,xb1,xb2) and Boolean(ya3,yb1,yb2)
p8=Boolean(xa4,xb1,xb2) and Boolean(ya4,yb1,yb2)
if (p1 or p2 or p3 or p4) or (p5 or p6 or p7 or p8):
print("YES")
else:
print("NO")
while True:
try:
xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split())
solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2)
except EOFError:
break
``` | instruction | 0 | 56,343 | 23 | 112,686 |
No | output | 1 | 56,343 | 23 | 112,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0). | instruction | 0 | 56,613 | 23 | 113,226 |
Tags: binary search, geometry, shortest paths, sortings
Correct Solution:
```
import math as m
def count(zoz, x, y):
poc = 0
for i in zoz:
poc += abs(x-i[0])
poc += abs(y-i[1])
return poc
res = []
for _ in range(int(input())):
n = int(input())
xes = []
yes = []
for i in range(n):
sur = [int(x) for x in input().split()]
xes.append(sur[0])
yes.append(sur[1])
xes.sort()
yes.sort()
x = xes[int(len(xes)/2)]-xes[int((len(xes)-1)/2)] + 1
y = yes[int(len(yes)/2)]-yes[int((len(yes)-1)/2)] + 1
res.append(x*y)
for i in res:
print(i)
``` | output | 1 | 56,613 | 23 | 113,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
y = []
x = []
for i in range(n):
l,r = map(int,input().split())
x.append(l)
y.append(r)
x.sort()
y.sort()
f = x[n//2]-x[(n-1)//2]+1
s = y[n//2]-y[(n-1)//2]+1
print(f*s)
``` | instruction | 0 | 56,617 | 23 | 113,234 |
Yes | output | 1 | 56,617 | 23 | 113,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
def solve(arr):
arr.sort()
n = len(arr)
return arr[n//2] - arr[(n-1)//2] + 1
for _ in range(int(input())):
n = int(input())
x , y = [0]*n , [0]*n
for i in range(n):
x[i] , y[i] = map(int,input().split())
print(solve(x)*solve(y))
``` | instruction | 0 | 56,618 | 23 | 113,236 |
Yes | output | 1 | 56,618 | 23 | 113,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
l=[]
l2=[]
for j in range(n):
x,y=map(int,input().split())
l.append(x)
l2.append(y)
l.sort()
v=0
if len(l)%2!=0:
v=1
else:
if l[len(l)//2]>l[len(l)//2-1]:
v=l[len(l)//2]-l[len(l)//2-1]+1
else:
v=1
l2.sort()
if len(l2)%2!=0:
v*=1
else:
if l2[len(l2)//2]>l2[len(l2)//2-1]:
v*=l2[len(l2)//2]-l2[len(l2)//2-1]+1
else:
v*=1
print(v)
``` | instruction | 0 | 56,619 | 23 | 113,238 |
Yes | output | 1 | 56,619 | 23 | 113,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from heapq import heappush, heappop, heapify
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br
def lcm(a, b):
return abs(a*b) // math.gcd(a, b)
'''
testcase = sys.argv[1]
f = open(testcase, "r")
input = f.readline
'''
sys.setrecursionlimit(100000000)
intinp = lambda: int(input().strip())
stripinp = lambda: input().strip()
fltarr = lambda: list(map(float,input().strip().split()))
intarr = lambda: list(map(int,input().strip().split()))
ceildiv = lambda x,d: x//d if(x%d==0) else x//d+1
MOD=1_000_000_007
num_cases = intinp()
#num_cases = 1
for _ in range(num_cases):
#n, k = intarr()
n = intinp()
#s = stripinp()
#arr = intarr()
ans = cc()
mi = math.inf
ed = []
mean = [0,0]
for _ in range(n):
x,y = intarr()
ed.append([x,y])
mean[0] += x
mean[1] += y
mean = [mean[0]/n, mean[1]/n]
for i in range(math.floor(mean[0])-1, math.ceil(mean[0])+2):
for j in range(math.floor(mean[1])-1, math.ceil(mean[1])+2):
curr = 0
for x,y in ed:
curr += abs(x-i) + abs(y-j)
if curr > mi: break
ans[curr] += 1
mi = min(mi, curr)
#print(ans, mean)
print(ans[min(ans.keys())])
``` | instruction | 0 | 56,620 | 23 | 113,240 |
No | output | 1 | 56,620 | 23 | 113,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
l =[]
l1 = []
for i in range(n):
x,y=map(int,input().split())
l.append(x)
l1.append(y)
l.sort()
l1.sort()
if n%2==1:
print(1)
else:
a = l[n//2]-l[n//2-1]+1
b = l1[n//2]-l1[n//2-1]+1
print(a*b-1)
``` | instruction | 0 | 56,621 | 23 | 113,242 |
No | output | 1 | 56,621 | 23 | 113,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
"""
Author - Satwik Tiwari .
18th Feb , 2021 - Thursday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil,sqrt,log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def testcase(t):
for pp in range(t):
solve(pp)
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
y%=(p-1) #not so sure about this. used when y>p-1. if p is prime.
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
inf = pow(10,20)
mod = 10**9+7
#===============================================================================================
# code here ;))
def solve(case):
n = int(inp())
x = 0
y = 0
points = []
for i in range(n):
a,b = sep()
points.append((a,b))
x+=a
y+=b
x = floor(x/n)
y = floor(y/n)
mn = inf
for i in range(max(0,x-50),x+50):
for j in range(max(0,y-50),y+50):
curr = 0
for a,b in points:
curr += abs(i-a) + abs(j-b)
mn = min(mn,curr)
ans = 0
for i in range(max(0,x-50),x+50):
for j in range(max(0,y-50),y+50):
curr = 0
for a,b in points:
curr += abs(i-a) + abs(j-b)
if(curr == mn): ans += 1
print(ans)
# testcase(1)
testcase(int(inp()))
``` | instruction | 0 | 56,622 | 23 | 113,244 |
No | output | 1 | 56,622 | 23 | 113,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|, where |x| is the absolute value of x.
Input
First line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 1000). Next n lines describe the positions of the houses (x_i, y_i) (0 β€ x_i, y_i β€ 10^9).
It's guaranteed that the sum of all n does not exceed 1000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green β possible positions for the exhibition.
<image>
First test case.
<image>
Second test case. <image>
Third test case. <image>
Fourth test case. <image>
Fifth test case. <image>
Sixth test case. Here both houses are located at (0, 0).
Submitted Solution:
```
# cook your dish here
t=int(input())
for _ in range(t):
n=int(input())
px=[]
py=[]
c=0
mn=0
x0,mx=0,0
y0,my=0,0
for i in range(n):
x,y=map(int,input().split())
px.append(x)
if x>mx:
mx=x
if y>my:
my=y
if y<y0 or i==0:
y0=y
if x<x0 or i==0:
x0=x
py.append(y)
for x in range(x0,mx+1):
for y in range(y0,my+1):
d=0
i=0
while i<len(px) and d<=mn:
d=d+abs(x-px[i])+abs(y-py[i])
i+=1
if d<mn or (x==x0 and y==y0):
mn=d
c=1
elif mn==d:
c+=1
print(c)
``` | instruction | 0 | 56,623 | 23 | 113,246 |
No | output | 1 | 56,623 | 23 | 113,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,754 | 23 | 113,508 |
Tags: geometry, math
Correct Solution:
```
from decimal import *
from math import sqrt,tan,pi
if __name__ == "__main__":
getcontext().prec = 50
l3,l4,l5 = map( Decimal , input().split() )
#print(l3,l4,l5)
S3 = Decimal(sqrt(3))*l3*l3/4
H3 = Decimal(sqrt(6))*l3/3
area3 = S3*H3/3
S4 = l4*l4
H4 = Decimal(sqrt(2))*l4/2
area4 = S4*H4/3
h5 = l5*Decimal(tan(54*pi/180))/2
S5 = (l5*h5/2)*5
H5 = Decimal(sqrt((3*l5*l5/4)-(h5*h5)))
area5 = S5*H5/3
res = area3 + area4 + area5
print(res)
``` | output | 1 | 56,754 | 23 | 113,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,755 | 23 | 113,510 |
Tags: geometry, math
Correct Solution:
```
from math import sqrt, cos, sin, pi
a, b, c = map(int, input().split())
abh = sqrt(a**2 - a**2 / 4)
aba = a * abh / 2
ah = sqrt(a**2 - (2 * abh / 3)**2)
aa = aba * ah / 3
bba = b * b
bh = sqrt(b**2 - (b / sqrt(2))**2)
ba = bba * bh / 3
x1, y1 = 0, 1
x2, y2 = cos(18 / 360 * 2 * pi), sin(18 / 360 * 2 * pi)
d = sqrt((x1-x2)**2 + (y1-y2)**2)
f = c/d
ch = sqrt(c**2 - f**2)
cba = f * f * sin(72 / 360 * 2 * pi) / 2 * 5
ca = cba * ch / 3
print(aa + ba + ca)
``` | output | 1 | 56,755 | 23 | 113,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,756 | 23 | 113,512 |
Tags: geometry, math
Correct Solution:
```
from functools import reduce
from math import factorial
l1, l2, l3 = [int(x) for x in input().split()]
A = (2**0.5)/12
B = ((15 + 5*5**0.5)/288)**0.5
print((l1**3 + 2*l2**3)*A + B*l3**3)
``` | output | 1 | 56,756 | 23 | 113,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,757 | 23 | 113,514 |
Tags: geometry, math
Correct Solution:
```
from math import sqrt, sin, pi, tan
def altura(l, R):
return sqrt(l**2 - R**2)
def volumen(A, h):
return A * h / 3
l3, l4, l5 = list(map(int, input().split()))
A3 = l3**2 * sqrt(3) / 4
R3 = l3 / sqrt(3)
h3 = altura(l3, R3)
V3 = volumen(A3, h3)
A4 = l4**2
R4 = l4 / sqrt(2)
h4 = altura(l4, R4)
V4 = volumen(A4, h4)
# A5 = 5 * a**2 * sin(2 * pi / 5) / 2
A5 = 5 * l5**2 * tan(54 * pi/180) / 4
R5 = l5 / (2 * sin(pi / 5))
h5 = altura(l5, R5)
V5 = volumen(A5, h5)
print(V3 + V4 + V5)
``` | output | 1 | 56,757 | 23 | 113,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,758 | 23 | 113,516 |
Tags: geometry, math
Correct Solution:
```
from math import sqrt
x, y, z = map(int, input().split())
s = sqrt(2) / 12 * x ** 3
p = sqrt(2) / 6 * y ** 3
d = 5 ** .5 * (5 + 2 * 5 ** .5) ** .5 / 4 * z ** 2
q = 1 / 3 * d * sqrt(z ** 2 * (3 - 5 ** .5) / (5 - 5 ** .5))
print(s + p + q)
``` | output | 1 | 56,758 | 23 | 113,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,759 | 23 | 113,518 |
Tags: geometry, math
Correct Solution:
```
import math
l1, l2, l3 = map(int, input().split())
m1 = l1 * l1 - l1 * l1 / 4
h1 = math.sqrt(m1 - m1 / 9)
v1 = l1 * math.sqrt(m1) * h1 / 6
m2 = l2 * l2 - l2 * l2 / 4
h2 = math.sqrt(m2 - l2 * l2 / 4)
v2 = l2 * l2 * h2 / 3
m3 = l3 * l3 - l3 * l3 / 4
x = l3 * math.tan(54 * math.pi / 180) / 2
h3 = math.sqrt(m3 - x * x)
s3 = 5 * l3 * l3 / math.tan(math.pi / 5) / 4
v3 = s3 * h3 / 3
print(v1 + v2 + v3)
``` | output | 1 | 56,759 | 23 | 113,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,760 | 23 | 113,520 |
Tags: geometry, math
Correct Solution:
```
import math as m
def volume(n,x):
q = m.pi*((n-2)/n)
x = x/(2*m.cos(q/2))
return(((1/3)*(n/2)*(m.sin(q))*(((4*((m.cos(q/2))**2)) - 1)**(0.5)))*(x**3))
a ,b ,c = [int(x) for x in input().split()]
print(volume(3,a) + volume(4,b) + volume(5,c))
``` | output | 1 | 56,760 | 23 | 113,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709 | instruction | 0 | 56,761 | 23 | 113,522 |
Tags: geometry, math
Correct Solution:
```
import math
a, b, c = map(lambda x: int(x), input().split(' '))
summ = 0
summ += (a ** 2 - ((a * a - a * a / 4) ** 0.5 * 2 / 3) ** 2) ** 0.5 * (a * a - a * a / 4) ** 0.5 * a / 2
summ += b * b * (((b * b - b * b / 4) - b * b / 4) ** 0.5)
a = c
b = a / (2 * math.sin(math.pi / 5))
summ += 5 / 2 * a * ( ( b ** 2 - a * a / 4 ) ** 0.5 ) * ((a * a - b * b) ** 0.5)
print(summ / 3)
``` | output | 1 | 56,761 | 23 | 113,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709
Submitted Solution:
```
from math import *
l3, l4, l5 = map(int, input().split())
a = (l4**3)/(3 * 2 ** 0.5)
b = (2**0.5 * l3**3)/12
c = ((5-5**0.5)/10)**0.5*5*l5**3
c /= (12 * tan(pi/5))
print(a+b+c)
``` | instruction | 0 | 56,762 | 23 | 113,524 |
Yes | output | 1 | 56,762 | 23 | 113,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β one triangular, one quadrangular and one pentagonal.
The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
<image>
Input
The only line of the input contains three integers l3, l4, l5 (1 β€ l3, l4, l5 β€ 1000) β the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
Output
Output one number β the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
Examples
Input
2 5 3
Output
38.546168065709
Submitted Solution:
```
from math import sqrt as s
x, y, z = map(int, input().split())
print(pow(x, 3) * (1 / 6 / s(2)) + pow(y, 3) * (s(2) / 6) + pow(z, 3) * ((5 + s(5)) / 24))
``` | instruction | 0 | 56,763 | 23 | 113,526 |
Yes | output | 1 | 56,763 | 23 | 113,527 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.