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>

using Int = int;
using namespace std;


struct digit{
	static Int x[10][10];
	Int val;
	digit(Int val) : val(val) {}
	digit operator*(const digit &a){
		return digit(x[val][a.val]);
	}
	operator int(){
		return val;
	}
} zero(0);

#define REP(i, n) for(digit i(0); i.val < (n); ++i.val)

Int digit::x[10][10];

Int out[10][10][10][10];

int main(){
	for(Int i = 0; i < 10; ++i) for(Int j = 0; j < 10; ++j) cin >> digit::x[i][j];

	// REP(i, 10) REP(j, 10) cout << i*j;
	
	Int count = 0;

	REP(a, 10) REP(b, 10) REP(c, 10) REP(d, 10){
		digit e = zero * a * b * c * d;
		REP(i, 10) if(a != i && zero * i * b * c * d * e == 0) goto DAME;
		REP(i, 10) if(b != i && zero * a * i * c * d * e == 0) goto DAME;
		REP(i, 10) if(c != i && zero * a * b * i * d * e == 0) goto DAME;
		REP(i, 10) if(d != i && zero * a * b * c * i * e == 0) goto DAME;
		REP(i, 10) if(e != i && zero * a * b * c * d * i == 0) goto DAME;
		if(a != b && zero * b * a * c * d * e == 0) goto DAME;
		if(b != c && zero * a * c * b * d * e == 0) goto DAME;
		if(c != d && zero * a * b * d * c * e == 0) goto DAME;
		if(d != e && zero * a * b * c * e * d == 0) goto DAME;
		goto YOSHI;
DAME:
		++count;
YOSHI:;
	}
	cout << count << endl;

}