#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[2010][2010];
int sum1[2010][2010], sum2[2010][2010], c[2010][2010], d[2010];
int f[2010][2010], ans = 0;
bool check(int x, int y, int l) {
  bool v = true;
  v &= ((sum1[x][y + l - 1] -
         1ll * sum1[x - l + 1 - 1][y - 1] * d[l] % 1000000007 + 1000000007) %
        1000000007) == c[s[x][y - 1] - 'a' + 1][l];
  v &= ((sum2[x + l - 1][y] -
         1ll * sum2[x - 1][y + l - 1 + 1] * d[l] % 1000000007 + 1000000007) %
        1000000007) == c[s[x][y - 1] - 'a' + 1][l];
  v &= ((sum1[x][y + l] - 1ll * sum1[x - l - 1][y - 1] * d[l + 1] % 1000000007 +
         1000000007) %
        1000000007) == c[s[x][y - 1] - 'a' + 1][l + 1];
  v &= ((sum2[x + l][y] - 1ll * sum2[x - 1][y + l + 1] * d[l + 1] % 1000000007 +
         1000000007) %
        1000000007) == c[s[x][y - 1] - 'a' + 1][l + 1];
  return v;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; j++) {
      sum1[i][j] = (26ll * sum1[i - 1][j - 1] + s[i][j] - 'a' + 1) % 1000000007;
      sum2[i][j] = (26ll * sum2[i - 1][j + 1] + s[i][j] - 'a' + 1) % 1000000007;
    }
  }
  d[0] = 1;
  for (int i = 1; i <= n; i++) d[i] = 26ll * d[i - 1] % 1000000007;
  for (int i = 1; i <= 26; i++) {
    for (int j = 1; j <= n; j++)
      c[i][j] = (26ll * c[i][j - 1] + i) % 1000000007;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[i][j] = max(1, max(f[i - 1][j], f[i][j - 1]) - 1);
      for (int k = f[i][j - 1]; k >= f[i][j - 1] - 1; k--)
        if (k > 0 && i - k >= 1 && j - k >= 1 && i + k <= n && j + k <= m) {
          if (check(i, j, k)) {
            f[i][j] = k + 1;
            break;
          }
        }
      ans += f[i][j];
    }
  }
  printf("%d", ans);
}
