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>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,o,n) for(int i=o; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define pb push_back
#define eb emplace_back

#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const ll MOD = 1e9+7;

int mp[10][10];
int ans;
bool check(int a, int b, int c, int d, int e,
int oa, int ob, int oc, int od, int oe){
  if(a==oa &&
b==ob &&
c==oc &&
d==od &&
     e==oe ) return 0;
	return mp[ mp[ mp[ mp[ mp[0][a] ][b] ][c] ][d] ][e] == 0;
}

int main(){
	ans = 0;
	rep(i,10) rep(j,10){
		cin >> mp[i][j];
	}

	rep(a,10) rep(b,10) rep(c,10) rep(d,10){
		int e = mp[ mp[ mp[ mp[0][a] ][b] ][c] ][d];
		bool f = false;
		rep(i,10) if(i!=a) f |= check(i,b,c,d,e,a,b,c,d,e);
		rep(i,10) if(i!=b) f |= check(a,i,c,d,e,a,b,c,d,e);
		rep(i,10) if(i!=c) f |= check(a,b,i,d,e,a,b,c,d,e);
		rep(i,10) if(i!=d) f |= check(a,b,c,i,e,a,b,c,d,e);
		rep(i,10) if(i!=e) f |= check(a,b,c,d,i,a,b,c,d,e);
		f |= check(b,a,c,d,e,a,b,c,d,e);
		f |= check(a,c,b,d,e,a,b,c,d,e);
		f |= check(a,b,d,c,e,a,b,c,d,e);
		f |= check(a,b,c,e,d,a,b,c,d,e);
		if( f ) ans++;
	}

	cout << ans << endl;

	return 0;
}