#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< 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; rep (t, 26) { int temp = sum[i + ok][j + ok][t] - sum[i][j + ok][t] - sum[i + ok][j][t] + sum[i][j][t]; if (temp > 0) cnt++; } //DEBUG_VEC(num); return cnt > k; } int solve(int si, int sj) { int l = 0, r1 = 0, r2 = 0; while (si + r1 < h and sj + r1 < w) { if (check1(si, sj, r1)) break; r1++; r2++; } if (not check1(si, sj, r1)) return 0; while (si + r2 <= h and sj + r2 <= w) { if (check2(si, sj, r2)) break; r2++; } int res = r2 - r1; while (si + l < h and sj + l < w) { l++; while (si + r1 < h and sj + r1 < w and not check1(si + l, sj + l, r1 - l)) { r1++; } if (not check1(si + l, sj + l, r1 - l)) return res; while (si + r2 <= h and sj + r2 <= w and not check2(si + l, sj + l, r2 - l)) { r2++; } res += r2 - r1; } return res; } int main() { cin >> h >> w >> k; rep (i, h) { rep (j, w) { char c; cin >> c; sum[i + 1][j + 1][c - 'a']++; } } rep (i, h) { rep (j, w) { rep (k, 26) { sum[i + 1][j + 1][k] += sum[i + 1][j][k]; } } rep (j, w + 1) { rep (k, 26) { sum[i + 1][j][k] += sum[i][j][k]; } } } ll ans = 0; rep (i, h) { //DEBUG(pii(i, j)); // ans += nibutan(i, j); ans += solve(i, 0); //DEBUG(ans); } for (int j = 1; j < w; j++) { ans += solve(0, j); } cout << ans << endl; } /* 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; } //*/