#include using vi26 = std::vector>; using vvi26 = std::vector; int H, W, K; vvi26 table; int scaleCount(int, int, int); int calcLevel(int, int, int, int); int main() { scanf("%d%d%d", &H, &W, &K); table.resize(H + 1, vi26(W + 1)); for (int h{1}; h <= H; h++) for (int w{1}; w <= W; w++) { char c; scanf(" %c", &c); table[h][w][c - 'a']++; } for (int h{1}; h <= H; h++) for (int w{1}; w <= W; w++) for (int c{}; c < 26; c++) table[h][w][c] += table[h][w - 1][c]; for (int h{1}; h <= H; h++) for (int w{}; w <= W; w++) for (int c{}; c < 26; c++) table[h][w][c] += table[h - 1][w][c]; int64_t ans{}; for (int h{H - 1}; h > 0; h--) ans += scaleCount(h, 0, K) - scaleCount(h, 0, K + 1); ans += scaleCount(0, 0, K) - scaleCount(0, 0, K + 1); for (int w{W}; w > 0; w--) ans += scaleCount(0, w, K) - scaleCount(0, w, K + 1); printf("%lld\n", ans); return 0; } int scaleCount(int begin_h, int begin_w, int K) { int ans{}; for (int right{1}, left{}; begin_h + right <= H && begin_w + right <= W; right++) { if (calcLevel(begin_h + left, begin_w + left, begin_h + right, begin_w + right) < K) continue; while (calcLevel(begin_h + left + 1, begin_w + left + 1, begin_h + right, begin_w + right) >= K) left++; ans += left + 1; } return ans; } int calcLevel(int top, int left, int bottom, int right) { int level{}; for (int c{}; c < 26; c++) if (table[bottom][right][c] + table[top][left][c] - table[top][right][c] - table[bottom][left][c] > 0) level++; return level; }