Figure Eight

No attempts yetTime limit1sMemory limit128 MB

Problem

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:

  • Each rectangle encloses at least one interior cell.
  • The two rectangles share a single horizontal line: the bottom edge of the top rectangle lies on the top edge of the bottom rectangle and is a (not necessarily proper) sub-segment of it. In other words, both edges sit on the same row, and the top rectangle's left and right columns lie between the bottom rectangle's left and right columns, endpoints included.
  • Every cell along the outline (all four sides of both rectangles) must be flawless (.). 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.

Input

  • Line 1: a single integer $N$, the side length of the slab.
  • Lines $2 \ldots N+1$: each line has $N$ characters, each either * (an imperfection) or . (a flawless cell), describing one row of the marble.

Output

  • A single line: the highest aesthetic score of any figure eight whose outline uses no imperfect cells. If no figure eight is attainable, output -1.