Friendly Points

No attempts yetTime limit1sMemory limit128 MB

Problem

There are nn points on the plane. All points have distinct xx-coordinates and distinct yy-coordinates (no two points share the same xx-coordinate, and no two points share the same yy-coordinate).

Two points are called friendly when the axis-aligned rectangle that has these two points as opposite corners contains no other point strictly inside it. Count how many friendly pairs of points there are.

Input

The first line contains the number of points nn (1n1051 \le n \le 10^5). Each of the next nn lines contains the coordinates xx and yy (0x,y1060 \le x, y \le 10^6) of one point, separated by a space.

Output

Print a single integer: the number of friendly pairs of points.