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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

void bfs(vector<string> &datas, string s) {
    if (s.size() == 4) {
        datas.push_back(s);
        return;
    }
    for (int i = 0; i < 10; i++) {
        string t = s;
        t += (char) (i + '0');
        bfs(datas, t);
    }
}

bool check(vector<vector<int>> &x, string t) {
    int d = t[0] - '0';
    d = x[0][d];
    for (int i = 1; i < t.size(); i++) {
        d = x[d][t[i] - '0'];
    }
    return d == 0;
}

string getGoodString(vector<vector<int>> &x, string s) {
    int d = s[0] - '0';
    d = x[0][d];
    for (int i = 1; i < s.size(); i++) {
        d = x[d][s[i] - '0'];
    }
    s += (char) (d + '0');
    return s;
}

int main() {

    vector<vector<int>> x(10, vector<int>(10));
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> x[i][j];

    vector<string> datas;
    bfs(datas, "");

    int ans = 0;
    for (int i = 0; i < datas.size(); i++) {
        string s = datas[i];
        s = getGoodString(x, s);
        bool bad = false;
        for (int j = 0; j < 5; j++) {
            for (char k = '0'; k <= '9'; k++) {
                string t = s;
                t[j] = k;
                if (s[j] == k) continue;
                bool result = check(x, t);
                if (result)bad = true;
            }
        }
//
        for (int i = 0; i < 4; i++) {
            string t = s;
            swap(t[i], t[i + 1]);
            if (s == t) continue;
            bool result = check(x, t);
            if (result) bad = true;

        }

        if (bad) ans++;
    }

    cout << ans << endl;

}












































