Under construction

Still being built. Things may change

Coffee Shops

Time limit5sMemory limit128 MB

Summary
For each query radius m, find the grid intersection reached by the most coffee shops within Manhattan distance m, breaking ties by smallest y then smallest x.
Level

Hard8 of 10

Topics
Prefix sum, Geometry, Brute force, Implementation
Solved
No attempts yet

Problem

A neighborhood has many coffee shops. The neighborhood is a square grid: every street runs north-south or east-west, so the intersections form lattice points.

The distance between two intersections (a,b)(a, b) and (c,d)(c, d) is the Manhattan distance ∣a−c∣+∣b−d∣|a - c| + |b - d|, which equals the number of blocks you must walk to go from one to the other.

Given the positions of all coffee shops and a walking limit of mm blocks, write a program that finds the intersection from which the number of coffee shops within mm blocks is as large as possible. A candidate intersection is any lattice point inside the city, i.e. an (x,y)(x, y) with 1≤x≤dx1 \le x \le dx and 1≤y≤dy1 \le y \le dy.

Input

The input consists of several test cases. Each test case describes one city.

The first line of each test case contains four integers dxdx, dydy, nn, and qq. The city has size dx×dydx \times dy (1≤dx,dy≤10001 \le dx, dy \le 1000), it contains nn coffee shops (0≤n≤5⋅1050 \le n \le 5 \cdot 10^5), and there are qq queries (1≤q≤201 \le q \le 20).

Each of the next nn lines contains two integers xix_i and yiy_i (1≤xi≤dx1 \le x_i \le dx, 1≤yi≤dy1 \le y_i \le dy), the position of the ii-th coffee shop. At most one coffee shop sits at any intersection.

Each of the next qq lines contains one integer mm (0≤m≤1060 \le m \le 10^6), the maximum number of blocks that may be walked.

The last line of the input contains four zeros, which marks the end of the input.

Output

For each test case, first print the test case number in the form Case k: (where kk starts at 11). Then, for each query, print one line: for that query's mm, print the maximum number of coffee shops that lie within mm blocks of some intersection, followed by the position of an intersection that achieves that maximum, in the form count (x,y).

If several intersections achieve the maximum, print the southernmost one (the smallest yy); if there is still a tie, print the westernmost one (the smallest xx).

Examples1

  1. Example 1

    Input
    4 4 5 3
    1 1
    1 2
    3 3
    4 4
    2 4
    1
    2
    4
    0 0 0 0
    
    Expected output
    Case 1:
    3 (3,4)
    4 (2,2)
    5 (3,1)