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<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int tra[10][10];
int ten[4] = { 1000,100,10,1 };
int trans(int n) {
	int res = 0;
	res = tra[res][n / 1000];
	res = tra[res][n / 100 - 10*(n / 1000)];
	res = tra[res][n / 10 - 10*(n / 100)];
	res = tra[res][n - 10*(n / 10)];
	return res;
}
int main() {
	rep(i, 10) {
		rep(j, 10) {
			cin >> tra[i][j];
		}
	}
	int x[10000];
	rep(i, 10000) {
		x[i] = trans(i);
	}
	int cnt = 0;
	rep(i, 10000) {
		int y[4];
		rep(j, 4) {
			y[j] = i / ten[j]-10*(i/(10*ten[j]));
		}
		bool f = false;
		rep(j, 4) {
			rep(k, 10) {
				if (k == y[j])continue;
				int r = i;
				r -= ten[j] * (r / ten[j]-10*(r/(10*ten[j])));
				r += k * ten[j];
				if (tra[x[r]][x[i]]==0) {
					f = true;
				}
				if (f)break;
			}
			if (f)break;
		}
		rep(j, 10) {
			if (x[i] == j)continue;
			if (tra[x[i]][j] == 0)f = true;
		}
		if (y[0] != y[1]) {
			int r = i;
			r %= 100;
			r += 100 * y[0] + 1000 * y[1];
			if (tra[x[r]][x[i]]==0)f = true;
		}
		if (y[1] != y[2]) {
			int r = i;
			r %= 10;
			r += 100 * y[2] + 10 * y[1] + 1000 * y[0];
			if (tra[x[r]][x[i]] == 0)f = true;
		}
		if (y[2] != y[3]) {
			int r = 1000 * y[0] + 100 * y[1] + 10 * y[3] + y[2];
			if (tra[x[r]][x[i]] == 0)f = true;
		}
		if (y[3] != x[i]) {
			int memo = y[3];
			int r = i - memo + x[i];
			if (tra[x[r]][memo] == 0)f = true;
		}
		if (f)cnt++;
	}
	cout << cnt << endl;
	return 0;
}
