cho.sh
Notes
Loading...

Greedy Panda

Time limit

2s

Memory limit

256 MB

Problem

An n × n bamboo forest is given. A greedy panda starts eating bamboo in one cell. After eating all the bamboo there, it may move to one of the four adjacent cells: up, down, left, or right.

The panda has one rule: it only moves to a cell that contains strictly more bamboo than the cell it just left.

The zookeeper wants to release the panda at the best starting cell and guide it along the best route so that the panda visits as many cells as possible. Given the bamboo amounts in every cell of the forest, find the maximum number of cells the panda can visit.

Input

The first line contains the forest size n (1 ≤ n ≤ 500).

Each of the next n lines contains n integers separated by spaces. Each integer is the amount of bamboo in that cell, and every amount is a natural number no greater than 1,000,000.

Output

Print the maximum number of cells the panda can visit.