QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#13821. Chessboard Making

统计

Chess is one of the oldest board games in the world, sharing fame with Chinese Go, Chinese Chess, and Japanese Shogi. It is said that chess originated from the philosophy of the I Ching, where the board is an $8 \times 8$ black-and-white grid, corresponding to the sixty-four hexagrams, with black and white representing yin and yang.

Our protagonist, Xiao Q, is a fanatical chess enthusiast. As a top-tier player, he is no longer satisfied with the standard board and rules, so he and his good friend Xiao W decided to expand the board to accommodate their new rules.

Xiao Q found a rectangular piece of paper composed of $N \times M$ square cells, where each cell is colored either black or white. Xiao Q wants to cut out a portion of this paper to serve as a new board. Naturally, he hopes this board will be as large as possible.

However, Xiao Q has not yet decided whether to look for a square board or a rectangular board (of course, regardless of the type, the board must be alternating black and white, meaning adjacent cells must have different colors). Therefore, he hopes to find the maximum area of a square board and the maximum area of a rectangular board to decide which is better.

Xiao Q has come to you, as you are about to participate in the National Olympiad in Informatics. Can you help him?

Input

The first line contains two integers $N$ and $M$, representing the length and width of the rectangular paper. The following $N$ lines contain an $N \times M$ matrix of 0s and 1s, representing the colors of the rectangular paper (0 represents white, 1 represents black).

Output

The output should contain two lines, each containing an integer. The first line is the area of the largest square board that can be found, and the second line is the area of the largest rectangular board that can be found (note that the square and rectangle can overlap or be contained within one another).

Constraints

For 20% of the data, $N, M \le 80$. For 40% of the data, $N, M \le 400$. For 100% of the data, $N, M \le 2000$.

Examples

Input 1

3 3
1 0 1
0 1 0
1 0 0

Output 1

4
6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.