Rectangles in Three Dimensions

Time limit1sMemory limit128 MB

Problem

There are N rectangles in three-dimensional space. Each rectangle is parallel to exactly one of the XY, YZ, and ZX planes.

Each rectangle is given by the coordinates of two opposite vertices. Two rectangles are considered to intersect if they share at least one point. Sharing only an edge or only a vertex also counts.

Find the number of intersecting pairs of rectangles.

Input

The first line contains the number of rectangles N. (1 ≤ N ≤ 100,000)

Each of the next N lines contains six integers x1 y1 z1 x2 y2 z2 describing one rectangle. The first three integers are the coordinates of one vertex, and the next three integers are the coordinates of the opposite vertex.

Every coordinate is an integer from 1 to 999, inclusive. Because each rectangle is parallel to one coordinate plane, exactly one of the three coordinate values is the same for the two given vertices.

Output

Print the number of intersecting pairs of rectangles.