문제
Farmer John is quite reliable in all aspects of managing his farm, except one: he is terrible at mowing the grass in a timely fashion. He only manages to move the mowing machine once per day, in fact. On day 1, he starts at position
So slow is FJ's progress that some of the grass he mows might grow back before he is finished with all his mowing. Any section of grass that is cut in day
Please count the number of times FJ's mowing path crosses over an earlier segment on which grass has already grown back. You should only count "perpendicular" crossings, defined as a point in common between a horizontal and a vertical segment that is an endpoint of neither.
Problem credits: Chad Waters and Brian Dean
입력
The first line of input contains
The next
출력
Please output a count of the number of crossing points described above, where FJ re-cuts a point of grass that had grown back after being cut earlier.
예제
7 4
0 10
10 10
10 5
3 5
3 12
6 12
6 3
1
Here, FJ crosses on day 7 a segment of grass he cut on day 2, which counts. The other intersections do not count.
Note: This problem has expanded limits: 5 seconds per test case (10 for Python and Java), and 512 MB of memory.