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 int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 2e9;
const int mod = 1e9 + 7;

int a[10][10];

int f(const vi& v) {
    int t = 0;
    rep(i, v.size()) {
        t = a[t][v[i]];
    }
    return t;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    rep(i, 10) rep(j, 10) cin >> a[i][j];

    int ans = 0;
    rep(i, 10000) {
        vi b(4);
        int p = i;
        rep(j, 4) {
            b[j] = p % 10;
            p /= 10;
        }
        reverse(all(b));
        b.emplace_back(f(b));

        ans += [&](){
            rep(j, 5) {
                rep(k, 10) {
                    if (b[j] == k) continue;
                    vi c = b;
                    c[j] = k;
                    if (!f(c)) return 1;
                }
            }

            rep(j, 4) {
                if (b[j] == b[j + 1]) continue;
                vi c = b;
                swap(c[j], c[j + 1]);
                if (!f(c)) return 1;
            }
            return 0;
        }();
    }

    cout << ans << endl;
}