Squares |

A children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count the number of squares of certain sizes that are formed by these lines. For example, in the figure shown below, there are 3 squares-2 of size 1 and 1 of size 2. (The ``size" of a square is the number of lines segments required to form a side.)

Your problem is to write a program that automates the process of counting all the possible squares.

The input file represents a series of game boards. Each board consists of
a description of a square array of *n ^{2}* dots
(where

Line 1:nthe number of dots in a single row or column of the arrayLine 2:

mthe number of interconnecting linesEach of the next m lines are of one of two types:

H i jindicates a horizontal line in rowiwhich connectsthe dot in column

jto the one to its right in columnj+ 1or

V i jindicates a vertical line in columniwhich connects

the dot in rowjto the one below in rowj+ 1

Information for each line begins in column 1. The end of input is indicated by end-of-file. The first record of the sample input below represents the board of the square above.

For each record, label the corresponding output with ```Problem #1`",
```Problem #2`", and so forth. Output for a record
consists of the number of squares of each size on the board, from the
smallest to the largest. lf no squares of any size
exist, your program should print an appropriate message indicating so.
Separate output for successive input records
by a line of asterisks between two blank lines, like in the sample below.

4 16 H 1 1 H 1 3 H 2 1 H 2 2 H 2 3 H 3 2 H 4 2 H 4 3 V 1 1 V 2 1 V 2 2 V 2 3 V 3 2 V 4 1 V 4 2 V 4 3 2 3 H 1 1 H 2 1 V 2 1

Problem #1 2 square (s) of size 1 1 square (s) of size 2 ********************************** Problem #2 No completed squares can be found.