In computer vision, objects of interest are often represented as regions of 1s in a binary image (bitmap). An important step in identifying such objects is tracing the contour (also called the border or boundary) of an object.
Assume the bitmap contains no 1s on its outer border. To trace the contour of a single object, use the Moore boundary tracking algorithm:
You are given a bitmap with at most 200 rows and 200 columns containing several objects. For each object, determine the length of its contour (the number of pixels in the traced contour) using the procedure above.
A pixel value of 0 is background and 1 is an object pixel. Two object pixels belong to the same object if they are joined by a path of object pixels moving in any of the 8 compass directions (8-connectivity). The border of the bitmap (first row, last row, first column, last column) is always background. Any object with fewer than 5 pixels is treated as noise and ignored. No object has holes; equivalently, every pair of background pixels is joined by a path of background pixels using only the 4 main compass directions (N, S, E, W).
The input contains several test cases. Each case begins with a line holding two positive integers $R$ and $C$: the number of rows and the number of columns of the bitmap. The next $R$ lines each contain a string of $C$ characters, each 0 or 1. The input ends with a case where $R = C = 0$; this last case is not processed.
For each case, print the case number on its own line, formatted as Case k. On the next line, print the contour lengths of all objects in the bitmap, sorted in ascending order and separated by single spaces. If the bitmap contains no object with at least 5 pixels, print no objects found on that line instead.