#P10907. Ant Meeting Centers

    ID: 12952 Type: Default 1000ms 256MiB

Ant Meeting Centers

Ant Meeting Centers

In a 2D plane, there are (n) ants. Each ant has a line segment that defines its activity range, with the endpoints for the (i)-th ant given as ( (u_i^x, u_i^y) ) and ( (v_i^x, v_i^y) ). The ants plan to set up meeting centers at the intersections of these segments. However, to minimize costs, they will only establish a meeting center if the intersection point has integer coordinates.

Your task is to determine the number of distinct meeting centers (i.e. the number of lattice points that lie on at least two segments).

Note: For a segment with endpoints ( (x_1, y_1) ) and ( (x_2, y_2) ), if these points are integers then all lattice points on the segment can be enumerated by stepping from ( (x_1, y_1) ) to ( (x_2, y_2) ) with step sizes ( \Delta x = \frac{x_2 - x_1}{gcd(|x_2-x_1|,|y_2-y_1|)} ) and ( \Delta y = \frac{y_2 - y_1}{gcd(|x_2-x_1|,|y_2-y_1|)} ).

inputFormat

The first line contains an integer (n) ((n \ge 1)), the number of ants. Each of the following (n) lines contains four integers (u_i^x), (u_i^y), (v_i^x), (v_i^y) separated by spaces, representing the endpoints of the (i)-th ant's segment.

outputFormat

Output a single integer: the number of distinct lattice points (meeting centers) that lie on at least two segments.

sample

3
0 0 4 4
0 4 4 0
0 2 4 2
1