#include #include #include #include #include #include #include using namespace std; typedef long long ll; int cnt[26][2001][2001]; int H, W, K; bool exist(int h1, int w1, int h2, int w2, char c){ return cnt[c-'a'][h2+1][w2+1]-cnt[c-'a'][h1][w2+1]-cnt[c-'a'][h2+1][w1]+cnt[c-'a'][h1][w1] > 0; } int sum(int h1, int w1, int h2, int w2){ int ans = 0; for(int i = 0; i < 26; i++){ if(exist(h1, w1, h2, w2, 'a'+i)) ans++; } return ans; } int search_upper(int h1, int w1, int m){ if(sum(h1, w1, h1+1, w1+1) > m) return 0; int l = 1, r = min(H-h1-1, W-w1-1); if(sum(h1, w1, h1+r, w1+r) == m) return r; while(r-l > 1){ int c = (l+r)/2; if(sum(h1, w1, h1+c, w1+c) > m) r = c; else l = c; } return l; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> H >> W >> K; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ char c; cin >> c; for(int k = 0; k < 26; k++){ cnt[k][i+1][j+1] = cnt[k][i+1][j]+cnt[k][i][j+1]-cnt[k][i][j]; if(c == 'a'+k) cnt[k][i+1][j+1]++; } } } ll ans = 0; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ ans += max(0, search_upper(i, j, K)-search_upper(i, j, K-1)); } } cout << ans << endl; }