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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>

int table[10][10] = {0};

int e(const std::string& s) {
	int a = s[0] - '0',
		b = s[1] - '0',
		c = s[2] - '0',
		d = s[3] - '0';
	return table[table[table[table[0][a]][b]][c]][d];
}

bool check(const std::string& s) {
	int ee = s[4] - '0';
	return table[e(s)][ee] == 0;
}

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

	int num = 0;
	for (int i = 0; i < 10000; i++) {
		char* cp = new char[5];
		std::sprintf(cp, "%04d", i);
		std::string s = cp;
		s += std::to_string(e(s));
		int zeroCount = 1;
		// 1桁打ち間違い
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 10; k++) {
				if (s[j] == '0' + k) continue;

				char c = s[j];
				s[j] = '0' + k;
				if (check(s)) zeroCount++;
				s[j] = c;
			}
		}
		// 入れ替え
		for (int j = 0; j < 4; j++) {
			if (s[j] == s[j + 1]) continue;

			std::string s2 = s;
			std::swap(s2[j], s2[j + 1]);
			if (check(s2)) zeroCount++;
		}
		if (zeroCount != 1) {
			num++;
		}
	}
	std::cout << num << std::endl;
	return 0;
}
