#P6200. Shooting All Opponents
Shooting All Opponents
Shooting All Opponents
Bessie has divided a lawn into an \(N \times N\) grid (with \(1 \le N \le 100\)) for a simulation of a paintball game. She also knows the positions of her \(K\) opponents (with \(1 \le K \le 10^5\)). In the game, Bessie can shoot a bullet in any one of the eight directions: north, south, east, west, northeast, southeast, northwest, and southwest. A bullet travels in a straight ray in that direction and will hit an opponent if that opponent lies on the bullet’s path. In particular, if an opponent is in the same cell as Bessie, she can shoot that opponent.
Your task is to count the number of positions on the grid from which Bessie can hit every opponent. Formally, if Bessie stands at cell \((i,j)\) and an opponent is at \((r,c)\), then Bessie can hit that opponent if at least one of the following conditions holds:
[ \text{either } i = r, \quad \text{or} \quad j = c, \quad \text{or} \quad i - j = r - c, \quad \text{or} \quad i + j = r + c. ]
Count the number of cells \((i,j)\) (with \(1 \le i,j \le N\)) such that for every given opponent at \((r,c)\), at least one of the above conditions holds.
inputFormat
The first line contains two integers \(N\) and \(K\) separated by a space.
Each of the next \(K\) lines contains two integers \(r\) and \(c\), representing the position of an opponent on the grid. (The grid is 1-indexed.)
outputFormat
Output a single integer: the number of positions from which Bessie can shoot all opponents.
sample
3 1
2 2
9