Counting Axis-Aligned Right Triangles

Time limit1sMemory limit128 MB

Problem

You are given N distinct points on a coordinate plane.

Choose three points to form a right triangle. The two sides meeting at the right angle must each be parallel to one of the coordinate axes. In other words, only right triangles whose two non-hypotenuse sides are parallel to the x-axis or y-axis are counted.

Find the number of ways to choose three points that satisfy this condition. The order of the chosen points does not matter.

Input

The first line contains the number of points N.

Each of the next N lines contains two integers X and Y, the coordinates of one point.

  • 3 <= N <= 100,000
  • 1 <= X, Y <= 100,000
  • No two given points have the same coordinates.

Output

Print the number of right triangles that satisfy the condition.