#include #include #include #define inf 1000000000 using namespace std; int h, w, k; int sum[2005][2005]; char c[2005][2005]; int dp[2005][2005]; vector vec[2005][2005]; int get(int x, int y, int k) { return sum[x+k][y+k]-sum[x+k][y-1]-sum[x-1][y+k]+sum[x-1][y-1]; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w >> k; for(int y = 1; y <= h; y++){ for(int x = 1; x <= w; x++){ cin >> c[x][y]; } } for(int x = 1; x <= w+1; x++) dp[x][h+1] = inf; for(int y = 1; y <= h+1; y++) dp[w+1][y] = inf; for(int i = 0; i < 26; i++){ for(int x = 1; x <= w; x++){ for(int y = 1; y <= h; y++){ sum[x][y] = sum[x-1][y]+sum[x][y-1]-sum[x-1][y-1]; if(c[x][y] == i+'a') sum[x][y]++; } } for(int y = h; y >= 1; y--){ for(int x = w; x >= 1; x--){ dp[x][y] = min(dp[x+1][y], dp[x][y+1]); if(c[x][y] == i+'a') dp[x][y] = 0; if(dp[x][y] >= inf) continue; if(get(x, y, dp[x][y]) == 0) dp[x][y]++; if(dp[x][y] > min(w-x, h-y)) continue; vec[x][y].push_back(dp[x][y]); } } } int ans = 0; for(int x = 1; x <= w; x++){ for(int y = 1; y <= h; y++){ if(vec[x][y].size() < k) continue; vec[x][y].push_back(min(w-x, h-y)+1); sort(vec[x][y].begin(), vec[x][y].end()); ans += vec[x][y][k] - vec[x][y][k-1]; } } cout << ans << endl; return 0; }