#include #define rep(i,n,m) for(int i = (n); i <(m); i++) #define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--) using namespace std; using ll = long long; const int INF = 1000000000; int main() { int h, w, k; cin >> h >> w >> k; string table[h]; rep(i, 0, h) cin >> table[i]; int dis[26][h+1][w+1]; rep(c,0, 26) rep(i, 0, h + 1) rep(j, 0, w + 1) dis[c][i][j] = INF; rep(c, 0, 26) { char color = c + 'a'; rrep(i, h, 0) rrep(j, w, 0) { if (table[i][j] == color) dis[c][i][j] = 1; else { int max_k = min(h-i, w-j); if (dis[c][i+1][j] + 1 <= max_k) dis[c][i][j] = min(dis[c][i][j], dis[c][i+1][j] + 1); if (dis[c][i][j+1] + 1 <= max_k) dis[c][i][j] = min(dis[c][i][j], dis[c][i][j+1] + 1); if (dis[c][i+1][j+1] + 1 <= max_k) dis[c][i][j] = min(dis[c][i][j], dis[c][i+1][j+1] + 1); } // if (color == 'd') // cout << i << ' ' << j << ' ' << dis[c][i][j] << endl; } } ll ans = 0; rep(i, 0, h) rep(j, 0, w) { vector nums; int max_k = min(h-i, w-j) + 1; nums.push_back(max_k); rep(c, 0, 26) { if (dis[c][i][j] == INF) nums.push_back(max_k); else nums.push_back(dis[c][i][j]); } sort(nums.begin(), nums.end()); // rep(c, 0, 26) // cout << nums[c] << " "; // cout << endl; // cout << "**********" << endl; // cout <