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 <utility> // pair make_pair
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

#define SIZE 10
Vec<Vec<int>> table(10, Vec<int>(10));
bool detection (int a, int b, int c, int d, int e); 

int main(void) {
    FOR(i, 0, 10) {
        FOR(j, 0, 10) {
            cin >> table[i][j];
        }
    }
    int count = 0;
    FOR(a, 0, 10) {
        FOR(b, 0, 10) {
            FOR(c, 0, 10) {
                FOR(d, 0, 10) {
                    int e = table[table[table[table[0][a]][b]][c]][d];
                    if (detection(a, b, c, d, e) == false) {
                        count++;
                    }
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

bool detection (int a, int b, int c, int d, int e) {
    bool detect = true;
    int temp_e;
    FOR(temp, 0, 10) {
        if (temp != a) {
            temp_e = table[table[table[table[0][temp]][b]][c]][d];
            if (table[temp_e][e] == 0) {
                detect = false;
            }
        }
        if (temp != b) {
            temp_e = table[table[table[table[0][a]][temp]][c]][d];
            if (table[temp_e][e] == 0) {
                detect = false;
            }
        }
        if (temp != c) {
            temp_e = table[table[table[table[0][a]][b]][temp]][d];
            if (table[temp_e][e] == 0) {
                detect = false;
            }
        }
        if (temp != d) {
            temp_e = table[table[table[table[0][a]][b]][c]][temp];
            if (table[temp_e][e] == 0) {
                detect = false;
            }
       }
        if (temp != e) {
            temp_e = table[table[table[table[0][a]][b]][c]][d];
            if (table[temp_e][temp] == 0) {
                detect = false;
            }
        }
    }

    temp_e = table[table[table[table[0][b]][a]][c]][d];
    if (a != b && table[temp_e][e] == 0) {
        detect = false;
    }
    temp_e = table[table[table[table[0][a]][c]][b]][d];
    if (b != c && table[temp_e][e] == 0) {
        detect = false;
    }
    temp_e = table[table[table[table[0][a]][b]][d]][c];
    if (c != d && table[temp_e][e] == 0) {
        detect = false;
    }
    int temp_d = table[table[table[table[0][a]][b]][c]][e];
    if (d != e && table[temp_d][d] == 0) {
        detect = false;
    }
    return detect;
}