Time limit
2s
Memory limit
128 MB
You are given an N×M rectangular grid. Each cell contains one digit. Find the largest square whose four corner cells all contain the same digit. The sides of the square must be parallel to the rows and columns of the grid.
The first line contains two natural numbers N and M. Each of N and M is at most 50. The next N lines each contain a string of length M, and every character is a digit.
Print the area of the largest square that satisfies the condition.