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;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<vector<int>> x(10, vector<int>(10));
  for (auto&& v : x) {
    for (auto&& e : v) {
      cin >> e;
    }
  }
  auto check = [&](int a, int b, int c, int d, int e) {
    return x[x[x[x[x[0][a]][b]][c]][d]][e];
  };
  int res = 0;
  for (int a = 0; a < 10; ++a) {
    for (int b = 0; b < 10; ++b) {
      for (int c = 0; c < 10; ++c) {
        for (int d = 0; d < 10; ++d) {
          int e = x[x[x[x[0][a]][b]][c]][d];
          bool ok = true;
          for (int i = 0; i < 10; ++i) {
            if (i != a and check(i, b, c, d, e) == 0) {
              ok = false;
            }
            if (i != b and check(a, i, c, d, e) == 0) {
              ok = false;
            }
            if (i != c and check(a, b, i, d, e) == 0) {
              ok = false;
            }
            if (i != d and check(a, b, c, i, e) == 0) {
              ok = false;
            }
            if (i != e and check(a, b, c, d, i) == 0) {
              ok = false;
            }
          }
          if (a != b and check(b, a, c, d, e) == 0) {
            ok = false;
          }
          if (b != c and check(a, c, b, d, e) == 0) {
            ok = false;
          }
          if (c != d and check(a, b, d, c, e) == 0) {
            ok = false;
          }
          if (d != e and check(a, b, c, e, d) == 0) {
            ok = false;
          }
          res += not ok;
        }
      }
    }
  }
  cout << res << '\n';
}

