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;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

int table[10][10];

int f(int a, int b){
    return table[a][b];
}

int check(string s){
    int res = 0;
    for(int i=0;i<int(s.size());i++){
        int d = s[i]-'0';
        res = f(res, d);
    }
    return res;
}

int main(){
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >> table[i][j];
        }
    }
    int ans = 0;
    for(int i=0;i<10000;i++){
        string s = to_string(i);
        while(s.size()<4) s.insert(s.begin(),'0');
        s.push_back('0'+check(s));
        bool ok = true;
        for(int i=0;i<5;i++){
            for(int d=0;d<=9;d++){
                if(s[i] == '0'+d) continue;
                string t = s;
                t[i] = '0'+d;
                ok &= check(t) != 0;
            }
        }
        for(int i=0;i<4;i++){
            string t = s;
            swap(t[i],t[i+1]);
            if(s == t) continue;
            ok &= check(t) != 0;
        }
        if(!ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

