AT_past19_g 結合律
Description
You are given an $ N $ -by- $ N $ matrix $ A $ . The element in the $ i $ -th row and $ j $ -th column of $ A $ is denoted by $ A(i,j) $ . Exactly one element of $ A $ is $ 0 $ , and each of the other $ (N^2-1) $ elements is an integer between $ 1 $ and $ N $ .
How many ways are there to replace the only element $ 0 $ in $ A $ with an integer between $ 1 $ and $ N $ , inclusive, such that the resulting $ A $ satisfies the following condition?
- $ A(A(i,j),k)=A(i,A(j,k)) $ for all $ 1\leq i,j,k\leq N $ .
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ A(1,1) $ $ A(1,2) $ $ \dots $ $ A(1,N) $ $ A(2,1) $ $ A(2,2) $ $ \dots $ $ A(2,N) $ $ \vdots $ $ A(N,1) $ $ A(N,2) $ $ \dots $ $ A(N,N) $
Output Format
Print the answer as an integer.
Explanation/Hint
### Sample Explanation 1
Since $ A(2,2) $ is $ 0 $ , we consider replacing it with each integer between $ 1 $ and $ 3 $ .
- If $ A(2,2) $ becomes $ 1 $ : it does not satisfy the condition. For $ (i,j,k)=(2,2,3) $ , we have $ A(A(i,j),k)=3 $ but $ A(i,A(j,k))=2 $ .
- If $ A(2,2) $ becomes $ 2 $ : it does not satisfy the condition. For $ (i,j,k)=(3,3,2) $ , we have $ A(A(i,j),k)=2 $ but $ A(i,A(j,k))=3 $ .
- If $ A(2,2) $ becomes $ 3 $ : it satisfies the condition. $ A(A(i,j),k)=A(i,A(j,k)) $ for all $ 1\leq i,j,k\leq N $ .
Thus, the answer is $ 1 $ .
### Constraints
- $ 1\leq N \leq 300 $
- $ 0\leq A(i,j)\leq N $
- There is exactly one occurrence of $ 0 $ in $ A(i,j)\ (1\leq i,j\leq N) $ .
- All input values are integers.