#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
const int M = 1000;
int mat[N][M], dp[N][M], dpp[N][M];
bool vis[N][M];
int n, m;
int nc2(int n) { return n * (n - 1) / 2; }
void fdown() {
  for (int j = 0; j < m; j++) {
    dp[n - 1][j] = 1;
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = (mat[i][j] == mat[i + 1][j]) ? dp[i + 1][j] + 1 : 1;
    }
  }
}
void fright() {
  for (int i = 0; i < n; i++) {
    dpp[i][m - 1] = 1;
  }
  for (int j = m - 2; j >= 0; j--) {
    for (int i = 0; i < n; i++) {
      dpp[i][j] = (mat[i][j] == mat[i][j + 1]) ? dpp[i][j + 1] + 1 : 1;
    }
  }
}
void solve() {
  int ans;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char x;
      cin >> x;
      mat[i][j] = x - 'a';
    }
  }
  fdown();
  fright();
  ans = 0;
  for (int colour = 0; colour < 26; colour++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (mat[i][j] == colour && !vis[i][j]) {
          int ht = dp[i][j];
          vis[i][j] = true;
          for (int k = i; k < i + ht; k++) {
            vis[k][j] = true;
          }
          if (i - ht < 0 || dp[i - ht][j] < ht || i + ht >= n ||
              dp[i + ht][j] < ht)
            continue;
          int rb = dpp[i][j];
          for (int k = i; k < i + ht; k++) {
            rb = min(rb, dpp[k][j]);
          }
          for (int k = i - ht; k < i; k++) {
            rb = min(rb, dpp[k][j]);
          }
          for (int k = i + ht; k < i + 2 * ht; k++) {
            rb = min(rb, dpp[k][j]);
          }
          ans += nc2(rb + 1);
          for (int k = i; k < i + ht; k++) {
            for (int l = j + 1; l < j + rb; l++) {
              vis[k][l] = true;
            }
          }
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
