An observatory logs n distinct star positions on an integer sky chart. A trio of stars is called aligned when all three lie on a single straight line. Count how many unordered triples of stars are aligned.
Line 1: an integer n, the number of stars.
Next n lines: two integers x y, the position of a star. All positions are distinct.
A single integer: the number of aligned (collinear) triples.
Example 1
Input
4 0 0 1 1 2 2 0 1
Expected
1
Explanation
Only (0,0), (1,1), (2,2) share a line, so there is exactly 1 aligned triple.
Example 2
Input
3 0 0 1 0 0 1
Expected
0
Explanation
These three form a right angle and are not collinear, so there are 0 aligned triples.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →