Chess Masters
... As he approached the palace, he noticed that its gates were open. Upon entering, he saw a stone bench in the passageway. Seated on the bench were two girls, as radiant as the moon, engaged in a game of chess.
"One Thousand and One Nights", "The Tale of Hasan of Basra"
It is also said that in ancient times, during the reign of Harun al-Rashid, the ruler of the faithful, he became aware of a game called chess. He ordered craftsmen to carve a board and pieces, painters to color them in white and red, and varnishers to finish them with varnish.
The craftsmen completed their task and presented the board to the ruler. However, the squares on the board were not arranged in the traditional chess pattern. Harun al-Rashid demanded an explanation from the painter. The painter explained that on a chessboard, for any square section you choose (with sides parallel to the board's sides), the number of red and white cells should differ by no more than 1. On the board he created, not all squares necessarily had this property, but many did.
Intrigued by the painter's explanation (though it did not spare the painter from punishment), the ruler wanted to know how many different squares on the board had a difference between the number of red and white cells of no more than 1.
Input
The first line specifies the size of the board N (1 ≤ N ≤ 300). The next N lines each contain N numbers, indicating the color of each cell on the board (0 for white, 1 for red).
Output
Output a single line with the number of squares on the board that have the specified property.