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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	vector<vector<int>> num(10, vector<int>(10));
	REP(i, 10) {
		REP(j, 10) {
			cin >> num[i][j];
		}
	}
	int cnt = 0;
	REP(i, 10000) {
		int e = num[num[num[num[0][(i / 1000) % 10]][(i / 100) % 10]][(i / 10) % 10]][i % 10];
		const int newnum = i * 10 + e;
		bool check = true;
		int di = 1;
		REP(j, 5) {
			REP(k, 10) {
				if (((newnum / di) % 10) == k)
					continue;
				int copy = newnum - ((newnum / di) % 10)*di + k*di;
				if (num[num[num[num[num[0][(copy / 10000) % 10]][(copy / 1000) % 10]][(copy / 100) % 10]][(copy / 10) % 10]][copy % 10] == 0)
					check = false;
			}
			di *= 10;
		}
		di = 1;
		REP(j, 4) {
			if (((newnum / di) % 10) == ((newnum / di / 10) % 10)) {
				di *= 10;
				continue;
			}
			int copy = newnum - ((newnum / di) % 10)*di + ((newnum / di / 10) % 10)*di - ((newnum / di / 10) % 10)*di * 10 + ((newnum / di) % 10)*di * 10;
			if (num[num[num[num[num[0][(copy / 10000) % 10]][(copy / 1000) % 10]][(copy / 100) % 10]][(copy / 10) % 10]][copy % 10] == 0)
				check = false;
			di *= 10;
		}
		if (!check) {
			cnt++;
		}
	}
	cout << cnt << endl;
}