#include #define all(vec) vec.begin(), vec.end() using namespace std; using ll = long long; using P = pair; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll LINF = (1LL << 60) - 1LL; constexpr double eps = 1e-9; constexpr ll MOD = 1000000007LL; template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }; template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }; template ostream &operator<<(ostream &os, vector v) { for (int i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "\n" : " "); } return os; } template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } template typename enable_if::value == 0>::type fill_v(T &t, const V &v) { t = v; } template typename enable_if::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) { fill_v(e, v); } }; struct Segtree { int H, W; vector> dat; Segtree() {} void build(int H_, int W_, vector> &f) { H = 1; while (H < H_) { H <<= 1; } W = 1; while (W < W_) { W <<= 1; } dat.assign(2 * H - 1, vector(2 * W - 1, 0)); for (int i = 0; i < (int)f.size(); i++) { for (int j = 0; j < (int)f[0].size(); j++) { dat[i + H - 1][j + W - 1] = f[i][j]; } } for (int i = 2 * H - 2; i > H - 2; i--) { for (int j = W - 2; j >= 0; j--) { dat[i][j] = dat[i][2 * j + 1] | dat[i][2 * j + 2]; } } for (int i = H - 2; i >= 0; i--) { for (int j = 0; j < 2 * W - 1; j++) { dat[i][j] = dat[2 * i + 1][j] | dat[2 * i + 2][j]; } } } int query(int li, int lj, int ri, int rj) { //(y1,x1),(y2,x2) return queryh(li, lj, ri, rj, 0, H, 0); } int queryh(int li, int lj, int ri, int rj, int si, int ti, int k) { if (ri <= si || ti <= li) { return 0; } if (li <= si && ti <= ri) { return queryw(lj, rj, 0, W, k, 0); } const int mi = (si + ti) / 2; return queryh(li, lj, ri, rj, si, mi, 2 * k + 1) | queryh(li, lj, ri, rj, mi, ti, 2 * k + 2); } int queryw(int lj, int rj, int sj, int tj, int i, int k) { if (rj <= sj || tj <= lj) { return 0; } if (lj <= sj && tj <= rj) { return dat[i][k]; } const int mj = (sj + tj) / 2; return queryw(lj, rj, sj, mj, i, 2 * k + 1) | queryw(lj, rj, mj, tj, i, 2 * k + 2); } }; int h, w, k; Segtree seg; inline int popcnt(int k) { return __builtin_popcount(k); } int calc(int p) { int res = 0; for (int i = 1; i < h; i++) { int y = i, x = 0; int l = 0; while (x < w && y < h) { while (l <= x && popcnt(seg.query(i + l, l, y + 1, x + 1)) >= p) { l++; } res += l; x++; y++; } } for (int i = 0; i < w; i++) { int y = 0, x = i; int l = 0; while (x < w && y < h) { while (l <= y && popcnt(seg.query(l, i + l, y + 1, x + 1)) >= p) { l++; } res += l; x++; y++; } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w >> k; auto a = make_v(h, w); for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { a[i][j] = 1 << (s[j] - 'a'); } } seg.build(h, w, a); cout << calc(k) - calc(k + 1) << endl; }