#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  char grid[n + 5][m + 5];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> grid[i][j];
    }
  }
  for (int i = 0; i <= m + 1; i++) {
    grid[0][i] = '*';
    grid[n + 1][i] = '*';
  }
  for (int i = 0; i <= n + 1; i++) {
    grid[i][0] = '*';
    grid[i][m + 1] = '*';
  }
  int dp[n + 5][m + 5];
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      dp[i][j] = 0;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (grid[i][j] == grid[i - 1][j] && grid[i][j] == grid[i - 1][j - 1] &&
          grid[i][j] == grid[i - 1][j + 1]) {
        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1]);
        dp[i][j] = min(dp[i][j], dp[i - 1][j + 1]);
        if (grid[i - 2 * dp[i][j]][j] == grid[i][j]) {
          dp[i][j]++;
        }
      } else {
        dp[i][j] = 1;
      }
      ans = ans + 1LL * dp[i][j];
    }
  }
  cout << ans;
  return 0;
}
