cho.sh
Notes
Loading...

Matchsticks and Squares

Time limit

1s

Memory limit

128 MB

Problem

Matchsticks are placed along the lines of a grid on a table. A square is formed when every matchstick needed along its four sides is present. Matchsticks inside the square do not affect whether that square is counted.

Given each matchstick arrangement, count all squares that can be formed.

Input

The input consists of several arrangements.

The first line of each arrangement contains two integers rrr and ccc, the number of rows and columns. (1≤r,c≤20)(1 \le r,c \le 20)(1≤r,c≤20)

Then 2r+12r+12r+1 lines describing the matchstick arrangement follow. The 1st, 3rd, 5th, ... of these lines have length ccc; each character is either a hyphen (-) for a horizontal matchstick or an asterisk (*) for an empty space. The 2nd, 4th, 6th, ... of these lines have length c+1c+1c+1; each character is either a vertical bar (|) for a vertical matchstick or an asterisk (*) for an empty space.

The input ends with 0 0.

Output

For each arrangement, print one line containing the number of squares XXX in the format X squares.