#JUMPPY. Jumppy and the Grid
Jumppy and the Grid
Jumppy likes to jump! One day Jumppy went to a park. Jumppy can jump all over the park. The park can be thought of as a square grid with square cells of side length 1. The contents of the grid is either 0 (zero) or X. There are certain things which Jumppy likes. They are:
- Jumppy likes rectangles.
- Jumppy likes X.
Therefore Jumppy will jump only in the rectangles consisting of X. A rectangle is defined as follows:
- The whole rectangular region should contain only X.
- The rectangle should be surrounded with 0 or the boundary of the grid.
- The diagonally adjacent cell (see the definition) of the corner of the rectangle may be X or 0. (Refer to the first example).
Diagonally adjacent cell: Suppose the given cell has coordinates (p, q) then its diagonally adjacent cells would have coordinates (p+1, q+1), (p+1, q-1), (p-1, q+1), (p-1, q-1).
Now Jumppy is curious how many rectangles are there in the park. Help Jumppy find the number of rectangle.
Input
An integer n denoting the size of the grid. Then n lines follow each containing a string of n characters describing the square grid. All the characters will be either 0 or X.
Output
Output the number of rectangles in the given grid.
Constraints
0 < n <= 1000
Examples:
Input: 4 XX00 XX00 00XX 00XX</p>Output: 2
Input: 5 00000 0XXX0 0XXX0 0XXX0 00X00 Output: 0
Input: 5 00000 0XXX0 0X0X0 0XXX0 00000 Output: 0
Input: 3 X0X 0X0 X0X Output: 5
Explanation
Case 1: As can be seen there are two rectangles as highlighted.
Case 2: The grid contains no rectangles because it violates the second condition of the definition.
Case 3: The grid contains no rectangles because it violates the first condition of the definition.
Case 4: The individual X in this case can be considered as rectangles.