is writing a problem for a programming contest. However, there is one issue: he can't solve it and needs your help.

The problem goes as follows:

Given an matrix of numbers, what is the longest

strictlyincreasing path through the matrix, assuming that you can only move horizontally or vertically?

Being the good friend that you are, can you help him do it?

**Note: If you are using Python 2/3, submit using PyPy 2/3 instead because it is significantly faster**

#### Input Specification

The first line contains .

The next lines each contain space separated integers that denote the matrix.

#### Output Specification

On a line, output the longest **strictly** increasing path in the matrix.

#### Constraints

For all subtasks:

##### Subtask 1 [5%]

##### Subtask 2 [20%]

##### Subtask 3 [75%]

#### Sample Input 1

```
3
9 8 4
7 2 3
6 1 5
```

#### Sample Output 1

`5`

#### Explanation for Sample Output 1

To get the longest **strictly** increasing path you can traverse the values of the matrix in the following order: . Since path length is calculated by how many movements you have to make and not by the amount of values that you touch, the answer is instead of .

Note that the values aren't guaranteed to be unique in the actual test data.

#### Sample Input 2

```
3
1 2 3
8 9 4
7 6 5
```

#### Sample Output 2

`8`

#### Explanation for Sample Output 2

The longest path is a spiral starting from and ending at .

## Comments

Does "strictly increasing" mean that a value must be greater than the previous value, or greater than/equal to?

All the numbers must be greater than the previous one. E.g the sequence is strictly increasing, but the sequence is not.

Why does this submission (https://dmoj.ca/submission/3096627) using ArrayList and Collections.sort pass while this identical submission (https://dmoj.ca/submission/3096626) using a normal array fail? Aren't ArrayLists generally slower?

Looks like it might be due to a difference between sorting algorithms.

This problem seems more like dp than graph theory.