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>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(long long)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int board[11][11];

int conv(int a, int b, int c, int d, int e) {
    int n1 = board[0][a];
    int n2 = board[n1][b];
    int n3 = board[n2][c];
    int n4 = board[n3][d];
    return board[n4][e];
}

bool check(int a, int b, int c, int d, int e) {
    rep(aa, 10) {
        if (a == aa) continue;
        if (conv(aa, b, c, d, e) == 0) return false;
    }
    rep(bb, 10) {
        if (b == bb) continue;
        if (conv(a, bb, c, d, e) == 0) return false;
    }
    rep(cc, 10) {
        if (c == cc) continue;
        if (conv(a, b, cc, d, e) == 0) return false;
    }
    rep(dd, 10) {
        if (d == dd) continue;
        if (conv(a, b, c, dd, e) == 0) return false;
    }
    rep(ee, 10) {
        if (e == ee) continue;
        if (conv(a, b, c, d, ee) == 0) return false;
    }

    if (a != b and conv(b, a, c, d, e) == 0) return false;
    if (b != c and conv(a, c, b, d, e) == 0) return false;
    if (c != d and conv(a, b, d, c, e) == 0) return false;
    if (d != e and conv(a, b, c, e, d) == 0) return false;

    return true;
}

int main() {
    rep(i, 10) rep(j, 10) cin >> board[i][j];
    int ans = 0;
    rep(a, 10) {
        int n1 = board[0][a];
        rep(b, 10) {
            int n2 = board[n1][b];
            rep(c, 10) {
                int n3 = board[n2][c];
                rep(d, 10) {
                    int e = board[n3][d];
                    if (!check(a, b, c, d, e)) ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

