Squares
Time limit1sMemory limit128 MB
Count the number of squares whose four corners all come from a given set of integer-coordinate points, allowing tilted squares.
Problem
A square is a four-sided polygon whose sides all have equal length and whose adjacent sides meet at 90-degree angles. Equivalently, it is a polygon that looks exactly the same after being rotated 90 degrees about its centre. This rotation property alone does not single out the square, however: a regular octagon also looks the same after a 90-degree rotation.
Given a set of stars in the night sky, count how many squares can be formed using the stars as corners. To keep things simple, treat the night sky as a two-dimensional plane where each star is given by integer coordinates . The squares may be axis-aligned or tilted at any angle.
Input
The input consists of several test cases. Each test case begins with a line containing the integer (), the number of points. Each of the next lines contains the and coordinates (two integers) of one point. All points are distinct, and the absolute value of every coordinate is at most . A line with terminates the input.
Output
For each test case, print on its own line the number of squares that can be formed from the given stars.