Here’s a Product Which Will Make You Tensor

Time Limit: 4000 ms Memory Limit: 65536 KiB

Problem Description


Input

The first line of input for a test case will contain two positive integers r and c indicating the number of rows and columns in the matrix. After this will follow r lines each containing c positive integers. The values of r and c will be ≤ 500, each entry in the matrix will be no greater than 65,536, and the last test case is followed by a line containing 0 0.

Output

For each test case, output the number of different ways the matrix could be the tensor product of two positive integer matrices, neither of which is a 1 × 1 matrix.

Sample Input

6 6
1 1 1 2 2 2
1 1 1 2 2 2
1 1 2 2 2 4
3 3 3 4 4 4
3 3 3 4 4 4
3 3 6 4 4 8
2 2
3 6
4 9
2 4
15 18 30 36
20 24 40 48
0 0

Sample Output

1
0
4

Hint

 

Source

The 2009 ACM-ICPC East Central North America