fork download
  1. H, W = map(int,input().split())
  2. grid = [list(map(int,list(input()))) for i in range(H)]
  3. maxdis = 0
  4. for i in range(H):
  5. for j in range(W):
  6. n = grid[i][j]
  7. for _ in range(j+1, W):
  8. if n == grid[i][_]:
  9. dis = _ - j
  10. if dis + i < H:
  11. if grid[i+dis][j] == grid[i+dis][j+dis] and maxdis < dis:
  12. maxdis = dis
  13. print((maxdis+1)**2)
Success #stdin #stdout 0.01s 27648KB
stdin
2 2
11
22
stdout
4