Under construction

Still being built. Things may change

UFO Rectangles

Interview

Time limit2sMemory limit512 MB

Summary
Find every flattened rectangle frame drawn with X cells in a grid and print the top-left and bottom-right coordinates of each.
Level

Medium4 of 10

Topics
Matrix, Implementation
Solved
No attempts yet

Statement

Yandex has a secret department that handles special orders from the governments of different countries. Recently it received a message from a small banana republic that is suffering from an alien invasion.

Crop circles are strange circular formations that sometimes appear in potato or wheat fields, and they may or may not be left by UFOs. In the banana republic, the aliens leave rectangles of flattened banana plants instead.

The photo is divided into cells, and each cell is either intact or flattened. The aliens draw a rectangle by flattening all cells on the frame of an r×cr \times c rectangle, where rr and cc are both at least 33. The frames never share cells, and no two frames touch along two or more sides.

XXXXXXXXX       XXXXX....        XXXXXXXXXX
X.XXXXX.X       X...XXXX.        X..XXXXX.X
X.X...X.X       X...XX.X.        X..X...X.X
X.XXXXX.X       X...XX.X.        X..X...X.X
X.......X       X...XXXX.        X..XXXXX.X
XXXXXXXXX       XXXXX....        XXXXXXXXXX

   OK              OK              NOT OK

Find all the rectangles the aliens drew so the department can investigate.

Input

The first line contains two integers nn and mm (3≤n,m≤20003 \leq n, m \leq 2000), the dimensions of the photo. Then nn lines follow, each with mm characters. Each character is . for an intact cell or X for a flattened cell.

It is guaranteed that the picture corresponds to some set of rectangles that satisfy the conditions above.

Output

On the first line, print an integer kk (k≥0k \geq 0), the number of flattened rectangles in the photo. Then print kk lines, each with four integers r1r_1, c1c_1, r2r_2, and c2c_2 (1≤r1<r2≤n1 \leq r_1 < r_2 \leq n, 1≤c1<c2≤m1 \leq c_1 < c_2 \leq m). These are the row and column numbers of the top-left and bottom-right corners of a rectangle. Rows are numbered 1 to nn from top to bottom, and columns are numbered 1 to mm from left to right.

Rectangles may be printed in any order. If several answers are possible, print any one of them.

Examples3

  1. Example 1

    Input
    3 3
    XXX
    X.X
    XXX
    
    Expected output
    1
    1 1 3 3
    
  2. Example 2

    Input
    6 7
    XXXXXXX
    X.XX..X
    XXXXXXX
    XXXXXXX
    X.XX..X
    XXXXXXX
    
    Expected output
    4
    1 1 3 3
    1 4 3 7
    4 1 6 3
    4 4 6 7
    
  3. Example 3

    Input
    10 10
    ..........
    XXXXXXXXXX
    X..XXXX..X
    X..X..X..X
    X..XXXX..X
    X...XXXX.X
    X...X..X.X
    X...X..X.X
    X...XXXX.X
    XXXXXXXXXX
    
    Expected output
    3
    2 1 10 10
    3 4 5 7
    6 5 9 8