#define rep(i, n) for(int i = 0; i < (int)(n); i++) typedef long long ll; #include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); ll h,w,K; std::cin >> h>>w>>K; std::vector s(h); // int sum[26][2001][2001]; vector>> sum(26,vector>(h+1,vector(w+1))); for (int i = 0; i < h; i++) { std::cin >> s[i]; for (int j = 0; j < w; j++) { int alpha = s[i][j]-'a'; for (int k = 0; k < 26; k++) { sum[k][i+1][j+1] = sum[k][i][j+1] + sum[k][i+1][j] - sum[k][i][j]; } sum[alpha][i+1][j+1]++; } } ll result = 0; // vector> size_from(h,vector(w,1)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ll l,r; l = 0; r = min(h-i,w-j)+1; while(r-l>1){ ll size = (r+l)/2; ll num = 0; for (int k = 0; k < 26; k++) { ll cou = sum[k][i+size][j+size]-sum[k][i][j+size]-sum[k][i+size][j]+sum[k][i][j]; if(cou>0)num++; } if(num1){ ll size = (r+l)/2; ll num = 0; for (int k = 0; k < 26; k++) { ll cou = sum[k][i+size][j+size]-sum[k][i][j+size]-sum[k][i+size][j]+sum[k][i][j]; if(cou>0)num++; } if(num<=K){ l = size; }else{ r = size; } } result += l-maxmin; } } std::cout << result << std::endl; }