Jimin bought a map of islands and sea before leaving to search for treasure. The map is an N×M rectangle, and each cell contains either x or ..
A sea is a maximal group of . cells connected horizontally or vertically. An island is a maximal group of x cells connected horizontally, vertically, or diagonally.
An island that contains no other island has height 0. If the largest height among the islands contained in island A is K, then the height of island A is K+1.
Island A contains island B when A and B are different islands, and from any cell of island B it is impossible to move outside island A. Movement is allowed only horizontally or vertically, not diagonally.
The following map also shows island numbers for illustration.
There are 6 islands in this map. Five islands have height 0, namely 0 through 4, and one island has height 1, namely 5. Starting from island 3, it is impossible to leave island 5, so island 5 contains island 3. However, starting from island 4, it is possible to leave island 1, so island 1 does not contain island 4.
Given a map, output the number of islands of height 0, then height 1, and so on up to height H, where H is the greatest island height in the map.