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 <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int main(void)
{
  int ssn[10][10];
  int answer=0;
  REP(i,10) REP(j,10) cin >> ssn[i][j];
  REP(i,10) REP(j,10) REP(k,10) REP(l,10){
    bool flag=false;
    int d=ssn[ssn[ssn[ssn[0][i]][j]][k]][l];
    REP(e,10){
      if(i==e) continue;
      if(ssn[ssn[ssn[ssn[ssn[0][e]][j]][k]][l]][d]==0) flag=true;
    }
    REP(e,10){
      if(j==e) continue;
      if(ssn[ssn[ssn[ssn[ssn[0][i]][e]][k]][l]][d]==0) flag=true;\
    }
    REP(e,10){
      if(k==e) continue;
      if(ssn[ssn[ssn[ssn[ssn[0][i]][j]][e]][l]][d]==0) flag=true;
    }
    REP(e,10){
      if(l==e) continue;
      if(ssn[ssn[ssn[ssn[ssn[0][i]][j]][k]][e]][d]==0) flag=true;
    }
    REP(e,10){
      if(d==e) continue;
      if(ssn[ssn[ssn[ssn[ssn[0][i]][j]][k]][l]][e]==0) flag=true;
    }
    if(i!=j && ssn[ssn[ssn[ssn[ssn[0][j]][i]][k]][l]][d]==0) flag=true;
    if(j!=k && ssn[ssn[ssn[ssn[ssn[0][i]][k]][j]][l]][d]==0) flag=true;
    if(k!=l && ssn[ssn[ssn[ssn[ssn[0][i]][j]][l]][k]][d]==0) flag=true;
    if(l!=d && ssn[ssn[ssn[ssn[ssn[0][i]][j]][k]][d]][l]==0) flag=true;
    if(flag) ++answer;
  }
  cout << answer << endl;
  return 0;
}