Time Limit : sec, Memory Limit : KB
English / Japanese  

Land Division

Problem Statement

The country of JOI is a rectangle divided into a grid of H rows and W columns. The vertical direction of JOI is parallel to the north-south axis, and the horizontal direction is parallel to the east-west axis. The population of the cell in the i-th row from the north (1 ≦ i ≦ H) and the j-th column from the west (1 ≦ j ≦ W) is Ai,j people.

To improve administrative efficiency, JOI has decided to divide the entire country into two or more districts by drawing one or more boundary lines that satisfy the following conditions.

  • Boundary lines lie on the grid lines.
  • A boundary line is a line segment connecting the northern edge to the southern edge of JOI, or the eastern edge to the western edge of JOI.

Given the population of each cell in JOI, write a program that calculates the number of ways to divide the country such that the population of every district is equal.

Constraints

  • 1 ≦ H ≦ 50.
  • 1 ≦ W ≦ 50.
  • 1 ≦ Ai,j ≦ 100 000 (1 ≦ i ≦ H, 1 ≦ j ≦ W).
  • All input values are integers.

Input

The input is given from standard input in the following format.
H W
A1,1 A1,2 … A1,W
A2,1 A2,2 … A2,W
:
AH,1 AH,2 … AH,W

Output

Output the number of ways to divide the country such that the population of every district is equal, in one line to standard output.

Sample Input and Output

Sample Input 1

2 3
10 10 20
10 10 20

Sample Output 1

3

As shown in the figures below, there are 3 ways to divide the country such that the population of every district is equal, so output 3.

Sample Input 2

1 4
2 1 1 2

Sample Output 2

2

As shown in the figures below, there are 2 ways to divide the country such that the population of every district is equal, so output 2.

Sample Input 3

3 3
2 9 4
7 5 3
6 1 8

Sample Output 3

2

As shown in the figures below, there are 2 ways to divide the country such that the population of every district is equal, so output 2.

Sample Input 4

1 1
10000

Sample Output 4

0

There is no way to divide the country such that the population of every district is equal, so output 0.


Creative Commons License

Japan Information Olympiad Committee, "21st Japan Information Olympiad JOI 2021/2022 Second Preliminary Round Problem"