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;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    vvi x(10, vi(10));
    REP(i, 10) REP(j, 10) cin >> x[i][j];

    int ans = 0;
    REP(a, 10) REP(b, 10) REP(c, 10) REP(d, 10) {
        int e = x[x[x[x[0][a]][b]][c]][d];
        assert(x[x[x[x[x[0][a]][b]][c]][d]][e] == 0);
        bool canDetect = true;
        REP(i, 10) if (i != a) {
            if (x[x[x[x[x[0][i]][b]][c]][d]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != b) {
            if (x[x[x[x[x[0][a]][i]][c]][d]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != c) {
            if (x[x[x[x[x[0][a]][b]][i]][d]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != d) {
            if (x[x[x[x[x[0][a]][b]][c]][i]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != e) {
            if (x[x[x[x[x[0][a]][b]][c]][d]][i] == 0) canDetect = false;
        }
        if (b != a and x[x[x[x[x[0][b]][a]][c]][d]][e] == 0) canDetect = false;
        if (c != b and x[x[x[x[x[0][a]][c]][b]][d]][e] == 0) canDetect = false;
        if (d != c and x[x[x[x[x[0][a]][b]][d]][c]][e] == 0) canDetect = false;
        if (e != d and x[x[x[x[x[0][a]][b]][c]][e]][d] == 0) canDetect = false;
        if (!canDetect) ++ans;
    }
    cout << ans << endl;

    return 0;
}