Cyclically Shifted Maze

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Let's call a maze a rectangular field of cells, where cells can either be empty or contain a wall, and one can move from an empty cell to its empty neighbour cells in four directions.

Let's call a maze connected if it's possible to reach any its empty cell from any other empty cell by moving in four directions.

There was a connected maze of size n×mn \times m. It was cyclically shifted some rows down and some columns right, but nobody knows the exact shifts. Find all possible shifts.

입력

The first line contains two integers nn and mm (1n,m2001 \le n, m \le 200) --- the sizes of maze.

Each of the next nn lines contains mm characters "." or "#" --- empty cells and walls, correspondingly.

There is at least one empty cell in the maze.

출력

In the first line output a single integer kk (0knm0 \le k \le n \cdot m) --- the number of possible shifts.

In each of the next kk lines output two integers r_ir\_i and c_ic\_i (0r_i<n,0c_i<m0 \le r\_i < n, 0 \le c\_i < m) --- the number of rows the original maze was shifted down and the number of columns it was shifted right. Pairs (r_ir\_i, c_ic\_i) should be output in lexicographical order. Original maze must be connected for each of these cases.