407563: GYM102829 J Island Grid

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Island Gridtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Often, UTPC problem writers struggle to make the problem that they come up with match the particular theme of the week. For example, here is a problem that the UTPC officers found hard to fit inside this week's meta theme. You are given a 2D grid of numbers and want to find the highest value island that you can create out of this grid. You can create an island by picking an initial starting coordinate and taking all grid spaces such that there exists a path taking only cardinal directions with grid values that are only greater than or equal to the grid value at the initial starting coordinate. The value of the island is the grid value at the initial starting coordinate multiplied by the number of grid entries that the island covers. Can you find the maximum value island on the grid? If there are multiple islands with equal value, always take the one that covers more grid entries.

Input

The first line of the input will consist of a single integer $$$n$$$ ($$$1 \leq n \leq 500$$$). The next $$$n$$$ lines of input will each consist of $$$n$$$ integers, $$$a_{ij}$$$ ($$$1 \leq a_{ij} \leq 10^9$$$).

Output

Output two space-separated integers, the maximum value of an island you can create and the size of the associated island.

ExamplesInput
3
1 1 1
1 10 1
1 1 1
Output
10 1
Input
3
1 1 1
1 9 1
1 1 1
Output
9 9
Note

For the first test case, it is optimal to take the $$$10$$$ spot only. For the second test case, it is optimal to take the entire grid.

加入题单

算法标签: