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:
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

	int ret = 0;
	REP(i1, 10) REP(i2, 10) REP(i3, 10) REP(i4, 10) {
		int tmp = a[a[a[a[0][i1]][i2]][i3]][i4];
		int num[] = {(int)i1, (int)i2, (int)i3, (int)i4, tmp};
		bool flag = false;
		//1??????????????´???
		REP(j1, 5) REP(j2, 10) {
			if(num[j1] == j2) continue;
			int b = 0;
			REP(k, 5) {
				if(j1 == k) b = a[b][j2];
				else b = a[b][num[k]];
			}
			if(!b) flag = true;
		}
		//??\??????????????´???
		REP(j, 4) {
			int n[5];
			REP(k, 5) n[k] = num[k];
			if(n[j] == n[j+1]) continue;
			swap(n[j], n[j+1]);
			int b = 0;
			REP(k, 5) b = a[b][n[k]];
			if(!b) flag = true;
		}
		if(flag) ret++;
	}
	cout << ret << endl;
	return 0;
}