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++)

using namespace std;

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;
}