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
#include <bits/stdc++.h>
using namespace std;

int X[11][11];

int batu(int a, int b, int c, int d) {	
	int e = X[0][a];
	int f = X[e][b];
	e = X[f][c];
	f = X[e][d];
	return f;
}

bool check(int a, int b, int c, int d, int e) {
	int f = X[0][a];
	int g = X[f][b];
	f = X[g][c];
	g = X[f][d];
	return !!X[g][e];
}

int main() {
	for ( int i = 0; i < 10; i++ ) {
		for ( int j = 0; j < 10; j++ ) cin >> X[i][j];
	}

	int ans = 0;
	for ( int a = 0; a < 10; a++ ) {
		for ( int b = 0; b < 10; b++ ) {
			for ( int c = 0; c < 10; c++ ) {
				for ( int d = 0; d < 10; d++ ) {					
					int e = batu(a, b, c, d);							
					bool flag = true;
					for ( int i = 0; i < 10; i++ ) {
						if ( i == a ) continue;
						flag &= check(i, b, c, d, e);
					}

					for ( int i = 0; i < 10; i++ ) {
						if ( i == b ) continue;
						flag &= check(a, i, c, d, e);
					}

					for ( int i = 0; i < 10; i++ ) {
						if ( i == c ) continue;
						flag &= check(a, b, i, d, e);
					}

					for ( int i = 0; i < 10; i++ ) {
						if ( i == d ) continue;
						flag &= check(a, b, c, i, e);
					}

					for ( int i = 0; i < 10; i++ ) {
						if ( i == e ) continue;
						flag &= check(a, b, c, d, i);
					}
					
					if ( a != b ) flag &= check(b, a, c, d, e);
					if ( b != c ) flag &= check(a, c, b, d, e);
					if ( c != d ) flag &= check(a, b, d, c, e);
					if ( d != e ) flag &= check(a, b, c, e, d);					

					if ( !flag ) ans++;					
				}
			}
		}
	}

	cout << ans << endl;
	
	return 0;
}

