#include #include #include #include using namespace std; typedef long long ll; int H,W,K; vector> F(2001,vector(2001)); vector>> dp(26,vector>(2001,vector(2001,-1))); int rec(int x,int y,int c){ if(dp[c][x][y]!=-1) return dp[c][x][y]; if(F[x][y]-'a'==c) return dp[c][x][y] = 1; int res = min(H-x+1,W-y+1)+1; if(x!=H && y!=W) res = min(res,rec(x+1,y+1,c)+1); if(x!=H) res = min(res,rec(x+1,y,c)+1); if(y!=W) res = min(res,rec(x,y+1,c)+1); return dp[c][x][y] = res; } int main(){ cin >> H >> W >> K; for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) cin >> F[i][j]; ll ans = 0; for(int c=0;c<26;c++){ for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) rec(i,j,c); } vector A(27); for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){ for(int c=0;c<26;c++){ A[c] = dp[c][i][j]; } A[26] = min(H-i+1,W-j+1)+1; sort(A.begin(),A.end()); ans += (ll) A[K]-A[K-1]; } cout << ans << endl; }