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 int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
int tbl[10][10];
string to_s(int n) {
  char number[6];
  sprintf(number, "%05lld", n);
  return string(number);
}
int check(const string &s) {
  int d = tbl[0][s[0] - '0'];
  d = tbl[d][s[1] - '0'];
  d = tbl[d][s[2] - '0'];
  d = tbl[d][s[3] - '0'];
  d = tbl[d][s[4] - '0'];
  return d == 0;
}
string make(int n) {
  char number[5];
  sprintf(number, "%04lld", n);
  string s = string(number);
  int d = tbl[0][s[0] - '0'];
  d = tbl[d][s[1] - '0'];
  d = tbl[d][s[2] - '0'];
  d = tbl[d][s[3] - '0'];
  s.push_back(d + '0');
  return s;
}
signed main() {
  ios::sync_with_stdio(false);
  REP(i,10) REP(j,10) cin >> tbl[i][j];
  int error = 0;
  REP(n,10000) {
    string s = make(n);
    if(!check(s)) continue;
    bool e = false;
    REP(i,5) REP(j,10) {
      string t = s;
      t[i] = '0' + j;
      if(t != s) {
        if(check(t)) {
          e = true;
          // DEBUG(s);
          // DEBUG(t);
        }
      }
    }
    REP(i,4) {
      string t = s;
      swap(t[i], t[i + 1]);
      if(t != s) {
        if(check(t)) {
          e = true;
          // DEBUG(s);
          // DEBUG(t);
        }
      }
    }
    if(e) {
      error++;
    }
  }
  cout << error << endl;
}