import java.util.Scanner;
import java.math.BigInteger;
public class Ruudukko {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[][] arr = new int[n][n];
Long[][] arr2 = new Long[n][n];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
arr[i][j] = scan.nextInt();
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
arr2[i][j] = 1;
}
}
for(int i = 2; i <= n*n; i++) {
for(int j = 0; j < n; j++) {
for(int k = 0; k < n; k++) {
if(arr[j][k] == i) {
for(int l = 0; l < n; l++) {
if(arr[j][l] < i) {
arr2[j][k] = (arr2[j][k] + arr2[j][l])%1000000007;
}
}
for(int l = 0; l < n; l++) {
if(arr[l][k] < i) {
arr2[j][k] = (arr2[j][k] + arr2[l][k])%1000000007;
}
}
}
}
}
}
Long sum = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
sum = (sum + arr2[i][j])%1000000007;
}
}
System.out.print(sum);
}
}