atcoder#ABC186F. [ABC186F] Rook on Grid

[ABC186F] Rook on Grid

Score : 600600 points

Problem Statement

We have a grid with HH horizontal rows and WW vertical columns. Let Square (i,j)(i,j) be the square at the ii-th row and jj-th column.

There are MM obstacles on this grid. The ii-th obstacle is at Square (Xi,Yi)(X_i, Y_i).

We have a rook, the chess piece, on Square (1,1)(1, 1). 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

  • 1H,W2×1051\leq H,W \leq 2\times 10^5
  • 0M2×1050\leq M \leq 2\times 10^5
  • 1XiH1\leq X_i \leq H
  • 1YiW1\leq Y_i \leq W
  • (Xi,Yi)(1,1)(X_i,Y_i) \neq (1,1)
  • (Xi,Yi)(X_i,Y_i) are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW MM

X1X_1 Y1Y_1

\vdots

XMX_M YMY_M

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 (4,4)(4,4) and (5,4)(5,4) can be reached in two moves or less.

200000 200000 0
40000000000