There are N distinct points on the plane. The i-th point sits at integer coordinates (xi,yi).
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 x-axis and the other is parallel to the y-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.