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"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int check(vvi &v,int i) {
	int res = 10000;
	int c = 0,a=i;
	REP(j, 5) {
		c = v[c][a / res];
		a %= res;
		res /= 10;
	}
	return c;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vvi v(10, vi(10));
	REP(i, 10)REP(j, 10)cin >> v[i][j];
	int cnt = 0;
	vi digit(10000);
	REP(i, 10000) {
		int a = i, res = 1000, c = 0;
		REP(j, 4) {
			c = v[c][a / res];
			a %= res;
			res /= 10;
		}
		digit[i] = c;
	}

	REP(i, 10000) {
		int a = i;
		string s;
		REP(j, 4) {
			s = char(a % 10 + '0') + s;
			a /= 10;
		}
		s += char(digit[i] + '0');
		string tmp = s;

		REP(j, 5) {
			REP(k, 10) {
				tmp = s;
				tmp[j] = k + '0';
				if (s == tmp)continue;
				if (check(v,stoi(tmp))==0) {
					cnt++;
					goto next;
				}
			}
		}
		REP(j, 4) {
			tmp = s;
			swap(tmp[j], tmp[j + 1]);
			if (s == tmp)continue;
			if (check(v, stoi(tmp))==0) {
				cnt++;
				//cout << i << endl;
				goto next;
			}
			
		}
	next:;
	}
	cout << cnt << endl;

	return 0;
}