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>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;
 
int x[11][11];

int check(int n){
    int tmp = x[0][n / 1000];
    n %= 1000;
    int tmp2 = x[tmp][n / 100];
    n %= 100;
    int tmp3 = x[tmp2][n / 10];
    n %= 10;
    int tmp4 = x[tmp3][n];
    return tmp4;
}

int change_to_i(string s){
    stringstream ss; int k;
    ss<<s; ss>>k;
    return k;
}

string change_to_s(int n){
    stringstream ss; ss<<n;
    return ss.str();
}

bool test(string s){
    int n = change_to_i(s);
    int res = x[check(n / 10)][n % 10];
    return res == 0; 
}

signed main(){
    rep(i, 0, 10) rep(j, 0, 10) cin >> x[i][j];
    int ans = 0;
    rep(i, 0, 10000){
        string s = change_to_s(i);
        int sz_s = s.size();
        rep(j, 0, 4 - sz_s) s = "0" + s;
        int check_digit = check(i);
        s = s + (char)('0' + check_digit);
        bool f = false;
        rep(j, 0, 5){
            rep(k, 0, 10){
                string t = s;
                t[j] = (char)('0' + k);
                if(s == t) continue;
                if(test(t)){
                    f = true;
                    j = 5;
                    break;
                }
            }
        }
        rep(j, 0, 4){
            string t = s;
            swap(t[j], t[j + 1]);
            if(t == s) continue;
            if(test(t)){
                f = true;
                break;
            }
        }
        if(f) ans++;
    }
    cout << ans << endl;
}