11151 - rectangle intersection   

Description

According to Wikipedia,  the definition of rectangle is as follows: "In Euclidean plane geometry, a rectangle is a quadrilateral(四邊形) with four right angles(直角). It can also be defined as an equiangular quadrilateral, since equiangular means that all of its angles are equal (360°/4 = 90°)."

In this problem, you are asked to calculate the number of rectangle pairs that intersect to each other among a set of given rectangles.  All rectangles are located in a 2-dimensional euclidean space(二維空間), and all their edges are parallel to either the X- or the Y-axis.

Input

The first line contains one number N, where 2 <= N <= 128, standing for the number of given rectangles.

Each of the following N lines describes a rectangle and has 4 integers separated by space, representing

  1. the x coordinate of the bottom-left vertex
  2. the y coordinate of the bottom-left vertex
  3. the width (the length of the edge that is parallel to the x-axis), positive
  4. the height (the length of the edge that is parallel to the y-axis), positive

 Notice that each of the 4 numbers is representable by an int type in C language.

Output

The output should contain only one number, representing the number of rectangle pairs that intersect to each other.

Notice that if the area of overlapping part is zero, then the pair should NOT count.

Sample Input  Download

Sample Output  Download

Tags

Lee Homework



Discuss