Farmer John's cows received a large square slab of marble that, unfortunately, has a few imperfections. The slab is an $N \times N$ grid ($5 \le N \le 300$) where * marks an imperfection and . marks a flawless cell.
The cows love the number 8 (with a cloven hoof on each of their four feet they can count to eight on their "toes"), so they want to carve a figure eight into the slab. A figure eight is drawn from the outlines of two axis-aligned rectangles — a top rectangle and a bottom rectangle — that satisfy all of the following:
.). Interior cells are unrestricted and may contain imperfections.A rectangle spanning rows $a..b$ and columns $c..d$ encloses an interior area of $(b - a - 1)\times(d - c - 1)$. The aesthetic score of a figure eight is the product of its two enclosed interior areas, and the cows want it as large as possible.
Schematic of one figure eight (8 marks the carved outline cells):
.8888...
.8..8...
88888888
8......8
88888888
Report the maximum achievable aesthetic score, or -1 if no valid figure eight can be carved.
* (an imperfection) or . (a flawless cell), describing one row of the marble.-1.