Preparando MOJI

Frames

2000ms 262144K

Description:

One day Vasya got hold of a sheet of checkered paper n × m squares in size. Our Vasya adores geometrical figures, so he painted two rectangles on the paper. The rectangles' sides are parallel to the coordinates' axes, also the length of each side of each rectangle is no less than 3 squares and the sides are painted by the grid lines. The sides can also be part of the sheet of paper's edge. Then Vasya hatched all squares on the rectangles' frames.

Let's define a rectangle's frame as the set of squares inside the rectangle that share at least one side with its border.

A little later Vasya found a sheet of paper of exactly the same size and couldn't guess whether it is the same sheet of paper or a different one. So, he asked you to check whether the sheet of paper he had found contains two painted frames and nothing besides them.

Please note that the frames painted by Vasya can arbitrarily intersect, overlap or even completely coincide.

The coordinates on the sheet of paper are introduced in such a way that the X axis goes from top to bottom, the x coordinates of the squares' numbers take values from 1 to n and the Y axis goes from the left to the right and the y coordinates of the squares' numbers take values from 1 to m.

Input:

The first input line contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the sheet of paper Vasya found. Next n lines, each consisting of m symbols "." (dot) and "#" (number sign), describe the found sheet of paper. The symbol "#" represents a hatched square and the symbol "." represents a non-hatched square.

Output:

In the first line print the single word "YES" or "NO", meaning whether it is true that the found sheet of paper has two frames painted on it. If the answer is positive, then print in the second line 4 integers: the coordinates of the upper left and lower right corners of the first frame. In the third line print 4 integers: the coordinates of the upper left and the lower right corners of the second frame. If there are multiple answers, print any of them.

Sample Input:

4 5
#####
#.#.#
###.#
#####

Sample Output:

YES
1 1 3 3
1 1 4 5

Sample Input:

5 6
...###
...###
#####.
#...#.
#####.

Sample Output:

NO

Note:

In the first sample there are two frames on the picture. The first one is:

###..
#.#..
###..
.....

The second one is:

#####
#...#
#...#
#####

In the second sample the painted figures are not frames. Note that the height and width of valid frames is no less than 3.

Informação

Codeforces

Provedor Codeforces

Código CF152D

Tags

brute force

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 08:34:41

Relacionados

Nada ainda