//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 100010001; const ll LINF = (ll)INF*INF*10; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} const int N = 2010; //head int h, w, k; string c[N]; int siz[N][N][27]; ll ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> h >> w >> k; rep(i, h) cin >> c[i]; for(int i = h-1; i >= 0; i--) for(int j = w-1; j >= 0; j--) { rep(k, 26) { if(c[i][j] == 'a'+k) siz[i][j][k] = 1; else { if(i == h-1 or j == w-1) siz[i][j][k] = 2; else { siz[i][j][k] = min({h-i+1, w-j+1, siz[i+1][j][k], siz[i][j+1][k], siz[i+1][j+1][k]})+1; } } } } rep(i, h) rep(j, w) { sort(siz[i][j], siz[i][j]+26); ans += siz[i][j][k] - siz[i][j][k-1]; } cout << ans << endl; }