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:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int t[10][10];


int check(const string &s) {
	int x = 0;
	rep(i, 4)x = t[x][s[i] - '0'];
	return x;
}

bool check2(const string &s) {
	int x = 0;
	rep(i, 5)x = t[x][s[i] - '0'];
	return x == 0;
}


bool f(int a) {
	string s;
	s += a / 1000 % 10 + '0';
	s += a / 100 % 10 + '0';
	s += a / 10 % 10 + '0';
	s += a / 1 % 10 + '0';
	s += check(s) + '0';

	
	for(char &d : s) {
		char c = d;
		rep(i,10) {
			if (c == i + '0')continue;
			d = i + '0';
			if (check2(s)) {
				return false;
			}
		}
		d = c;
	}
	rep(i,4) {
		if (s[i] == s[i + 1])continue;
		swap(s[i], s[i + 1]);
		if (check2(s)) {
			return false;
		}
		swap(s[i], s[i + 1]);
	}
	return true;
}



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	rep(i, 10)rep(j, 10)cin >> t[i][j];

	int a = 0;
	rep(i, 10000) if (!f(i))a++;
	cout << a << endl;
	return 0;
}