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;

int tb[10][10];
int flg[10000];

int ce(int a, int b, int c, int d)
{
	return tb[tb[tb[tb[0][a]][b]][c]][d];
}

bool chk(int a, int b, int c, int d)
{
	int e = ce(a, b, c, d), te = -1;
	for (int i = 0; i <= 9; i++)
	{
		te = tb[ce(i, b, c, d)][e];
		if (i != a && te == 0) return true;
		te = tb[ce(a, i, c, d)][e];
		if (i != b && te == 0) return true;
		te = tb[ce(a, b, i, d)][e];
		if (i != c && te == 0) return true;
		te = tb[ce(a, b, c, i)][e];
		if (i != d && te == 0) return true;
		te = tb[ce(a, b, c, d)][i];
		if (i != e && te == 0) return true;
	}
	te = tb[ce(b, a, c, d)][e];
	if (a != b && te == 0) return true;
	te = tb[ce(a, c, b, d)][e];
	if (b != c && te == 0) return true;
	te = tb[ce(a, b, d, c)][e];
	if (c != d && te == 0) return true;
	te = tb[ce(a, b, c, e)][d];
	if (d != e && te == 0) return true;
	return false;
}

int main()
{
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			scanf("%d", &tb[i][j]);
	int ans = 0;
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				for (int l = 0; l < 10; l++)
				{
					ans += chk(i,j,k,l);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}