#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Pll = pair; using Pii = pair; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int h,w,k; cin >> h >> w >> k; vector> a(h+1, vector(w+1, -1)); for(int i=1;i<=h;++i) { string s; cin >> s; for(int j=1;j<=w;++j) { a[i][j] = int(s[j-1] - 'a'); } } int kr = 1; // k を達成するのに最低限必要な半径 while(kr*kr < k) ++kr; int count[h+1][w+1][26]; fill_n(count[0][0], (h+1)*(w+1)*26, 0); for(int i=1;i<=h;++i) { for(int j=1;j<=w;++j) { for(int k=0;k<26;++k) { count[i][j][k] = count[i-1][j][k] + count[i][j-1][k] - count[i-1][j-1][k]; } ++count[i][j][a[i][j]]; } } int ans = 0; for(int i=1;i<=h;++i) { for(int j=1;j<=w;++j) { for(int r=kr;r<=min(h-i+1, w-j+1);++r) { int level = 0; for(int k=0;k<26;++k) { if(count[i+r-1][j+r-1][k] - count[i+r-1][j-1][k] - count[i-1][j+r-1][k] + count[i-1][j-1][k] > 0) { ++level; } } // cerr << i << "," << j << " " << r << ": " << level << endl; if(level > k) { break; } else if(level == k) { ++ans; } } } } cout << ans << endl; }