#include <bits/stdc++.h>
using namespace std;
long long ld[2002][2002], ru[2002][2002], lu[2002][2002], rd[2002][2002], ans;
char arr[2002][2002];
int N, M;
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      long long mn = 1000000000;
      for (int k = 0; k < 2; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (arr[x][y] == arr[i][j])
          mn = min(mn, lu[x][y]);
        else
          mn = 0;
      }
      lu[i][j] = 1 + mn;
    }
  }
  for (int i = N; i >= 1; i--) {
    for (int j = M; j >= 1; j--) {
      long long mn = 1000000000;
      for (int k = 2; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (arr[x][y] == arr[i][j])
          mn = min(mn, rd[x][y]);
        else
          mn = 0;
      }
      rd[i][j] = 1 + mn;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = M; j >= 1; j--) {
      long long mn = 1000000000;
      for (int k = 0; k < 4; k += 2) {
        int x = i + dx[k], y = j + dy[k];
        if (arr[x][y] == arr[i][j])
          mn = min(mn, ru[x][y]);
        else
          mn = 0;
      }
      ru[i][j] = 1 + mn;
    }
  }
  for (int i = N; i >= 1; i--) {
    for (int j = 1; j <= M; j++) {
      long long mn = 1000000000;
      for (int k = 1; k < 4; k += 2) {
        int x = i + dx[k], y = j + dy[k];
        if (arr[x][y] == arr[i][j])
          mn = min(mn, ld[x][y]);
        else
          mn = 0;
      }
      ld[i][j] = 1 + mn;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      ans += min(min(ld[i][j], lu[i][j]), min(rd[i][j], ru[i][j]));
    }
  }
  cout << ans;
}
