Hide

Problem D
Meeting Points

This problem is very simple. Given $n$ lines lying in the $x$-$y$ plane, determine the number of intersection points. Here are the details:

  1. Each line is specified by two distinct points, $(x_1, y_1)$ and $(x_2, y_2)$, through which the line passes.

  2. All $n$ lines are distinct, i.e., no two lines will be coincident (lie on top of each other).

  3. You are guaranteed that there is no point in the plane at which three or more lines intersect.

Input

The first input line contains an integer $n$ ($2 \leq n \leq 100\, 000$), the number of lines in the $x$-$y$ plane. This is followed by $n$ input lines, each containing the specification of a line in the plane given as four space-separated integers, $x_1$ $y_1$ $x_2$ $y_2$. Each coordinate is at most $10^6$ in absolute value.

Output

Output a single integer, the number of intersection points.

Sample Input 1 Sample Output 1
2
-1 0 1 0
0 1 0 -1
1
Sample Input 2 Sample Output 2
3
1 1 2 2
2 2 3 1
3 1 1 1
3
Sample Input 3 Sample Output 3
4
0 2 2 0
0 -2 2 0
0 2 0 -2
-1 -1 0 1
6

Please log in to submit a solution to this problem

Log in