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>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<numeric>
#include<limits>
#include<bitset>
#include<unordered_map>
#include<functional>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define rng(a,b,e) a.begin()+b,a.begin()+e
#define DEBUG
typedef pair<int,int> II;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e+9;
const int SIZE = 10;

int x[SIZE][SIZE];

void solve();

int main() {
  rep(i,0,SIZE) rep(j,0,SIZE) cin>>x[i][j];
  solve();
  return 0;
}

void solve() {
  int res = 0;
  rep(a,0,SIZE) {
    rep(b,0,SIZE) {
      rep(c,0,SIZE) {
        rep(d,0,SIZE) {
          int e = x[x[x[x[0][a]][b]][c]][d];

          rep(a_,0,SIZE) {
            if(a_ != a && x[x[x[x[x[0][a_]][b]][c]][d]][e] == 0) { res++; goto EXIT; }
          }
          rep(b_,0,SIZE) {
            if(b_ != b && x[x[x[x[x[0][a]][b_]][c]][d]][e] == 0) { res++; goto EXIT; }
          }
          rep(c_,0,SIZE) {
            if(c_ != c && x[x[x[x[x[0][a]][b]][c_]][d]][e] == 0) { res++; goto EXIT; }
          }
          rep(d_,0,SIZE) {
            if(d_ != d && x[x[x[x[x[0][a]][b]][c]][d_]][e] == 0) { res++; goto EXIT; }
          }
          rep(e_,0,SIZE) {
            if(e_ != e && x[x[x[x[x[0][a]][b]][c]][d]][e_] == 0) { res++; goto EXIT; }
          }

          if(a != b && x[x[x[x[x[0][b]][a]][c]][d]][e] == 0) { res++; goto EXIT; }
          if(b != c && x[x[x[x[x[0][a]][c]][b]][d]][e] == 0) { res++; goto EXIT; }
          if(c != d && x[x[x[x[x[0][a]][b]][d]][c]][e] == 0) { res++; goto EXIT; }
          if(d != e && x[x[x[x[x[0][a]][b]][c]][e]][d] == 0) { res++; goto EXIT; }
          EXIT: ;
        }
      }
    }
  }

  cout<<res<<endl;
}