Stupendous Bowties
Time limit2sMemory limit512 MB
Given N distinct integer points, count unordered pairs of axis-aligned right triangles that share only the right-angle vertex.
- Level
Medium6 of 10
- Topics
- Geometry, Combinatorics, Hash map, Math
- Solved
- No attempts yet
Problem
There are distinct points on the plane. The -th point sits at integer coordinates .
A Fantastic Right Triangle uses three of the given points as its vertices, has positive area, and has both of its legs parallel to the axes: one leg is parallel to the -axis and the other is parallel to the -axis. The vertex where the two legs meet, the one whose interior angle is right, is called the triangle's Spectacular Vertex.
A Stupendous Bowtie is an unordered pair of Fantastic Right Triangles that share the same Spectacular Vertex and touch only at that point. Treat each triangle as a closed region that includes its boundary and its interior, so the pair forms a bowtie only when the intersection of the two triangles is exactly that shared vertex.
Count the Stupendous Bowties that exist among the given points.
Input
The first line contains the number of points .
Each of the next lines contains two integers and separated by a space.
Output
Print, on a single line, the number of Stupendous Bowties that exist among the given points.
Limits
- The given points are pairwise distinct.
- The answer can exceed the range of a 32-bit integer.