#ABC182E. [ABC182E] Akari

[ABC182E] Akari

Score : 500500 points

Problem Statement

We have a grid with HH rows and WW columns. Let square (i,j)(i, j) be the square at the ii-th row and jj-th column in this grid. There are NN bulbs and MM blocks on this grid. The ii-th bulb is at square (Ai,Bi)(A_i, B_i), and the ii-th block is at square (Ci,Di)(C_i, D_i). There is at most one object - a bulb or a block - at each square. Every bulb emits beams of light in four directions - up, down, left, and right - that extend until reaching a square with a block, illuminating the squares on the way. A square with a bulb is also considered to be illuminated. Among the squares without a block, find the number of squares illuminated by the bulbs.

Constraints

  • 1H,W15001 \le H, W \le 1500
  • 1N5×1051 \le N \le 5 \times 10^5
  • 1M1051 \le M \le 10^5
  • 1AiH1 \le A_i \le H
  • 1BiW1 \le B_i \le W
  • 1CiH1 \le C_i \le H
  • 1DiW1 \le D_i \le W
  • (Ai,Bi)(Aj,Bj)  (ij)(A_i, B_i) \neq (A_j, B_j)\ \ (i \neq j)
  • (Ci,Di)(Cj,Dj)  (ij)(C_i, D_i) \neq (C_j, D_j)\ \ (i \neq j)
  • (Ai,Bi)(Cj,Dj)(A_i, B_i) \neq (C_j, D_j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW NN MM

A1A_1 B1B_1

A2A_2 B2B_2

A3A_3 B3B_3

\hspace{15pt} \vdots

ANA_N BNB_N

C1C_1 D1D_1

C2C_2 D2D_2

C3C_3 D3D_3

\hspace{15pt} \vdots

CMC_M DMD_M

Output

Print the number of squares illuminated by the bulbs among the squares without a block.

3 3 2 1
1 1
2 3
2 2
7

Among the squares without a block, all but square (3,2)(3, 2) are illuminated.

4 4 3 3
1 2
1 3
3 4
2 3
2 4
3 2
8

Among the squares without a block, the following eight are illuminated:

  • Square (1,1)(1, 1)
  • Square (1,2)(1, 2)
  • Square (1,3)(1, 3)
  • Square (1,4)(1, 4)
  • Square (2,2)(2, 2)
  • Square (3,3)(3, 3)
  • Square (3,4)(3, 4)
  • Square (4,4)(4, 4)
5 5 5 1
1 1
2 2
3 3
4 4
5 5
4 2
24

In this case, all the squares without a block are illuminated.