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>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)

int table[10][10];
int ans = 0;
bool flag = 0;

int ssn(string s){
  while(s.size() < 4) s = '0' + s;
  assert(s.size() >= 4);
  int ret = 0;
  ret = table[ret][s[0] - '0'];
  ret = table[ret][s[1] - '0'];
  ret = table[ret][s[2] - '0'];
  ret = table[ret][s[3] - '0'];
  return ret;
}


void check(int tar){
  string tars = to_string(tar);
  while(tars.size() < 4) tars = '0' + tars;
  int e = ssn(tars);
  tars = tars + char(e+'0');
  string orig = tars;
  rep(i,4){
    swap(tars[i],tars[i+1]);
    if(tars != orig && table[ssn(tars)][tars[4]-'0'] == 0) flag = 1;
    swap(tars[i],tars[i+1]);
  }
  rep(i,5)rep(j,10){
    string tt = orig;
    tt[i] = j + '0';
    if(tt != orig && table[ssn(tt)][tt[4] - '0'] == 0) flag = 1;
  }
  assert(tars == orig);
  //cerr << tars << endl;
  //if(flag)cerr << tar << endl;
}


int main(){
  rep(i,10)rep(j,10) cin >> table[i][j];
  rep(i,10000){
    flag = 0;
    check(i);
    ans += flag;
  }
  cout << ans << endl;
  //cerr<< ssn("2016111") << endl;
}

