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(int i=0;i<(int)N;i++)
#define rep1(i,N) for(int i=1;i<=(int)N;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define show(x) cout<<#x<<" "<<x<<endl
using namespace std;
int x[10][10];
int calc(vector<int> vc){
	int a=0;
	for(int v:vc) a=x[a][v];
	return a;
}
int main(){
	int ans=0;
	rep(i,10) rep(j,10) cin>>x[i][j];
	rep(i,10000){
		vector<int> ds;
		int tmp=i;
		rep(j,4){
			ds.pb(tmp%10);
			tmp/=10;
		}
		reverse(all(ds));
		int e=calc(ds);
		ds.pb(e);
		bool ok=1;
		rep(j,5){
			rep(k,10) if(ds[j]!=k){
				vector<int> vc=ds;
				vc[j]=k;
				if(calc(vc)==0) ok=0;
			}
		}
		rep(j,4){
			if(ds[j]==ds[j+1]) continue;
			vector<int> vc=ds;
			swap(vc[j],vc[j+1]);
			if(calc(vc)==0) ok=0;
		}
		if(!ok) ans++;
	}
	cout<<ans<<endl;
}