#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
vector<vector<int>> mat(m, vector<int>(n));
// Nhập ma trận
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
cin >> mat[i][j];
}
}
vector<vector<int>> dp(m, vector<int>(n, 0));
int maxSide = 0;
// Tính toán dp
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (i == 0 || j == 0) {
// Nếu là hàng đầu tiên hoặc cột đầu tiên
dp[i][j] = 1;
} else if (mat[i][j] == mat[i-1][j] && mat[i][j] == mat[i][j-1] && mat[i][j] == mat[i-1][j-1]) {
// Nếu có thể mở rộng hình vuông
dp[i][j] = min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]}) + 1;
} else {
// Không thể mở rộng, hình vuông nhỏ nhất là 1
dp[i][j] = 1;
}
// Cập nhật kích thước cạnh lớn nhất
maxSide = max(maxSide, dp[i][j]);
}
}
// Kết quả là diện tích hình vuông lớn nhất
cout << maxSide * maxSide << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IG0sIG47CiAgICBjaW4gPj4gbSA+PiBuOwoKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gbWF0KG0sIHZlY3RvcjxpbnQ+KG4pKTsKCiAgICAvLyBOaOG6rXAgbWEgdHLhuq1uCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG07ICsraSkgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbjsgKytqKSB7CiAgICAgICAgICAgIGNpbiA+PiBtYXRbaV1bal07CiAgICAgICAgfQogICAgfQoKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gZHAobSwgdmVjdG9yPGludD4obiwgMCkpOwogICAgaW50IG1heFNpZGUgPSAwOwo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W5kbDsKCiAgICByZXR1cm4gMDsKfQ==