Stars Drawing (Easy Edition)
Contest: Codeforces Round 501 (Div. 3)
Difficulty rating: 1700
Tags: brute force, dp, greedy

A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $$$0$$$ are not allowed).

Let's consider empty cells are denoted by '.', then the following figures are stars:

The leftmost figure is a star of size $$$1$$$, the middle figure is a star of size $$$2$$$ and the rightmost figure is a star of size $$$3$$$.

You are given a rectangular grid of size $$$n \times m$$$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $$$1$$$ to $$$n$$$, columns are numbered from $$$1$$$ to $$$m$$$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $$$n \cdot m$$$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.

In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $$$n \cdot m$$$ stars.

Input format:
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n, m \le 100$$$) — the sizes of the given grid.

The next $$$n$$$ lines contains $$$m$$$ characters each, the $$$i$$$-th line describes the $$$i$$$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

Output format:
If it is impossible to draw the given grid using stars only, print "-1".

Otherwise in the first line print one integer $$$k$$$ ($$$0 \le k \le n \cdot m$$$) — the number of stars needed to draw the given grid. The next $$$k$$$ lines should contain three integers each — $$$x_j$$$, $$$y_j$$$ and $$$s_j$$$, where $$$x_j$$$ is the row index of the central star character, $$$y_j$$$ is the column index of the central star character and $$$s_j$$$ is the size of the star. Each star should be completely inside the grid.

Constraints:
Time limit: 3.0 s
Memory limit: 256.0 MB

Note:
In the first example the output

is also correct.

Example input:
6 8
....*...
...**...
..*****.
...**...
....*...
........

Example output:
3
3 4 1
3 5 2
3 5 1

Example input:
5 5
.*...
****.
.****
..**.
.....

Example output:
3
2 2 1
3 3 1
3 4 1

Editorial:
Since we are almost unlimited in the number of stars in the answer, the following solution will works. We iterate over all possible stars centers and try to extend rays of the current star as large as possible. It can be done by the simple iterating and checking in $$$O(n)$$$. If the size of the current star is non-zero, let's add it to the answer. It is obvious that the number of stars in such answer will not exceed $$$n \cdot m$$$. Then let's try to draw all these stars on the empty grid. Drawing of each star is also can be done in $$$O(n)$$$. If after drawing our grid equals to the input grid, the answer is "YES" and our set of stars is the correct answer. Otherwise the answer is "NO".
Time complexity: $$$O(n^3)$$$.