cho.sh
Notes
Loading...

Squares

Time limit

2s

Memory limit

128 MB

Problem

Sejun spent the whole day drawing rectangles with pencils he received as a birthday present.

The paper can be viewed as an x-y coordinate plane. Every side of every rectangle is parallel to one of the coordinate axes. Sides of different rectangles may overlap or connect with each other, so the drawn line segments can form the boundary of new rectangles or squares that were not drawn directly.

In the figure below, three drawn rectangles form a total of 14 squares.

Given the rectangles Sejun drew, count how many squares can be formed using only the drawn line segments as their sides.

Input

The first line contains the number of rectangles N. N is a positive integer not greater than 50.

Each of the next N lines describes one rectangle in the form X1 Y1 X2 Y2. (X1, Y1) is the lower-left corner of the rectangle, and (X2, Y2) is the upper-right corner.

All coordinates are non-negative integers not greater than 1,000,000,000, and they always satisfy X1 < X2 and Y1 < Y2.

Output

Print the number of squares that can be formed from the sides of the drawn rectangles.