Nice Array

Count ways to fill the erased cells of an N by N array so that every permutation's diagonal sum is equal, modulo 1e9+7.

Hard8CombinatoricsMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given an N×NN \times N array AA and a permutation PP of the integers from 00 to N1N-1.

Sum(A,P)=A[0][P[0]]+A[1][P[1]]++A[N1][P[N1]]\mathrm{Sum}(A, P) = A[0][P[0]] + A[1][P[1]] + \cdots + A[N-1][P[N-1]]

An array is nice if Sum(A,P)\mathrm{Sum}(A, P) is the same no matter which permutation PP you pick.

Some cells of AA 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.

Input

The first line has the size NN (1N501 \le N \le 50) of the array AA.

Each of the next NN lines has one row of AA as NN characters with no spaces. An erased cell is -, and every other cell is an integer between 00 and 99.

Output

Print the number of ways to make the array nice, modulo 1,000,000,007, on the first line.

A number you fill in is an integer that is at least 00, and it may be larger than 99. No input has an infinite number of ways.