#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; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; //constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; bool a[26][2001][2001]; char s[2010]; int dp[26][2001][2001]; int srt[26]; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int H, W, K; scanf("%d %d %d", &H, &W, &K); for (int i = 0; i < 26; i++) for (int j = 0; j <= H; j++) for (int k = 0; k <= W; k++) dp[i][j][k] = min(H - j + 1, W - k + 1); for (int i = 0; i < H; i++) { scanf("%s", s); for (int j = 0; j < W; j++) { a[s[j] - 'a'][i][j] = true; dp[s[j] - 'a'][i][j] = 1; } } for (int i = 0; i < 26; i++) { for (int j = H - 1; j >= 0; j--) { for (int k = W - 1; k >= 0; k--) { chmin(dp[i][j][k], dp[i][j + 1][k] + 1); chmin(dp[i][j][k], dp[i][j][k + 1] + 1); chmin(dp[i][j][k], dp[i][j + 1][k + 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++) { srt[k] = dp[k][i][j]; } sort(srt, srt + 26); res += srt[K] - srt[K - 1]; } } printf("%lld\n", res); return 0; /* おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!! */ }