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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int cal[10][10];
int check(int a, int b, int c, int d, int err) {
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][i]][b]][c]][d]][err] == 0 && i != a) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][i]][c]][d]][err] == 0 && i != b) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][b]][i]][d]][err] == 0 && i != c) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][b]][c]][i]][err] == 0 && i != d) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][b]][c]][d]][i] == 0 && i != err) {
      return -1;
    }
  }

  if(cal[cal[cal[cal[cal[0][b]][a]][c]][d]][err] == 0 && a != b) return -1;
  if(cal[cal[cal[cal[cal[0][a]][c]][b]][d]][err] == 0 && b != c) return -1;
  if(cal[cal[cal[cal[cal[0][a]][b]][d]][c]][err] == 0 && c != d) return -1;
  if(cal[cal[cal[cal[cal[0][a]][b]][c]][err]][d] == 0 && d != err) return -1;

  return 1;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  FOR(i,0,10) FOR(j,0,10) cin >> cal[i][j];
  int ans = 0;
  FOR(a,0,10) {
    FOR(b,0,10) {
      FOR(c,0,10) {
        FOR(d,0,10) {
          int err = cal[cal[cal[cal[0][a]][b]][c]][d];
          if(check(a,b,c,d,err) == -1) ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return  0;
}