https://www.acmicpc.net/problem/1051
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int N, M;
string input;
int arr[51][51] = {0};
int result = 1;
cin >> N >> M;
for(int i=0; i<N; i++) {
cin >> input;
for(int j=0; j<M; j++) {
arr[i][j] = input[j] - '0';
}
}
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
for(int k=0; k<min(N,M); k++) {
if(i+k < N && j+k < M && arr[i][j] == arr[i+k][j] && arr[i][j] == arr[i][j+k] && arr[i][j] == arr[i+k][j+k])
result = max(result, k+1);
}
}
}
cout << result * result << endl;
return 0;
}