3A - Bear and Vectors
Practice
3.9 (21 votes)
Approved
Medium Hard
Problem
96% Success 1207 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Limak is a little polar bear, who isn't afraid of geometry. He has n 2-dimensional non-zero vectors \(\vec{a_1}, \vec{a_2}, \ldots, \vec{a_n}\), each described by two integers \(x_i, y_i\). Show him that you can count ways to choose an ordered triple of distinct indices \(i, j, k\) satisfying the two conditions:

  • \(\vec{a_i}\) is perpendicular to \(\vec{a_j} + \vec{a_k}\)
  • \(\vec{a_j}+\vec{a_k} \ne 0\)

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 \((x_i, y_i), (x_j + x_k, y_j + y_k), (0, 0)\) respectively.
  • \(\measuredangle ASB = 90^{\circ}\)
  • \(B \ne S\)

Input format

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

The i-th of next n lines contains two integers \(x_i, y_i\) — coordinates of \(\vec{a_i}\).

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

Output format

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

Constraints

  • \(3 \le n \le 3000\)
  • \(|x_i|, |y_i| \le 10^9\)

Subtasks

Extra constraints Points Which tests
\(n \le 50\) 20 1-4 and 9-10
no extra constraints 80 5-8 and 11-27

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsApprovedArraysData StructuresMediumOpen
Points:50
15 votes
Tags:
Binary search algorithmMatchingMedium-Hard
Points:20
31 votes
Tags:
AlgorithmsApprovedEasyGame TheoryMathOpen
Editorial

No editorial available for this problem.