December 4 - BMTK Programming School, High League
Each morning at 8:30 the schoolchildren of LKSH do their morning exercises in front of the main building. At the same time, boys and girls are standing on the ground, forming a rectangle.
The photographer stands on the porch of the building. He wants to make a group photo of some boys and girls. To do this, he needs to select a rectangular area on the ground so that the number of boys and girls inside will be equal. Unfortunately for pupils, there are many such areas. A photographer wants to take photos of all areas to choose the best. To make one photo takes one second. And all this time the boys and girls must continue their exercises!
Imagine that on the ground in front of the building a coordinate system is drawn. Then the students stand in the integer points, forming a rectangle of H × W points with sides parallel to the coordinate axes. The photographer needs to choose a sub-rectangle with sides parallel to the coordinate axes.
Write a program that calculates how many seconds the schoolchildren must do their morning exercises.
First line contains two positive integers H and W (1 ≤ W, H ≤ 300) - the dimensions of a rectangle formed by pupils. Each of the next H lines contains W numbers. Number 0 means a boy in this position, number 1 means girl.
Print the number of seconds while the morning exercises will continue.
3 4 0 1 0 0 1 0 1 1 0 0 0 1
3 1 0 0 0