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<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int in[10][10];
int f(int a,int b){return in[a][b];};
int F(int a,int b,int c,int d,int e){
	vi t{a,b,c,d,e};
	rep(i,5)rep(j,10)if(t[i]!=j){
		int q=t[i];
		t[i]=j;
		if(!f(f(f(f(f(0,t[0]),t[1]),t[2]),t[3]),t[4]))return 1;
		t[i]=q;
	}
	rep(i,4)if(t[i]!=t[i+1]){
		swap(t[i],t[i+1]);
		if(!f(f(f(f(f(0,t[0]),t[1]),t[2]),t[3]),t[4]))return 1;
		swap(t[i],t[i+1]);
	}
	return 0;
}
int main(){
	rep(i,10)rep(j,10)cin>>in[i][j];
	int out=0;
	rep(i,10)rep(j,10)rep(k,10)rep(l,10){
		if(F(i,j,k,l,f(f(f(f(0,i),j),k),l)))out++;
	}
	cout<<out<<endl;
}