Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int x[10][10];

int conv(int a, int b, int c, int d) {
  return x[x[x[x[0][a]][b]][c]][d];
}

int check(int a, int b, int c, int d, int e) {
  return x[conv(a, b, c, d)][e] == 0;
}

bool out(int a, int b, int c, int d, int e) {
  bool res = false;
  for (int i = 0; i < 10; i++) {
    if (i != a) res |= check(i, b, c, d, e);
    if (i != b) res |= check(a, i, c, d, e);
    if (i != c) res |= check(a, b, i, d, e);
    if (i != d) res |= check(a, b, c, i, e);
    if (i != e) res |= check(a, b, c, d, i);
  }
  if (a != b) res |= check(b, a, c, d, e);
  if (b != c) res |= check(a, c, b, d, e);
  if (c != d) res |= check(a, b, d, c, e);
  if (d != e) res |= check(a, b, c, e, d);
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> x[i][j];
    }
  }

  int ans = 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++) {
          if (out(a, b, c, d, conv(a, b, c, d))) ans++;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}