Map
Time limit1sMemory limit128 MB
Count the marked points that have at least one point strictly below-left, above-right, below-right, and above-left of them.
Problem
Jane found an old map of her town in the basement. The map is a square sheet of paper divided into unit squares, and several mysterious points are marked on it. Jane does not know what the points mean, so she decided to visit every one of them. She will meet three colleagues, Jack, Adam, and Robert, at one of the marked points, and that point becomes the starting point. Each of the four people is then assigned an area and visits all of the mysterious points inside it.
Relative to the starting point , Jane defines four areas:
- Area 1: every point whose first and second coordinates are both smaller than the starting point ( and ).
- Area 2: every point whose first and second coordinates are both larger ( and ).
- Area 3: every point whose first coordinate is larger and second coordinate is smaller ( and ).
- Area 4: every point whose first coordinate is smaller and second coordinate is larger ( and ).
Finally, all four visit together the marked points whose first or second coordinate equals the matching coordinate of the starting point.
Jane wants to pick the starting point so that each of the four people has at least one mysterious point to visit on their own, meaning all four areas are non-empty. Count how many of the marked points can serve as such a starting point.
Input
The first line contains two integers and (, ): the number of marked points and the size of the map. Each of the next lines contains two integers and (, ), the coordinates of the -th point. All points are distinct.
Output
Print a single integer: the number of marked points that can be chosen as the starting point.
Hint
