cho.sh
Notes
Loading...

Mosaic

Time limit

1s

Memory limit

128 MB

Problem

Suchan is helping decorate a classroom wall with a mosaic picture. He attached a large rectangular sheet of drawing paper to the wall, drew horizontal and vertical lines at 1 cm intervals, and colored each square cell with the same paint. Afterward, he found that some cells had been colored incorrectly.

He wants to cover every incorrectly colored cell with square paper that has the same color as the drawing paper. The number of sheets he may use is fixed, and all incorrectly colored cells must be covered under the following rules.

  1. Every sheet of paper used is a square of the same size.
  2. The size of a sheet is represented by the length of one side, and sheets of any needed size are available.
  3. Every sheet must be attached with its bottom side aligned to the bottom edge of the drawing paper. Sheets may overlap.

Rows are numbered from 1 upward starting at the bottom of the paper, and columns are numbered from 1 to the right starting at the left edge.

A cell is represented by (row, column). In the illustration, if there are 9 incorrectly colored cells and 4 sheets of paper are available, the smallest possible sheet size is 3 cm.

Given the number of rows and columns of the drawing paper, the number of sheets available, and the positions of all incorrectly colored cells, find the minimum side length of a sheet that can cover every incorrectly colored cell while satisfying the rules above.

Input

The first line contains two natural numbers R and C, the number of rows and columns of the drawing paper. Both R and C are at most 1,000,000.

The second line contains a natural number P, the number of sheets that may be used. P is at most 100.

The third line contains a natural number K, the number of incorrectly colored cells. K is at most 1,000.

Each of the next K lines contains the position of one incorrectly colored cell as two natural numbers: first its row number, then its column number.

Output

Print one natural number: the minimum sheet size in centimeters that can cover every incorrectly colored cell using the given number of sheets.