One More Tri
Craft Punk are a viral duo known for their electronic music as well as their geometric constructions. You are at one of their concerts where, in between songs, they give a geometry puzzle. Whoever solves it first wins a hefty prize.
"Don't stop the dancing; One more tri(angle)" yells the Craft Punk singer, as he tosses down a bunch of pebbles onto a dish. Your challenge is, among all unordered triples of these pebbles, how many can form a right-angled triangle. A triangle is right angled if any of its three internal angles is .
Calculate this number as quickly as possible so that you can win the awesome prize: a fully funded vacation to a private resort island.
Input
The first line contains a single integer
, the number of pebbles dropped onto the dish.
The next lines each contain two space-separated integers
and
, the coordinates of the
-th pebble. Note that pebble positions are unique, i.e. there cannot be two pebbles in exactly the same spot.
Output
Output a single integer: the number of unordered triples of pebbles that form right-angled triangles. Note that 'unordered' here means that the same points in different orders don't count multiple times.
Note
If you are a Python user, you might need to submit using PyPy3 for this problem. PyPy3 is an alternate Python compiler that is often much faster, but accepts the same code. You can select it in the submission window.
Example
Input 1
4
0 0
1 0
0 1
1 1
Output 1
4
The pebbles form a unit square. Each of the corners are right angled, so there are
possible right angle triangles (indeed that is every unordered triple of these pebbles).
Input 2
5
0 0
1 0
2 0
0 1
1 1
Output 2
7
Here are all right triangles (unordered triples):
Input 3
4
0 0
2 1
3 4
5 7
Output 3
0
There are possible triangles but none of them have a right angle.
Comments
zw
hi