Under construction

Still being built. Things may change

Nice Array

Time limit2sMemory limit512 MB

Summary
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.
Level

Hard8 of 10

Topics
Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

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

Sum(A,P)=A[0][P[0]]+A[1][P[1]]+⋯+A[N−1][P[N−1]]\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 (1≤N≤501 \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.

Examples6

  1. Example 1

    Input
    2
    1-
    -2
    
    Expected output
    4
    
  2. Example 2

    Input
    3
    123
    4--
    --9
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    9--
    -9-
    --9
    
    Expected output
    271
    
  4. Example 4

    Input
    2
    11
    12
    
    Expected output
    0
    
  5. Example 5

    Input
    4
    -4--
    -0-2
    --1-
    4---
    
    Expected output
    10
    
  6. Example 6

    Input
    3
    --2
    02-
    -10
    
    Expected output
    0