3A - Bear and Vectors

3.9

21 votes
Approved, Medium-Hard
Problem

Limak is a little polar bear, who isn't afraid of geometry. He has n 2-dimensional non-zero vectors a1,a2,,an, each described by two integers xi,yi. Show him that you can count ways to choose an ordered triple of distinct indices i,j,k satisfying the two conditions:

  • ai is perpendicular to aj+ak
  • aj+ak0

If you don't know vectors (so you don't understand what is written above) then you can use the following three conditions, equivalent to those given above:

  • For fixed i,j,k let A,B,S denote points (xi,yi),(xj+xk,yj+yk),(0,0) respectively.
  • ASB=90
  • BS

Input format

The first line contains one integer n — the number of vectors.

The i-th of next n lines contains two integers xi,yi — coordinates of ai.

Some of n vectors may be equal to each other but none of them is equal to (0,0).

Output format

In one line print the number of ordered triples of distinct indices i,j,k satisfying the given conditions.

Constraints

  • 3n3000
  • |xi|,|yi|109

Subtasks

Extra constraints Points Which tests
n50 20 1-4 and 9-10
no extra constraints 80 5-8 and 11-27
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

There are n=5 vectors in the sample test. Note that some of them may be equal. There are 4 ways to choose a triple of indices:

  • (1,2,4) because a1=(1,1) is perpendicular to a2+a4=(12,0+1)=(1,1)
  • (1,4,2)
  • (1,4,5)
  • (1,5,4)
Editor Image

?