Problem: See Russian Translation

The end semester exams are now approaching. Ritu is the Computer Science Teacher of  Coder Public School. He has been assigned the task of preparing good algorithmic problems for the students by the Dean of the school.

Ritu like every other teacher has his own favorite topics. Ritu likes matrices and maths. So, he tries to create a problem that contains a mixture of both the things. After thinking for weeks, he comes up with a really awesome problem to blow away the minds of his students. But, before giving this problem in the exam he wants to check whether it's tough for his students or not. So, he gives his problem to you to solve so that he could decide whether his problem is good enough or not. So here goes the problem:

Given an N*N matrix where each cell in the matrix contains number between 1 to 100. The students are required to report the total number of decreasing paths.

From a particular cell (x,y) you can only go to cells (x+1,y) , (x-1,y) , (x,y+1) , (x,y-1) but you can't go outside the matrix, and you can't go to cell with higher or equal number than the number in current cell.

Since the number of such paths could be huge he asks them to tell him modulo 10^9+7. A path of only one cell is counted as a path.

So try your hand on Ritu's problem and give him a feedback on his problem so that he could decide whether his problem was good enough or not.

Input:

The first line contains the integer N denoting the size of matrix.

This is followed by N lines where each line contains N space separated integers.

Output:

Print the total number of such paths Modulo 10^9+7.

Constraints:

1 ≤ N ≤1000

1 ≤ Numbers in matrix cells ≤100

SAMPLE INPUT
2
1 2
1 3

SAMPLE OUTPUT
8

Explanation

Length 1 Paths : (1) , (1) , (2) , (3)

Length 2 Paths : (2,1) , (3,1) , (3,2)

Length 3 Paths : (3,2,1)

Solution (in PYTHON):

Solution:
__author__ = 'siddharth'

D = None
N = 0
MOD = 1000000007

def vfoo():
    for i in sorted(D.iteritems(), key=lambda v: v[1]):
        yield i

def indices(i):
    u, v = i/N, i%N
    I = list()
    if u > 0:
        I.append((u-1)*N + v)
    if u < N-1:
        I.append((u+1)*N + v)
    if v > 0:
        I.append(u*N + v-1)
    if v < N-1:
        I.append(u*N + v+1)

    for i in I:
        yield i

if __name__ == "__main__":

    N = int(raw_input())
    D = dict()

    CT = {k: 1 for k in xrange(N**2)}

    for n in xrange(N):
        L = map(int, raw_input().split())
        for i, l in enumerate(L):
            D[n*N + i] = l

    for i, v in vfoo():
        for j in indices(i):
            if D[j] > v:
                CT[j] += CT.get(i, 1)

    print sum(CT.itervalues())%MOD