import java.util.Scanner;
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];
int[][] arr2 = new int[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];
}
}
for(int l = 0; l < n; l++) {
if(arr[l][k] < i) {
arr2[j][k] = arr2[j][k] + arr2[l][k];
}
}
}
}
}
}
int sum = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
sum = sum + arr2[i][j];
}
System.out.print(sum);
}
}