You are given an N×N array A and a permutation P of the integers from 0 to N−1.
Sum(A,P)=A[0][P[0]]+A[1][P[1]]+⋯+A[N−1][P[N−1]]
An array is nice if Sum(A,P) is the same no matter which permutation P you pick.
Some cells of A have been erased. Write a program that counts the ways to fill in every erased cell so that the array is nice. Two ways are different if the finished arrays differ in at least one cell.