PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000146. Chia bánh thành các phần (A Piece of Cake)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chia bánh thành các phần (A Piece of Cake)

A Piece of Cake

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A rectangular cake has width WW and height HH, with opposite corners (0,0)(0,0) and (W,H)(W,H). It contains NN strawberries at pairwise distinct integer coordinates (pi,qi)(p_i,q_i).

The cake is cut along AA vertical lines x=a1,…,aAx=a_1,\ldots,a_A and BB horizontal lines y=b1,…,bBy=b_1,\ldots,b_B. Cut coordinates are strictly increasing, and no strawberry lies on a cut. The cuts create exactly (A+1)(B+1)(A+1)(B+1) rectangular pieces. Find the smallest and largest number of strawberries in any piece, including empty pieces.

Input

  • The first line contains W,HW,H.
  • The second line contains NN.
  • Each of the next NN lines contains the coordinates pi,qip_i,q_i of one strawberry.
  • The next line contains AA, followed by a line of AA vertical cut coordinates a1,…,aAa_1,\ldots,a_A.
  • The next line contains BB, followed by a line of BB horizontal cut coordinates b1,…,bBb_1,\ldots,b_B.

Output

Print two integers m,Mm,M: the minimum and maximum numbers of strawberries in one piece.

Subtasks

  • Subtask 1 (20 points): 3≤W,H≤603\le W,H\le60; 1≤N≤301\le N\le30; 1≤A,B≤81\le A,B\le8; 0<pi<W0<p_i<W, 0<qi<H0<q_i<H; strawberry coordinates are distinct; 0<a1<⋯<aA<W0<a_1<\cdots<a_A<W, 0<b1<⋯<bB<H0<b_1<\cdots<b_B<H; no strawberry lies on any cut.
  • Subtask 2 (30 points): 3≤W,H≤1063\le W,H\le10^6; 1≤N≤2⋅1041\le N\le 2\cdot10^4; 1≤A,B≤5001\le A,B\le500; 0<pi<W0<p_i<W, 0<qi<H0<q_i<H; strawberry coordinates are distinct; 0<a1<⋯<aA<W0<a_1<\cdots<a_A<W, 0<b1<⋯<bB<H0<b_1<\cdots<b_B<H; no strawberry lies on any cut.
  • Subtask 3 (50 points): 3≤W,H≤1093\le W,H\le10^9; 1≤N≤2⋅1051\le N\le 2\cdot10^5; 1≤A,B≤2⋅1051\le A,B\le 2\cdot10^5; 0<pi<W0<p_i<W, 0<qi<H0<q_i<H; strawberry coordinates are distinct; 0<a1<⋯<aA<W0<a_1<\cdots<a_A<W, 0<b1<⋯<bB<H0<b_1<\cdots<b_B<H; no strawberry lies on any cut.

Examples

Input

7 6
5
6 1
3 1
4 2
1 5
6 2
2
2 5
2
3 4

Output

0 2

Explanation

The cuts x=2,5x=2,5 create three columns; y=3,4y=3,4 create three rows, giving 3×3=93\times3=9 pieces. Strawberries (3,1)(3,1) and (4,2)(4,2) share one piece, (6,1)(6,1) and (6,2)(6,2) share another, and (1,5)(1,5) occupies a third. Thus two pieces contain 22, one contains 11, and six contain 00 strawberries. The answer is 0 2.