Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)

array<array<int,10>,10> r;

bool get(){
	rep(i,10)rep(j,10) if(!(cin>>r[i][j])) return false;
	return true;	
}

int calc(vi v){
	int ret=0;
	rep(i,4) ret=r[ret][v[i]];
	return ret;
}

bool isValid(int n){
	vi v={n/1000%10, n/100%10, n/10%10, n%10, -1};
	v[4]=calc(v);
	vi l;
	rep(i,5)rep(j,10){
		if(v[i]!=j) {
			auto tmp=v; tmp[i]=j;
			if(r[calc(tmp)][tmp[4]]==0) return false; 
		}
	}
	rep(i,4){
		if(v[i]!=v[i+1]){
			auto tmp=v; swap(tmp[i],tmp[i+1]);
			if(r[calc(tmp)][tmp[4]]==0) return false; 			
		}
	}
	return true;
}

int solve(){
	int ans=0;
	rep(i,10000) if(!isValid(i)) ans++;
	return ans;	
}

int main(){
	while(get()){
		cout<<solve()<<endl;
	}
	return 0;
}