Emperor's Palace

시간 제한2초메모리 제한1024 MB

요약
막힌 칸이 있는 격자에서 세로 막대와 세 개의 가로 날개로 이루어진 E자 모양의 최대 넓이를 구한다.
난이도

보통10점 중 7점

유형
구현, 완전 탐색, 누적 합, 배열
정답자
아직 제출이 없습니다

문제

The great Emperor Emelyan I is building a palace for himself. To emphasize the greatness of the Emperor, the palace must be huge --- it must be visible from space. In addition, the palace must be in the shape of the letter E.

More formally, the palace should be a union of four rectangles: the main building of size a×1a \times 1 and three wings of size 1×b1 \times b, adjacent to the main building from the east, where aa and bb are positive integers numbers and a≥5a \ge 5. The north wing should be adjacent to the upper right corner of the main building, and the south wing should be adjacent to the lower right. The middle wing should not adjoin either the north or south wing, but should adjoin with its upper left corner to the main building at an integer distance from the upper right corner of the main building.

In other words, the palace must completely occupy the following squares 1×11 \times 1 of some rectangle of size a×(b+1)a \times (b+1): all squares adjacent to the left, upper or lower side of the rectangle, plus some line inside the rectangle, which is not adjacent to the top and bottom line.

The palace covers an area of a+3ba+3b.

The area for the construction of the future palace is a rectangle of size h×wh \times w, divided into cells of size 1×11 \times 1. Some cells are occupied by the Emperor's gardens, which cannot be built on. The rest of the cells are free and you can build on them.

Determine the largest area of the palace that can be built on empty spaces.

입력

The first line contains two integers hh and ww (5≤h,w≤1065 \le h,w \le 10^6, h×w≤5×106h \times w \le 5 \times 10^6).

Each of the following hh lines contains ww characters. The jj-th character in the ii-th of these lines is equal to "#" if the cell with coordinates (i,j)(i,j) is occupied and "." --- if this cell is free.

출력

Print one integer --- the largest possible area of the palace. If it is impossible to build a palace, print "\texttt {-1}".

예제2

  1. 예제 1

    입력
    6 6
    #.....
    ....#.
    ..####
    ....##
    ..##..
    ......
    
    예상 출력
    14
    
  2. 예제 2

    입력
    6 6
    #.....
    ...##.
    ..####
    ....##
    ..##..
    ......
    
    예상 출력
    12