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 <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
using namespace std;
using llong = long long;

llong table[16][16];

llong op(llong a, llong b) {
        return table[a][b];
}
llong check(string &ssn) {
        return op(op(op(op(op(0, ssn[0]-'0'), ssn[1]-'0'), ssn[2]-'0'), ssn[3]-'0'), ssn[4]-'0');
}
llong check_digits(string &basicID) {
        return op(op(op(op(0, basicID[0]-'0'), basicID[1]-'0'), basicID[2]-'0'), basicID[3]-'0');
}

string to_str(llong a) {
        string s;
        for (int i = 0; i < 4; i++) {
                s += (char)((a % 10) + '0');
                a /= 10;
        }

        reverse(s.begin(), s.end());
        return s;
}

bool typo_error(string &ssn) {
        for (int i = 0; i < 5; i++) {
                char b = ssn[i];
                for (char ch = '0'; ch <= '9'; ch++) {
                        if (ch == b) continue;
                        ssn[i] = ch;
                        if (check(ssn) == 0) return true;
                }
                ssn[i] = b;
        }
        return false;
}

bool trans_error(string &ssn) {
        string s = ssn;
        for (int i = 0; i < 4; i++) {
                swap(s[i], s[i + 1]);
                if (s == ssn) continue;
                else if (check(s) == 0) return true;
                swap(s[i], s[i + 1]);
        }
        return false;
}

int main() {
        for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                        cin >> table[i][j];
                }
        }

        llong ans = 0;
        for (int i = 0; i < 10000; i++) {
                string basicID = to_str(i);
                string ssn = basicID;
                ssn += (char)(check_digits(basicID) + '0');

                if (typo_error(ssn)) {
                        ans++;
                }
                else if (trans_error(ssn)) {
                        ans++;
                }
        }

        cout << ans << endl;
}

