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 lambda(res,...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define method(name,res,...) function<res(__VA_ARGS__)> name = (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define foreach(i,n) for(auto &i:(n))

using namespace std;

vector<int> fact(int x){
	vector<int> res;
	for(int i=0;i<4;++i){
		int num = x % 10;
		res.emplace_back(num);
		x/=10;
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
	vector<vector<int>> table(10,vector<int>(10));
	foreach(i,table){
		foreach(j,i){
			cin >> j;
		}
	}

	method(apply,int,vector<int> line){
		int res = 0;
		foreach(i,line){
			res = table[res][i];
		}
		return res;
	};
	method(func,bool,int x){
		vector<int> line = fact(x);
		int collect = apply(line);
		line.emplace_back(collect);
		//change one digits 
		foreach(i,line){
			for(int j=0;j<10;++j){
				if(i==j)continue;
				swap(i,j);
				int current = apply(line);
				if(current==0)return true;
				swap(i,j);
			}
		}

		//swap two digits
		for(int i=0;i+1<line.size();++i){
			if(line[i]==line[i+1])continue;
			swap(line[i],line[i+1]);
			int current = apply(line);
			if(current==0)return true;
			swap(line[i],line[i+1]);
		};
		return false;
	};

	int ans = 0;
	for(int i=0;i<10000;++i){
		ans +=  func(i);
	}

	cout << ans << endl;
	return 0;
}


