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 <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int tbl[10][10];
int cd[10][10][10][10];

int same(int a1, int b1, int c1, int d1, int e1, int a2, int b2, int c2, int d2, int e2) {
  return a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2 && e1 == e2;
}

int check(int a, int b, int c, int d, int e) {
  return !tbl[cd[a][b][c][d]][e];
}

int main(void) {
  REP(i, 0, 10) REP(j, 0, 10) cin >> tbl[i][j];

  REP(a, 0, 10) REP(b, 0, 10) REP(c, 0, 10) REP(d, 0, 10) {
    cd[a][b][c][d] = tbl[tbl[tbl[tbl[0][a]][b]][c]][d];
  }

  int cnt = 0, e;
  REP(a, 0, 10) REP(b, 0, 10) REP(c, 0, 10) REP(d, 0, 10) {
    e = cd[a][b][c][d];
    if(!same(a, b, c, d, e, b, a, c, d, e) && check(b, a, c, d, e)) { cnt++; continue; }
    if(!same(a, b, c, d, e, a, c, b, d, e) && check(a, c, b, d, e)) { cnt++; continue; }
    if(!same(a, b, c, d, e, a, b, d, c, e) && check(a, b, d, c, e)) { cnt++; continue; }
    if(!same(a, b, c, d, e, a, b, c, e, d) && check(a, b, c, e, d)) { cnt++; continue; }

    REP(i, 0, 10) if(!same(a, b, c, d, e, i, b, c, d, e) && check(i, b, c, d, e)) { cnt++; goto CONT; }
    REP(i, 0, 10) if(!same(a, b, c, d, e, a, i, c, d, e) && check(a, i, c, d, e)) { cnt++; goto CONT; }
    REP(i, 0, 10) if(!same(a, b, c, d, e, a, b, i, d, e) && check(a, b, i, d, e)) { cnt++; goto CONT; }
    REP(i, 0, 10) if(!same(a, b, c, d, e, a, b, c, i, e) && check(a, b, c, i, e)) { cnt++; goto CONT; }
    REP(i, 0, 10) if(!same(a, b, c, d, e, a, b, c, d, i) && check(a, b, c, d, i)) { cnt++; goto CONT; }

CONT: continue;
  }

  cout << cnt << endl;

  return 0;
}