Under construction

Still being built. Things may change

Rectangular Pizza

Interview

Time limit1sMemory limit1024 MB

Summary
Given the cut positions on a W by H pizza, count the slices whose area is at most K.
Level

Medium5 of 10

Topics
Sorting, Two pointers, Binary search
Solved
No attempts yet

Problem

Yongmo is in charge of preparing pizza for club members to share at the CTP event.

The pizza Yongmo ordered is a rectangle with width WW and height HH. In both the horizontal and vertical directions, there is at least one straight cut across the pizza. Each cut is at a natural number distance of 1 or more from the bottom edge or the left edge.

When the pizza has WW = 7 and HH = 5, with a horizontal cut at yy = 2 and vertical cuts at xx = 1 and xx = 5, the slices have the sizes shown in the figure above.

The CTP staff cannot give a slice to a member if its size is greater than KK, because one person would find it hard to eat. The staff counts the slices that can be given to members. Given the pizza information, find how many slices the CTP staff can give to members.

Input

The first line contains WW, HH, and KK separated by spaces. KK is the maximum size of a slice that a member can eat.

The second line contains NN, the number of horizontal cuts.

The third line contains the vertical positions of the horizontal cuts y1,y2,⋯ ,yNy_1, y_2, \cdots, y_N separated by spaces.

The fourth line contains MM, the number of vertical cuts.

The fifth line contains the horizontal positions of the vertical cuts x1,x2,⋯ ,xMx_1, x_2, \cdots, x_M separated by spaces.

Output

Print the number of pizza slices that the CTP staff can give to members.

Constraints

  • 2≤W,H≤1092 \le W, H \le 10^9
  • 1≤K≤W×H1 \le K \le W \times H
  • 1≤N≤min⁡(H−1,100 000)1 \le N \le \min(H - 1, 100\,000), 1≤M≤min⁡(W−1,100 000)1 \le M \le \min(W - 1, 100\,000)
  • 1≤xi≤W−11 \le x_i \le W - 1, 1≤yi≤H−11 \le y_i \le H - 1, and xix_i and yiy_i are natural numbers.
  • The sequences x1,x2,⋯ ,xMx_1, x_2, \cdots, x_M and y1,y2,⋯ ,yNy_1, y_2, \cdots, y_N are in ascending order.

Examples2

  1. Example 1

    Input
    7 5 6
    1
    2
    2
    1 5
    
    Expected output
    4
    
  2. Example 2

    Input
    4 4 3
    1
    2
    1
    2
    
    Expected output
    0