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 <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair<int,int>
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,b,a) for (int i=(b);i>=(a);--i)
typedef long long LL;
inline int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const int MAXN=500005,Mo=1000000007;
const double eps=1e-8,INF=1e20,PI=3.141592653589793238462;
int n,a[10][10],b[MAXN];
struct list{
	int l,lt[MAXN],nt[MAXN],x[MAXN];
	void clear(){ l=0; memset(lt,0,sizeof(lt)); }
	void addedge(int a,int b){ l++; nt[l]=lt[a]; lt[a]=l; x[l]=b; }
}E;
int check(int x,int y,int z,int w,int m) {
	return a[a[a[a[a[0][x]][y]][z]][w]][m];
}
int main(){
	FOR(i,0,9)
		FOR(j,0,9) a[i][j]=read();
	int flag,ans=0;
	FOR(i,0,9999) {
		flag=0;
		int x=i/1000,y=i/100%10,z=i/10%10,w=i%10;
		//cout<<x<<' '<<y<<' '<<z<<' '<<w<<endl;
		int m=a[a[a[a[0][x]][y]][z]][w];
		if (check(x,y,z,w,m)!=0) cout<<"lxsb"<<endl;
		if (x!=y&&check(y,x,z,w,m)==0) flag=1;
		if (y!=z&&check(x,z,y,w,m)==0) flag=1;
		if (w!=z&&check(x,y,w,z,m)==0) flag=1;
		if (m!=w&&check(x,y,z,m,w)==0) flag=1;
		FOR(j,0,9) {
			if (j!=x&&check(j,y,z,w,m)==0) { flag=1; break; }
			if (j!=y&&check(x,j,z,w,m)==0) { flag=1; break; }
			if (j!=z&&check(x,y,j,w,m)==0) { flag=1; break; }
			if (j!=w&&check(x,y,z,j,m)==0) { flag=1; break; }
			if (j!=m&&check(x,y,z,w,j)==0) { flag=1; break; }
		}
		if (flag) ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

/*
0 1 2 3 4 5 6 7 8 9
9 0 1 2 3 4 5 6 7 8
8 9 0 1 2 3 4 5 6 7
7 8 9 0 1 2 3 4 5 6
6 7 8 9 0 1 2 3 4 5
5 6 7 8 9 0 1 2 3 4
4 5 6 7 8 9 0 1 2 3
3 4 5 6 7 8 9 0 1 2
2 3 4 5 6 7 8 9 0 1
1 2 3 4 5 6 7 8 9 0

*/