#include using namespace std; #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define endl "\n" typedef long long ll; typedef pair pii; typedef pair pll; template ostream &operator<<(ostream &os, const vector &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; } template ostream &operator<<(ostream &os, const pair &p) {os << "(" << p.first << ", " << p.second << ")"; return os;} void solve() { int H, W, K; cin >> H >> W >> K; vector C(H); for (int i = 0; i < H; i++) { cin >> C[i]; } vector>> flag(26, vector>(H, vector(W, 0))); vector>> acc(26, vector>(H + 1, vector(W + 1, 0))); for (int c = 0; c < 26; c++) { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (C[i][j] == 'a' + c) { flag[c][i][j] = 1; } } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { acc[c][i + 1][j + 1] = acc[c][i][j + 1] + acc[c][i + 1][j] - acc[c][i][j] + flag[c][i][j]; } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int tmax = min(H - i, W - j) + 1; int tmin = 0; while(tmax - tmin > 1) { int t = (tmax + tmin) / 2; int sum = 0; for(int c = 0; c < 26; c++) { sum += (acc[c][i + t][j + t] - acc[c][i][j + t] - acc[c][i + t][j] + acc[c][i][j] > 0) ? 1 : 0; } if (sum <= K) { tmin = t; } else { tmax = t; } } int alpha = tmin; tmax = min(H - i, W - j) + 1; tmin = 0; while(tmax - tmin > 1) { int t = (tmax + tmin) / 2; int sum = 0; for(int c = 0; c < 26; c++) { sum += (acc[c][i + t][j + t] - acc[c][i][j + t] - acc[c][i + t][j] + acc[c][i][j] > 0) ? 1 : 0; } if (sum < K) { tmin = t; } else { tmax = t; } } int beta = tmin; ans += alpha - beta; } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }