#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; char S[2000][2001]; int sum[26][2001][2001]; int main() { int H, W, K; scanf("%d %d %d", &H, &W, &K); rep(i, H) scanf("%s", S[i]); rep(i, H) rep(j, W) rep(k, 26) { sum[k][i+1][j+1] = sum[k][i+1][j] + sum[k][i][j+1] - sum[k][i][j] + (S[i][j] - 'a' == k); } vector from_y, from_x; from_y.push_back(0); from_x.push_back(0); rep(i, H-1) from_y.push_back(i+1), from_x.push_back(0); rep(i, W-1) from_y.push_back(0), from_x.push_back(i+1); auto calc = [&](int k, int y1, int y2, int x1, int x2) -> int { return sum[k][y2][x2] - sum[k][y2][x1] - sum[k][y1][x2] + sum[k][y1][x1]; }; ll ans = 0; rep(u, from_y.size()) { int y = from_y[u]; int x = from_x[u]; vector ptr(26); int mn = 0; int mx = 0; int len = min(H - from_y[u], W - from_x[u]); for (; y < H && x < W; y++, x++) { rep(k, 26) { while (ptr[k] <= len && calc(k, y, ptr[k] + from_y[u], x, ptr[k] + from_x[u]) == 0) ptr[k]++; } auto count = [&](int x) { int ans = 0; rep(k, 26) ans += ptr[k] <= x; return ans; }; while (mn <= len && count(mn) < K) mn++; while (mx <= len && count(mx) <= K) mx++; ans += mx - mn; } } cout << ans << endl; }