Number of Right Triangles
Time limit1sMemory limit128 MB
Given up to 1500 planar points, count triples forming a right triangle, requiring an approach faster than brute force O(N^3).
Problem
There are N distinct points on a two-dimensional plane.
Choose three distinct points. Count how many choices form a triangle with one 90-degree angle. The same set of three points is counted only once.
Input
The first line contains the number of points N. (3 <= N <= 1500)
Each of the next N lines contains the x-coordinate and y-coordinate of one point, separated by a space. Every coordinate is between -10^9 and 10^9, inclusive.
No two points have the same coordinates.
Output
Print the number of right triangles on the first line.