#include using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define endl "\n" #define MP make_pair #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORR(x,arr) for(auto& x:arr) #define PII pair #define FI first #define SE second #define ALL(x) (x).begin(), (x).end() const int INF=1<<30; const ll LINF=1LL<<60; const ll mod=1e9+7; const int NIL = -1; templateinline bool chmax(T &a, const T &b) { if (ainline bool chmin(T &a, const T &b) { if (b> h >> w >> k; ll ans = 0; //memset(dp,-1,sizeof(dp)); FOR(i,1,h) FOR(j,1,w){ cin >> table[i][j]; } for(int a=0; a<26;a++){ for(int i=h+1; i>=1; i--){ for(int j=w+1; j>=1; j--){ if(table[i][j] == char(base+a)){ dp[i][j][a] = 1; continue; } dp[i][j][a] = min(dp[i+1][j+1][a], min(dp[i+1][j][a],dp[i][j+1][a]))+1; dp[i][j][a] = min(dp[i][j][a], min(h+1-i, w+1-j)+2); } } } FOR(i,1,h){ FOR(j,1,w){ sort(dp[i][j], dp[i][j]+26); ans += 1LL * (dp[i][j][k] - dp[i][j][k-1]); } } cout << ans << endl; return 0; }