#d1906. 矩形划分

矩形划分

Rectangle Partition

Problem Description

You are given a rectangle whose bottom-left corner is at (0,0)(0, 0) and top-right corner is at (n,m)(n, m); all four sides are parallel to the axes. You need to partition it into as many pieces as possible.

The partition rules are as follows:

  1. Each time two points p,qp, q are given, and you must draw a line between pp and qq to partition the rectangle. It is guaranteed that pp and qq lie on a pair of opposite sides — either both on the left/right boundaries, or both on the top/bottom boundaries.
  2. The line does not have to be straight; it may be curved, but it must not intersect itself, and must not intersect the rectangle boundary at any point other than p,qp, q.
  3. Two lines have at most one intersection, and if they intersect, they cross at that point.
  4. Lines whose endpoints lie on the same pair of opposite sides do not intersect each other.
  5. It is guaranteed that all given points are pairwise distinct.

Output the maximum number of pieces into which the rectangle can be partitioned.

Input Format

The first line contains two integers n,mn, m, as described (1≤n,m≤1091 \le n, m \le 10^9).

The second line contains two integers x,yx, y, meaning there are xx pairs of points on the left/right boundaries and yy pairs of points on the bottom/top boundaries (1≤x≤min⁡(m+1,105)1 \le x \le \min(m+1, 10^5), 1≤y≤min⁡(n+1,105)1 \le y \le \min(n+1, 10^5)).

The next xx lines each contain two integers a,ba, b, the vertical coordinates of the points on the left and right boundaries respectively (0≤a,b≤m0 \le a, b \le m).

The next yy lines each contain two integers c,dc, d, the horizontal coordinates of the points on the bottom and top boundaries respectively (0≤c,d≤n0 \le c, d \le n).

Output Format

Output one integer on a single line: the maximum number of pieces.

Sample Input

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

Sample Output

13

Sample Explanation

illustration of the partition

According to the partition shown above, the maximum number of pieces is 1313.