Multiplayer Moo#10386

Multiplayer Moo

2 seconds
256 megabytes
Hard

The cows have come up with a creative new game and, surprisingly, have given it the least creative name possible: "Moo".

Moo is played on an n \times n grid of square cells. A cow claims a cell by yelling "moo!" and writing her numeric ID in it.

At the end of the game, every cell contains a number. At this point, a cow wins the game if she has created a region of connected cells at least as large as any other region. A region is a group of cells with the same ID that is connected: from any cell of the region, one can reach any other cell of it by moving between cells of the region that are adjacent horizontally or vertically (diagonal neighbors do not count).

Since playing individually is a bit boring, the cows are also interested in teaming up in pairs. A team of two cows can create a region in the same way, but now each cell of the region may belong to either of the two cows on the team.

Given the final state of the game board, help the cows compute the size of the largest region owned by a single cow and the size of the largest region that can be claimed by a team of two cows. A region claimed by a two-cow team counts only if it contains the IDs of both cows on the team, not just one of them.

Input

The first line contains an integer n~(1 \le n \le 250). Each of the next lines contains integers from to 10^6, describing the final state of the game board. The board contains at least two distinct IDs.

Output

In the first line, print the size of the largest region claimed by a single cow. In the second line, print the size of the largest region claimed by a team of two cows.

Examples

Example 1

Loading
Loading

Note

In this example, the largest region of a single cow consists of five 's. If the cows with IDs and team up, they can form a region of size .