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;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

vector<vi> v(10, vi(10));

int gen(string s)
{
	int res = 0;		
	REP(i, s.size())
	{
		res = v[res][s[i] - '0'];
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> v;
	vs ids;
	REP(i, 10)REP(j, 10)REP(k, 10)REP(l, 10)
	{
		string tmp;
		tmp += to_string(i);
		tmp += to_string(j);
		tmp += to_string(k);
		tmp += to_string(l);
		ids.push_back(tmp);
	}
	int ans = 0;
	for (auto id : ids)
	{
		int cd = gen(id);
		id += char(cd + '0');
		bool f = false;
		REP(i, 5)REP(j, 10)
		{
			string s = id;
			s[i] = j + '0';
			if (s == id) continue;
			int a = gen(s);
			if (a == 0) f = true;
		}
		REP(i, 4)
		{
			string s = id;
			swap(s[i], s[i + 1]);
			if (s == id) continue;
			int a = gen(s);
			if (a == 0) f = true;
		}
		if (f) ans++;
	}
	cout << ans << endl;
	return 0;
}
