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<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int a[10][10];

int f(string s){
    int ret = 0;
    rep(i,s.size()) ret = a[ret][s[i]-'0'];
    return ret;
}

int main(void) {
    int i,j;
    int n = 10000;
    rep(i,10)rep(j,10){
        string s;
        cin >> s;
        a[i][j] = s[0] - '0';
    }
    int ans = 0;
    rep(i,n){
        bool c = false;
        string s = to_string(i) + char(f(to_string(i))+'0');
        while(s.size()<5)s = "0" + s;
        string t = s;
        rep(j,5){
            rep(k,10)if(s[j]-'0' != k){
                t = s;
                t[j] = '0' + k;
                if(f(t)==0)c = true;
            }
        }
        rep(j,4){
            t = s;
            swap(t[j],t[j+1]);
            if(s != t && f(t) == 0)c = true;
        }

        if(c) ans++;
    }
    cout << ans << endl;
}

