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>
#define lambda(res, ...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__)->res
#define method(name, res, ...)                                                 \
  function<res(__VA_ARGS__)> name = lambda(res, __VA_ARGS__)
#define foreach(i,n) for(auto&i:(n))

using namespace std;

int main(){
  int table[10][10];
  foreach(i,table)
    foreach(j,i)
    cin >> j;

  method(f,int,int x,int y){
    return table[x][y];
  };
  method(g,int,vector<int> xs){
    int res = 0;
    foreach(i,xs){
      res = f(res,i);
    }
    return res;
  };
  method(digits,vector<int>,int x,int n){
    vector<int> res;
    for(int i=0;i<n;++i){
      res.emplace_back(x%10);
      x/=10;
    }
    reverse(res.begin(),res.end());
    return res;
  };

  method(func,bool,int x){
    int y = x * 10 + g(digits(x,4));
    vector<int> ys = digits(y,5);
    foreach(i,ys){
      for(int j=0;j<10;++j){
        if(i==j)continue;
        swap(i, j);
        if(g(ys)==0)return true;
        swap(i, j);
      }
    }
    for(int i=0;i<4;++i){
      if(ys[i]==ys[i+1])continue;
      swap(ys[i],ys[i+1]);
      if(g(ys)==0)return true;
      swap(ys[i],ys[i+1]);
    }
    return false;
  };

  int ans = 0;

  for(int i=0;i<10000;++i){
    ans += func(i);
  }

  cout << ans << endl;

  return 0;
}

