an2dl (COCI CONTEST_#1)
Time limit: 4 seconds | Memory limit: 512 MB | Task type: batch
Algorithms: grid traversal, two pointers, range queries, monotonic queue

# Task AN2DL

While wandering around Building 21, you came across a wall completely covered with numbers, arranged in a table of *n* rows and *m* columns. Soon you noticed that there was a frame leaning against the wall large enough to frame *r* rows and *s* columns of the table on the wall. And next to the frame you found a pencil and a piece of paper containing an empty table.

![](./_page_0_Picture_4.jpeg)

You are sad that the table on the piece of paper is empty, so you decided to play around with the frame to fill it.

You leaned the frame against the wall so that the number in the *i*-th row and *j*-th column is in the upper left corner, and the borders of the frame are parallel to the edges of the wall. Considering the numbers inside the frame, and since you like large numbers, you have decided to write the largest among them in the *i*-th row and *j*-th column of the table on the piece of paper.

You repeated the process for every possible position of the frame on the wall (such that the frame is entirely on the wall, and that there are exactly *r* × *s* numbers inside it), making sure that the edges of the frame are parallel to the edges of the wall.

When you were done, the table on the piece of paper was even more beautiful than the one on the wall. What numbers are in the table on the piece of paper?

## Input

The first line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 4000), the number of rows and columns of the table on the wall.

Each of the following *n* lines contain *m* integers $a_{i,j}$ (|$a_{i,j}$| ≤ 10000), where $a_{i,j}$ is the number in the *i*-th row and *j*-th column of the table on the wall.

The last line contains two integers *r* and *s* (1 ≤ *r* < *n*, 1 ≤ *s* < *m*), the size of the frame.

## Output

Output the numbers written in the table on the piece of paper.

## Scoring

| Subtask | Points | Constraints               |
| ------- | ------ | ------------------------- |
| 1       | 12     | $n, m \le 40, r = n, s = m$ |
| 2       | 17     | $n, m \le 40$             |
| 3       | 25     | $n, m \le 1000$           |
| 4       | 56     | No additional constraints. |

![](./_page_1_Picture_0.jpeg)

## Examples

| Input          | Input          | Input           |
| -------------- | -------------- | -------------- |
| ```            | ```            | ```            |
| 3 3            | 3 3            | 5 5            |
| 1 1 2          | 1 1 2          | -1 -3 -4 -2 4  |
| 2 3 4          | 2 3 4          | -8 -7 -9 -10 11 |
| 4 3 2          | 4 3 2          | 5 2 -8 -2 1    |
| ```            | ```            | 13 -3 -2 -6 -9 |
|                |                | 11 6 2 7 4     |
|                |                | ```            |
|                | 2 1            | 2 3            |
| Output         | Output         | Output         |
| ```            | ```            | ```            |
| 4              | 2 3 4          | -1 -2 11       |
|                | 4 3 4          | 5 2 11         |
|                | ```            | 13 2 1         |
|                |                | 13 7 7         |
|                |                | ```            |

#### Clarification of the first example:

The frame is big enough to fit the entire table on the wall. The largest number inside the frame is 4, so that is the only number written on the table on the piece of paper.

#### Clarification of the second example:

All possible frame positions are shown in the picture below. The largest number for each of the positions is written in red.

![](./_page_1_Figure_9.jpeg)

Starter code:

Grader code:

Setup script:

Evaluation script: