Garden

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

JOI Kingdom is a mysterious kingdom which has a boundless expanse of territory. JOI-kun, the king of JOI Kingdom, is planning to cut a part of the territory and make his garden.

The territory of JOI Kingdom is considered as a sufficiently large 22-dimensional grid. The grid is paved with square cells from the top to the bottom and from the left to the right. There is a cell, which is the origin of the coordinates. Let (x,y)(x, y) denote the cell one arrives at when one moves from the origin to the right direction for the distance of xx cells and to the upward direction for the distance of yy cells. Here, the left direction for the distance of aa cells means the right direction for the distance of a-a cells. Similarly, the downward direction for the distance of aa cells means the upward direction for the distance of a-a cells.

Some artworks are placed on the territory. The artworks are classified into two types, Type A and Type B, according to the way to be placed in the territory.

  • There are NN kinds of artworks of type A. An artwork of ii-th kind (1iN1 ≤ i ≤ N) is placed on every cell of the form (P_i+kD,Q_i+lD)(P\_i + kD, Q\_i + lD), where kk, ll are integers.
  • There are MM kinds of artworks of type B. An artwork of jj-th kind (1jM1 ≤ j ≤ M) is placed on every cell of the form (R_j+kD,y)(R\_j + kD, y), where kk, yy are integers, or of the form (x,S_j+lD)(x, S\_j + lD), where ll, xx are integers.

Note that a cell may contain several artworks of different kinds.

JOI-kun is planning to choose a rectangular region on the grid to make a garden. In other words, he will choose 44 integers aa, bb, cc, dd. Then the cells of the form (x,y)(x, y), where xx, yy are integers satisfying axba ≤ x ≤ b, cydc ≤ y ≤ d, will constitute JOI-kun’s garden. Since JOI-kun likes to see artworks of many kinds, for any of the N+MN + M kinds of artworks, JOI-kun’s garden should contain at least one artwork of that kind. On the other hand, the citizens of JOI Kingdom will be angry if JOI-kun plans to make a too large garden. Therefore, JOI-kun wants to minimize the number of cells in the garden so that the above condition is satisfied.

Write a program which, given information of artworks, calculates the minimum number of cells in JOI-kun’s garden.

입력

Read the following data from the standard input.

NN MM DD

P_1P\_1 Q_1Q\_1

P_2P\_2 Q_2Q\_2

\vdots

P_NP\_N Q_NQ\_N

R_1R\_1 S_1S\_1

R_2R\_2 S_2S\_2

\vdots

R_MR\_M S_MS\_M

출력

Write one line to the standard output. The output should contain the minimum number of cells in JOI-kun’s garden.

제한

  • N1N ≥ 1.
  • M1M ≥ 1.
  • N+M500,000N + M ≤ 500\\,000.
  • 1D5,0001 ≤ D ≤ 5\\,000.
  • 0P_i<D0 ≤ P\_i < D (1iN1 ≤ i ≤ N).
  • 0Q_i<D0 ≤ Q\_i < D (1iN1 ≤ i ≤ N).
  • 0R_j<D0 ≤ R\_j < D (1jM1 ≤ j ≤ M).
  • 0S_j<D0 ≤ S\_j < D (1jM1 ≤ j ≤ M).
  • Given values are all integers.