#include using namespace std; #define st first #define nd second #define pb push_back #define mp make_pair #define klar(v) memset(v, 0, sizeof(v)) #define endl "\n" typedef vector vi; typedef vector> vpii; typedef vector vll; typedef pair pii; typedef long long ll; typedef pair pll; const int maxn = 1100; char grid[maxn][maxn]; int Xa[] = {-1, 0, -1, -1}, Ya[] = {0, -1, -1, 0}; int Xb[] = {0, 1, 0, -1}, Yb[] = {-1, -1, -1, -1}; ll dp[maxn][maxn]; ll gemacht(char w, int n, int m, int k){ ll ret = 0; //if(w != '#')return 0; //if(k != 0)return 0; klar(dp); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(grid[i][j] == w){ dp[i][j] = min(dp[i+Ya[k]][j+Xa[k]], dp[i+Yb[k]][j+Xb[k]])+1; //cout << i << " " << j << " " << dp[i][j] << " " << dp[i+Yb[k]][j+Xb[k]] << " " << i+Yb[k] << " " << j+Xb[k] << endl; } //cout << endl; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) ret += max(dp[i][j]-1, 0LL); return ret; } int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> grid[i][j]; ll ans = 0; for(int i = 33; i <= 126; i++) for(int j = 0; j < 4; j++) ans += gemacht(char(i), n, m, j); cout << ans << endl; return 0; }