#d1906. 矩形划分
矩形划分
Rectangle Partition
Problem Description
You are given a rectangle whose bottom-left corner is at and top-right corner is at ; 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:
- Each time two points are given, and you must draw a line between and to partition the rectangle. It is guaranteed that and lie on a pair of opposite sides — either both on the left/right boundaries, or both on the top/bottom boundaries.
- 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 .
- Two lines have at most one intersection, and if they intersect, they cross at that point.
- Lines whose endpoints lie on the same pair of opposite sides do not intersect each other.
- 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 , as described ().
The second line contains two integers , meaning there are pairs of points on the left/right boundaries and pairs of points on the bottom/top boundaries (, ).
The next lines each contain two integers , the vertical coordinates of the points on the left and right boundaries respectively ().
The next lines each contain two integers , the horizontal coordinates of the points on the bottom and top boundaries respectively ().
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

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