#P6063. [USACO05JAN] The Wedding Juicer G

[USACO05JAN] The Wedding Juicer G

Description

John’s cows found a nice part-time job: designing a punch-style juicer. The juicer is designed as follows.

There is a base of size W×HW \times H (3W,H3003 \leq W,H \leq 300). On each 1×11 \times 1 cell, there is a pillar of height BB (1B1091 \leq B \leq 10^9) used for juicing. Assume that the pillars are perfectly glued together, so water will not leak through the gaps between pillars.

However, John has never known how much juice such a juicer can hold. Assume there is nothing around the juicer, which means water on the boundary will flow away. Some juicers cannot hold any juice at all.

Input Format

The first line contains two integers WW and HH.

The next HH lines each contain WW numbers, representing the heights.

Output Format

Output the maximum amount of juice it can hold.

4 5
5 8 7 7
5 2 1 5
7 1 7 1
8 9 6 9
9 8 9 9
12

Hint

Translated by ChatGPT 5