cho.sh
Notes
Loading...

Wake Up!

Time limit

1s

Memory limit

128 MB

Problem

Wake up, heroes!

There are N heroes protecting this world. Each hero repeatedly moves back and forth at light-like speed along one line segment. Whenever two heroes meet at the same position, they collide and wake each other up.

Given the segment on which each hero moves, count the number of distinct positions where two heroes can collide.

No three heroes meet at one position at the same time, and no two heroes share the same segment portion of their paths.

Input

The first line contains the number of heroes N. (0 <= N <= 20,000)

Each of the next N lines contains the two endpoints (x1, y1) and (x2, y2) of one hero's segment. (-1,000,000 <= x1, y1, x2, y2 <= 1,000,000)

Output

Print the number of distinct positions where heroes can collide.

The answer is at most 100,000.