Example

Input

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


Output

0
#include<iostream>
using namespace std;

int main() {
  int table[10][10], temp2[10][10][10][10], count = 0, f;
  
  for (int i = 0; i < 10000; i++) temp2[i/1000][(i/100)%10][(i/10)%10][i%10]  = -1;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      cin >> table[i][j];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
	for (int l = 0; l < 10; l++) {
	  temp2[i][j][k][l] = table[table[table[table[0][i]][j]][k]][l];
	}
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
	for (int l = 0; l < 10; l++){
	  f = 0;
	  if(i != j && table[temp2[j][i][k][l]][temp2[i][j][k][l]] == 0){
	    count++;
	    continue;
	  } else if(j != k && table[temp2[i][k][j][l]][temp2[i][j][k][l]] == 0){
	    count++;
	    continue;
	  } else if(k != l && table[temp2[i][j][l][k]][temp2[i][j][k][l]] == 0){
	    count++;
	    continue;
	  }else if(l != temp2[i][j][k][l] && table[temp2[i][j][k][temp2[i][j][k][l]]][l] == 0){
	    count++;
	    continue;
	  }
	  for(int m = 0; m < 10; m++){
	    if(m != i){
	      if(table[temp2[m][j][k][l]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != j){
	      if(table[temp2[i][m][k][l]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != k){
	      if(table[temp2[i][j][m][l]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != l){
	      if(table[temp2[i][j][k][m]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != temp2[i][j][k][l]){
	      if(table[temp2[i][j][k][l]][m] == 0){
		f = 1;
		break;
	      }
	    }
	  }
	  if(f == 1) count++;
	}
      }
    }
  }

  cout<<count<<endl;
  
  
  return 0;
}

