Counting Codes

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

Graphic by Henry Wang.

You're one of the king's spies sent on a secret mission to retrieve an item of incredible value, an ancient scroll from the throne room. Legend has it, the scroll contains the answer to the PP versus NPNP problem. When you finally reach the throne room, you realize there is a code the guards enter every day while observing them. As a spy, you've started to notice a few rules for each guard's code:

  1. each code is a matrix consisting of nonzero decimal digits (integers from 11 to 99)  with mm rows and nn columns

  2. no digit repeats within any row of the code

  3. for each digit ll in the code,  except for those in the topmost row and rightmost column,  let uu be the digit above it and let rr be the digit to its right in the code matrix.  Then one of the following must be true:

    • uu is the product of ll and rr
    • uu is the sum of ll and rr
    • uu is the difference of ll and rr or rr and ll
    • uu is the quotient of ll and rr or rr and ll

On day 999999, you've noticed a guard has seem to walked off while entering his code. Some digits have been omitted, but after careful consideration you think you can crack the code. Digits that have been omitted are represented with a 00. How many complete codes are possible, given the guard's partial code?

입력

A test case starts with a line containing two numbers mm (3m63 \le m \le 6) and nn (3n63 \le n \le 6), which is the number of rows and number of columns of the grid.  The following mm lines contain nn integers from 00 to 99, separated by spaces. 00 indicates an unknown value that you can supply, and there will be at most m\*n2\lfloor \frac{m\*n}{2} \rfloor unknown values.

You can assume the guard has followed the rules with the partial code (i.e. no repeated digits appear in any row in the input, and any three pairs of non-zero digits that form an L have the property described above).

출력

For each test case, print the number of complete codes you can find.