Problem: 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

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int table[10][10];
int check(int a,int b,int c,int d,int e)
{
  for(int i=0;i<10;i++)
    {
      if(table[table[table[table[table[0][i]][b]][c]][d]][e]==0 && i!=a) return -1;
    }
  for(int i=0;i<10;i++)
    {
      if(table[table[table[table[table[0][a]][i]][c]][d]][e]==0 && i!=b) return -1;
    }
  for(int i=0;i<10;i++)
    {
      if(table[table[table[table[table[0][a]][b]][i]][d]][e]==0 && i!=c) return -1;
    }
  for(int i=0;i<10;i++)
    {
      if(table[table[table[table[table[0][a]][b]][c]][i]][e]==0 && i!=d) return -1;
    }
  for(int i=0;i<10;i++)
    {
      if(table[table[table[table[table[0][a]][b]][c]][d]][i]==0 && i!=e) return -1;
    }
  if(table[table[table[table[table[0][b]][a]][c]][d]][e] == 0 && a!=b) return -1;
  if(table[table[table[table[table[0][a]][c]][b]][d]][e] == 0 && b!=c) return -1;
  if(table[table[table[table[table[0][a]][b]][d]][c]][e] == 0 && c!=d) return -1;
  if(table[table[table[table[table[0][a]][b]][c]][e]][d] == 0 && d!=e) return -1;

  return 1;
}
int main(int argc,char const* argv[])
{
  for(int i=0;i<10;i++)
    {
      for(int j=0;j<10;j++)
	{
	  cin >> table[i][j];
	}
    }
  int ans=0;
  for(int a=0;a<10;a++)
    {
      for(int b=0;b<10;b++)
	{
	  for(int c=0;c<10;c++)
	    {
	      for(int d=0;d<10;d++)
		{
		  int e=table[table[table[table[0][a]][b]][c]][d];
		  if(check(a,b,c,d,e)==-1) ans++;
		}
	    }
	}
    }
  cout << ans << endl;
}