This page is still under construction.

Parts of this page are still being built. What you see may change.

Pirate Chest

Time limit15sMemory limit128 MB

Summary
Find the largest chest with top sides bounded by a and b that rests on a pond footprint and stays just below the raised water level.
Level

Hard8 of 10

Topics
Math, Matrix, Sliding window
Solved
No attempts yet

Problem

A retired pirate wants to hide his gold coins by locking them in a chest and sinking it in a murky pond.

The chest is a rectangular box. Its top and bottom are two equal rectangles with integer side lengths: one side is at most aa and the other is at most bb. Its height is any positive integer. The chest is always aligned with the grid, and its top stays parallel to the pond's surface.

The pond's surface is a rectangle of m×nm \times n unit squares and completely fills a valley with high vertical rock walls. The water depth at square (i,j)(i, j) is di,jd_{i,j}.

When the chest is lowered into the pond, it sinks as far as possible until its flat bottom touches the pond floor, so it rests on the shallowest square inside its footprint. The water pushed aside by the submerged chest raises the level of the pond's surface. This rise happens even if there is no room around the chest for the displaced water to spread, and the valley walls are high enough that water never spills out.

To stay hidden, the top of the chest must end up strictly below the raised water surface. If the chest were exactly one unit taller, its top would reach the surface and become visible, which is not allowed.

Find the largest volume of a chest that can be hidden in the pond this way.

Input

The first line contains four integers aa, bb, mm, and nn (1≤a,b,m,n≤5001 \le a, b, m, n \le 500). The pond's surface is m×nm \times n, and the top of the chest has size at most a×ba \times b. The values aa and bb are small enough that a chest with top size a×ba \times b can never cover the entire pond.

Each of the next mm lines contains nn integers. The jj-th integer on the ii-th of these lines is di,jd_{i,j} (0≤di,j≤1090 \le d_{i,j} \le 10^9), the water depth at square (i,j)(i, j).

Output

Print one integer: the maximum volume of a rectangular chest (one top side bounded by aa, the other bounded by bb) that can be completely submerged below the pond's surface. If no chest can be hidden, print 00.

Examples1

  1. Example 1

    Input
    3 1 2 3
    2 1 1
    2 2 1
    
    Expected output
    4