During a discussion of problems at the Petrozavodsk Training
Camp, Vova and Sasha argued about who of them could in 300
minutes find a pair of equal squares of the maximal size
in a matrix of size N × M containing lowercase English letters. Squares could overlap each other but could not coincide. He who had found a pair of greater size won. Petr walked by, looked at the matrix, said that the optimal pair of squares had sides K, and walked on. Vova and Sasha still cannot find this pair. Can you help them?
Input
The first line contains integers N and M separated with a space. 1 ≤ N, M ≤ 500.
In the next N lines there is a matrix consisting of
lowercase English letters, M symbols per line.
Output
In the first line, output the integer K which Petr said. In the next two lines, give coordinates of upper left corners of maximal equal squares. If there exist more than one pair of equal squares of size K, than you may output any of them. The upper left cell of the matrix has coordinates (1, 1), and the lower right cell has coordinates (N, M). If there are no equal squares in the matrix, then output 0.
Sample
input | output |
---|
5 10
ljkfghdfas
isdfjksiye
pgljkijlgp
eyisdafdsi
lnpglkfkjl
| 3
1 1
3 3
|
Problem Author: Vladimir Yakovlev
Problem Source: The XIth USU Programing Championship, October 7, 2006