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 <iostream>
#include <vector>
#include <algorithm>
#include <array>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int check(array<array<int, 10>, 10> &x, int a, int b, int c, int d) {
    return x[x[x[x[0][a]][b]][c]][d];
}

int check(array<array<int, 10>, 10> &x, int a, int b, int c, int d, int e) {
    return x[check(x, a, b, c, d)][e];
}

int main () {
    array<array<int, 10>, 10> x;
    REP (i, 0, x.size()) REP (j, 0, x[i].size()) cin >> x[i][j];
    int cnt = 0;
    REP (a, 0, 10) REP (b, 0, 10) REP (c, 0, 10) REP (d, 0, 10) {
        int digit = check(x, a, b, c, d);
        bool t = false;
        REP (e, 0, 10) {
            if (a != e) t |= (check(x, e, b, c, d, digit) == 0);
            if (b != e) t |= (check(x, a, e, c, d, digit) == 0);
            if (c != e) t |= (check(x, a, b, e, d, digit) == 0);
            if (d != e) t |= (check(x, a, b, c, e, digit) == 0);
            if (digit != e) t |= (check(x, a, b, c, d, e) == 0);
        }

        if (a != b) t |= (check(x, b, a, c, d, digit) == 0);
        if (b != c) t |= (check(x, a, c, b, d, digit) == 0);
        if (c != d) t |= (check(x, a, b, d, c, digit) == 0);
        if (d != digit) t |= (check(x, a, b, c, digit, d) == 0);
        cnt += t;
    }
    cout << cnt << endl;
    return 0;
}