QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB

#23554. Diamonds

Statistics

A geological survey has produced a map showing diamonds buried deep underground, as illustrated below.

The bold dots in the figure mark the locations of diamonds. We now want to excavate the ground to mine them.

The excavation region must always be a square whose two diagonals are parallel to the coordinate axes.

We will call this a D-square.

With the available budget and excavation technology, we can excavate a D-square region with diagonal length $K$ only once.

Therefore, we want the chosen D-square excavation region to contain as many diamonds as possible.

Let the bottom-left corner of the map be the origin $(0,0)$.

Each diamond is located at integer coordinates.

Every vertex of the D-square must have integer coordinates,

and its center, the intersection of the two diagonals, must lie on the map, including its boundary.

A diamond on an edge of the D-square is also considered to be inside it.

For example, in the figure below with $K=4$, the left D-square contains 5 diamonds and the right D-square contains 3 diamonds.

problem_23554_9747088f61fdfc73e150d23b42d6f057.webp

Write a program that, given the geological survey map, finds a D-square containing the greatest number of diamonds.

Input

The first line contains four integers $N$, $M$, $T$, and $K$, separated by spaces.

$N$ is the width of the map and $M$ is its height ($1\le N,M\le1{,}000{,}000$).

$T$ is the number of diamonds, and $K$ is the size of the D-square (its diagonal length).

$T$ is an integer from $1$ to $100$, and $K$ is an even integer from $2$ to $10{,}000{,}000$.

Each of the next $T$ lines contains two integers $A$ and $B$, separated by a space.

Here, $(A,B)$ is the location of a diamond ($0\le A\le N$, $0\le B\le M$).

All diamond coordinates in the input are distinct.

Output

On the first line, output two integers $X$ and $Y$, separated by a space, representing the center $(X,Y)$ of the D-square.

On the second line, output the number of diamonds contained in this D-square.

If there are several answers, output any one of them.

Examples

Input 1

10 8 9 4
2 2
3 4
9 3
9 5
8 2
4 5
4 3
5 3
6 4

Output 1

5 4
5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.