atcoder#ABC186F. [ABC186F] Rook on Grid
[ABC186F] Rook on Grid
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns. Let Square be the square at the -th row and -th column.
There are obstacles on this grid. The -th obstacle is at Square .
We have a rook, the chess piece, on Square . In one move, it can move to the right or downward through any number of squares without obstacles.
Find the number of squares the rook can reach in two moves or less.
Constraints
- are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of squares the rook can reach in two moves or less.
4 3 2
2 2
3 3
10
Every square without an obstacle can be reached in two moves or less.
5 4 4
3 2
3 4
4 2
5 2
14
Every square without an obstacle except and can be reached in two moves or less.
200000 200000 0
40000000000