eolymp
bolt
Try our new interface for solving problems
Problems

Image compression

Image compression

Agent Johnny English entered the enemy's lair and found a secret image in it, which must be urgently transferred to the command center. Before doing this, however, it must be compressed to keep the transmission time to a minimum.

The image is a rectangle n * m, divided into n * m unit cells - pixels. Each pixel can be either black or white.

Let's describe the image compression process. Johnny can split the entire image into rectangles of the same size (all rectangles must have the same height and width). If, as a result of this splitting, it turns out that all pixels in each rectangle have the same color, Johnny can replace each resulting rectangle with one pixel of the corresponding color. For a better understanding of the image compression process, study the tests from the example.

Help Johnny find the image compression that contains the minimum number of pixels.

Input

The first line contains two integers n and m (1n, m3000) - the height and the width of the original image, respectively. Then n lines follow, each consists of m characters describing the colors of the pixels in the original image. The "." symbol represents a white pixel, and the "X" symbol represents a black pixel.

Output

Print a description of the image compression. Follow the same format as in the input.

Time limit 2 seconds
Memory limit 128 MiB
Input example #1
9 12
........XXXX
........XXXX
........XXXX
XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXX
XXXX....XXXX
XXXX....XXXX
XXXX....XXXX
Output example #1
3 3
..X
XXX
X.X
Input example #2
2 3
X.X
.X.
Output example #2
2 3
X.X
.X.
Input example #3
2 3
..X
..X
Output example #3
1 3
..X
Source 2018 Цикл Интернет-олимпиад для школьников, первая командная олимпиада сезона, October 14, Problem B