def is_inside(rect, xp, yp):
x1, y1, x2, y2 = rect
return x1 < xp < x2 and y2 < yp < y1
with open("rectangles.txt") as file:
rectangles = [
list(map(int, line.split())) for line in file.read().strip().split("\n")
]
result = 0
for i, rect1 in enumerate(rectangles):
for rect2 in rectangles[i + 1 :]:
x1, y1, x2, y2 = rect1
x3, y3, x4, y4 = rect2
if is_inside(rect1, x3, y3) and is_inside(rect1, x4, y4):
result += 1
elif is_inside(rect2, x1, y1) and is_inside(rect2, x2, y2):
result += 1
print(result)