cho.sh
Notes
Loading...

Dividing a Rectangle into Three

Time limit

2s

Memory limit

128 MB

Problem

An N×MN \times MN×M rectangle is filled with N×MN \times MN×M digits.

Divide the rectangle into three non-overlapping smaller rectangles. Every cell must belong to exactly one smaller rectangle, and each smaller rectangle must contain at least one cell.

The sum of a smaller rectangle is the sum of the digits inside it. Find the maximum possible product of the three sums after dividing the given rectangle into three smaller rectangles.

Input

The first line contains the rectangle height NNN and width MMM.

The next NNN lines describe the rectangle from top to bottom. Each line contains exactly MMM digits.

NNN and MMM are positive integers at most 505050. The rectangle contains at least three cells. Each cell contains one decimal digit.

Output

Print the maximum possible product of the sums of the three smaller rectangles.