#pragma GCC target("avx2") #pragma GCC optimize("O3") #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 int inf = 1 << 28; //const long long mod = 1000000007LL; const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int dp[26][2002][2002]; int len[27]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int H, W, K; cin >> H >> W >> K; for (int k = 0; k < 26; k++)for (int i = 0; i <= H; i++) for (int j = 0; j <= W; j++) dp[k][i][j] = min(H - i + 1, W - j + 1); for (int i = 0; i < H; i++) { string s; cin >> s; for (ll j = 0; j < W; j++) { dp[s[j] - 'a'][i][j] = 1; } } for (int k = 0; k < 26; k++) { for (int i = H - 1; i >= 0; i--) { for (int j = W - 1; j >= 0; j--) { chmin(dp[k][i][j], dp[k][i + 1][j] + 1); chmin(dp[k][i][j], dp[k][i][j + 1] + 1); chmin(dp[k][i][j], dp[k][i + 1][j + 1] + 1); } } } ll res = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < 26; k++) { len[k] = dp[k][i][j]; } sort(len, len + 26); len[26] = min(H - i + 1, W - j + 1); //cout << i << " " << j << " " << len[K] << " " << len[K - 1] << endl; res += len[K] - len[K - 1]; } } cout << res << "\n"; return 0; /* おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!! */ }