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;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



vector<vector<int> > x(10, vector<int>(10));
int f(int a, int b, int c, int d) {
    return x[x[x[x[0][a]][b]][c]][d];
}
int error(int a, int b, int c, int d, int e) {
    if (x[x[x[x[x[0][a]][b]][c]][d]][e] == 0) return 1;
    return 0;
}
int all_correct(vector<int> a) {
    // 1文字置き換え
    rep(i, 5) {
        vector<int> b = a;
        rep(j, 10) {
            if (a[i] == j) continue;
            b[i] = j;
            /*
            if (a[0] == 2 && a[1] == 0 && a[2] == 1 && a[3] == 6 && a[4] == 6) {
                cout << error(b[0], b[1], b[2], b[3], b[4]) << endl;
            }
             */
            if (error(b[0], b[1], b[2], b[3], b[4])) return 0;
        }
    }
    // 2文字swap // 隣接だけやった
    rep(i, 4) {
        int j = i + 1;
        vector<int> b = a;
        if (b[i] == b[j]) continue;
        swap(b[i], b[j]);
        /*
        if (a[0] == 2 && a[1] == 0 && a[2] == 1 && a[3] == 6 && a[4] == 6) {
            cout << i << " " << j << " " << error(b[0], b[1], b[2], b[3], b[4]) << endl;
        }
        */
        if (error(b[0], b[1], b[2], b[3], b[4])) return 0;
    }
    return 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    rep(i, 10) rep(j, 10) cin >> x[i][j];
    
    int ans = 0;
    rep(i, 10) rep(j, 10) rep(k, 10) rep(l, 10) {
        int e = f(i, j, k, l);
        vector<int> a(5);
        a[0] = i; a[1] = j; a[2] = k; a[3] = l; a[4] = e;
        // rep(_, 5) cout << a[_] << " "; cout << endl;
        if (all_correct(a) == 0) ans++;
        // cout << ans << endl;
    }
    cout << ans << endl;
}