One More Tri


Submit solution

Points: 1
Time limit: 1.5s
Python 2.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

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 90^\circ.

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 n (1 \leq n \leq 2000), the number of pebbles dropped onto the dish.

The next n lines each contain two space-separated integers x_i and y_i (-10^4 \leq x_i,y_i \leq 10^4), the coordinates of the i-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 4 corners are right angled, so there are 4 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):

  • (0,0), (1,0), (0,1)
  • (0,0), (2,0), (0,1)
  • (0,0), (1,0), (1,1)
  • (1,0), (2,0), (1,1)
  • (0,0), (0,1), (1,1)
  • (1,0), (0,1), (1,1)
  • (0,0), (2,0), (1,1)
Input 3
4
0 0
2 1
3 4
5 7
Output 3
0

There are 4 possible triangles but none of them have a right angle.


Comments