#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; //const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int sum[26][2001][2001]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll H, W, K; cin >> H >> W >> K; for (ll i = 0; i < H; i++) { string s; cin >> s; for (ll j = 0; j < W; j++) sum[s[j] - 'a'][i + 1][j + 1]++; } for (ll i = 0; i < 26; i++)for (ll j = 1; j <= H; j++)for (ll k = 1; k <= W; k++) sum[i][j][k] += sum[i][j][k - 1] + sum[i][j - 1][k] - sum[i][j - 1][k - 1]; ll res = 0; for (ll i = 0; i < H; i++) { for (ll j = 0; j < W; j++) { ll low = 0; ll upp = 0; { ll left = 0; ll right = min(H, W); while (right - left > 1) { ll mid = (left + right) >> 1; if (i + mid - 1 >= H || j + mid - 1 >= W) { right = mid - 1; continue; } ll cnt = 0; for (ll k = 0; k < 26; k++) { cnt += ((sum[k][i + mid][j + mid] - sum[k][i][j + mid] - sum[k][i + mid][j] + sum[k][i][j]) > 0); } if (cnt < K) { left = mid; } else { right = mid; } } ll cnt = 0; for (ll k = 0; k < 26; k++) { cnt += (sum[k][i + right][j + right] - sum[k][i][j + right] - sum[k][i + right][j] + sum[k][i][j]) > 0; } if (cnt >= K) low = right; else low = right + 1; } { ll left = 0; ll right = min(H, W); while (right - left > 1) { ll mid = (left + right) >> 1; if (i + mid - 1 >= H || j + mid - 1 >= W) { right = mid - 1; continue; } ll cnt = 0; for (ll k = 0; k < 26; k++) { cnt += (sum[k][i + mid][j + mid] - sum[k][i][j + mid] - sum[k][i + mid][j] + sum[k][i][j]) > 0; } if (cnt <= K) { left = mid; } else { right = mid; } } ll cnt = 0; for (ll k = 0; k < 26; k++) { cnt += (sum[k][i + right][j + right] - sum[k][i][j + right] - sum[k][i + right][j] + sum[k][i][j]) > 0; //cout << i << " " << j << " " << k << " " << cnt << endl; } //cout << i << " " << j << " " << right << " " << cnt << endl; if (cnt > K) upp = right; else upp = right + 1; } //cout << i<<" "<