#include #pragma GCC optimize("O3", "unroll-loops") using namespace std; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector &vec, int len) { vec.resize(len); } template void ndarray(vector &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template istream &operator>>(istream &is, vector &vec){ for (auto &v : vec) is >> v; return is; } ///// This part below is only for debug, not used ///// template ostream &operator<<(ostream &os, const vector &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const deque &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const pair &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template ostream &operator<<(ostream &os, const map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; ///// END ///// /* #include #include #include using namespace __gnu_pbds; // find_by_order(), order_of_key() template using pbds_set = tree, rb_tree_tag, tree_order_statistics_node_update>; template using pbds_map = tree, rb_tree_tag, tree_order_statistics_node_update>; */ using lint = long long int; int dp[26][2001][2001]; int H, W, K; int count_n(int i, int j, int L) { int ret = 0; REP(d, 26) { int tmp = dp[d][i + L][j + L] - dp[d][i][j + L] - dp[d][i + L][j] + dp[d][i][j]; if (tmp > 0) ret++; } return ret; } int main() { cin >> H >> W >> K; vector C(H); cin >> C; memset(dp, 0, sizeof(dp)); REP(i, H) REP(j, W) dp[C[i][j] - 'a'][i + 1][j + 1]++; REP(d, 26) REP(i, H + 1) REP(j, W) { dp[d][i][j + 1] += dp[d][i][j]; } REP(d, 26) REP(i, H) REP(j, W + 1) { dp[d][i + 1][j] += dp[d][i][j]; } lint ret = 0; REP(i, H) REP(j, W) { int dmax = min(H - i, W - j); int cn = count_n(i, j, dmax); if (cn < K) continue; int l = 0, r = dmax; while (r - l > 1) { int c = (l + r) / 2; if (count_n(i, j, c) < K) l = c; else r = c; } if (count_n(i, j, r) == K) { int ll = r, rr = dmax + 1; while (rr - ll > 1) { int c = (ll + rr) / 2; if (count_n(i, j, c) > K) rr = c; else ll = c; } ret += ll - l; } } cout << ret << endl; }