#include using namespace std; using ll = long long; struct segtree { int H, W; vector> dat; segtree(){} segtree(vector> &f) { H = W = 1; while(H < (int)f.size()) H <<= 1; while(W < (int)f[0].size()) W <<= 1; dat.assign(2*H-1,vector(2*W-1,0)); init(f); } void init(vector> &f) { for (int i = 0; i < (int)f.size(); i++) for (int j = 0; j < (int)f[0].size(); j++) dat[i+H-1][j+W-1] = f[i][j]; for (int i = 2*H-2; i > H-2; i--) for (int j = W-2; j >= 0; j--) dat[i][j] = (dat[i][2*j+1] | dat[i][2*j+2]); for (int i = H-2; i >= 0; i--) for (int j = 0; j < 2*W-1; j++) dat[i][j] = (dat[2*i+1][j] | dat[2*i+2][j]); } int minimum(int li, int lj, int ri, int rj) { return minimum_h(li,lj,ri,rj,0,H,0); } int minimum_h(int li, int lj, int ri, int rj, int si, int ti, int k) { if(ri <= si or ti <= li) return 0; if(li <= si and ti <= ri) return minimum_w(lj,rj,0,W,k,0); const int mi = (si+ti)/2; return (minimum_h(li,lj,ri,rj,si,mi,2*k+1) | minimum_h(li,lj,ri,rj,mi,ti,2*k+2)); } int minimum_w(int lj, int rj, int sj, int tj, int i, int k) { if(rj <= sj or tj <= lj) return 0; if(lj <= sj and tj <= rj) return dat[i][k]; const int mj = (sj+tj)/2; return (minimum_w(lj,rj,sj,mj,i,2*k+1) | minimum_w(lj,rj,mj,tj,i,2*k+2)); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, K; cin >> h >> w >> K; vector c(h); vector< vector > masks(h, vector(w, 0)); for (int i = 0; i < h; i++) { cin >> c[i]; for (int j = 0; j < w; j++) { masks[i][j] = (1 << (c[i][j] - 'a')); } } segtree seg(masks); ll ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int sz = min(i + 1, j + 1); int ng = 0, ok = sz + 1; while (ok - ng > 1) { int mid = (ok + ng) / 2; int val = seg.minimum(i + 1 - mid, j + 1 - mid, i + 1, j + 1); if (__builtin_popcount(val) >= K) { ok = mid; } else { ng = mid; } } if (ok <= 0 || ok > sz) continue; int ng2 = sz + 1, ok2 = -1; while (ng2 - ok2 > 1) { int mid = (ok2 + ng2) / 2; int val = seg.minimum(i + 1 - mid, j + 1 - mid, i + 1, j + 1); if (__builtin_popcount(val) <= K) { ok2 = mid; } else { ng2 = mid; } } if (ok2 <= 0 || ok2 > sz || ok > ok2) continue; ans += ok2 - ok + 1; //cerr << i << " " << j << ": " << ok << " " << ok2 << endl; } } cout << ans << "\n"; return 0; }