#include #include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(n);i++) #define rep1(i,n) for(int i=1;i<=(n);i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const ll MOD = 1000000007; //const ll MOD = 998244353; const double pi = 3.14159265358979323846; #define Sp(p) cout< sum(H + 1, vii(W + 1, vi(26))); int h, w, k; bool check1(int i, int j, int ok) { //DEBUG(pii(i, j)); //DEBUG(ok); int cnt = 0; vi num(26); rep (t, 26) { num[t] = sum[i + ok][j + ok][t] - sum[i][j + ok][t] - sum[i + ok][j][t] + sum[i][j][t]; if (num[t] > 0) cnt++; } //DEBUG_VEC(num); return cnt >= k; } bool check2(int i, int j, int ok) { //DEBUG(pii(i, j)); //DEBUG(ok); int cnt = 0; vi num(26); rep (t, 26) { num[t] = sum[i + ok][j + ok][t] - sum[i][j + ok][t] - sum[i + ok][j][t] + sum[i][j][t]; if (num[t] > 0) cnt++; } //DEBUG_VEC(num); return cnt > k; } int nibutan(int i, int j) { int ok = min(w - j, h - i); if (not check1(i, j, ok)) return 0; int ng = 0; while (ng + 1 < ok) { int mid = (ng + ok) / 2; if (check1(i, j, mid)) { ok = mid; } else { ng = mid; } } int low_ok = ok; ok = min(w - j, h - i); if (not check2(i, j, ok)) { return ok - low_ok + 1; } ng = low_ok - 1; while (ng + 1 < ok) { int mid = (ng + ok) / 2; if (check2(i, j, mid)) { ok = mid; } else { ng = mid; } } //DEBUG(low_ok); //DEBUG(ok); return ok - low_ok; } int main() { cin >> h >> w >> k; vector num(h, vii(w, vi(26))); rep (i, h) { rep (j, w) { char c; cin >> c; num[i][j][c - 'a']++; } } rep (i, h) { rep (j, w) { rep (k, 26) { sum[i + 1][j + 1][k] = sum[i + 1][j][k] + num[i][j][k]; } } rep (j, w + 1) { rep (k, 26) { sum[i + 1][j][k] += sum[i][j][k]; } } } ll ans = 0; rep (i, h) { rep (j, w) { //DEBUG(pii(i, j)); ans += nibutan(i, j); //DEBUG(ans); } } cout << ans << endl; }