Time limit
2s
Memory limit
128 MB
After winning a war, a pyramid will be built on the battlefield. The pyramid occupies an a by b rectangular area of grid cells. Inside the pyramid, one small room will be built to hold the fallen soldiers, their belongings, and weapons. This room is a c by d rectangle.
The battlefield is divided into an m by n rectangular grid, and each cell has an integer height. Both the pyramid and the room must align exactly with grid cells. The heights of the room cells cannot be changed. All other cells occupied by the pyramid are leveled to one common height for construction. That common height is the average height of the pyramid cells excluding the room.
Only the room size is fixed, so the room may be placed anywhere inside the pyramid. However, there must be at least one cell of space between the room and the outside of the pyramid in all four directions. In other words, the room cannot touch the edge of the pyramid.
Given the battlefield size and heights, and the sizes of the pyramid and room, choose the positions of the pyramid and the room so that the final leveled average height is as large as possible.
The first line contains six integers m, n, a, b, c, and d.
3 <= m <= 1000, 3 <= n <= 1000, 3 <= a <= m, 3 <= b <= n, 1 <= c <= a - 2, and 1 <= d <= b - 2.
The next n lines each contain m natural numbers. These numbers are the cell heights, and no height is greater than 100.
On the first line, print the coordinates of the top-left cell of the pyramid area. On the second line, print the coordinates of the top-left cell of the room inside the pyramid.
Print each coordinate as the horizontal coordinate followed by the vertical coordinate, separated by a space. The top-left cell of the battlefield is 1 1. If there are multiple optimal answers, you may print any one of them.