#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int INF = 2000000000;
const long long INFLL = 1LL * INF * INF;
char arr[N][N];
int same[N][N];
long long dp[N][N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> arr[i][j];
      same[i][j] = 1 + (arr[i][j] == arr[i - 1][j]) * same[i - 1][j];
    }
  }
  long long res = 0;
  for (int i = 3; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int pi = i - same[i][j], ppi = i - 2 * same[i][j];
      if (same[i][j] != same[pi][j] || same[i][j] > same[ppi][j]) {
        continue;
      }
      dp[i][j] = 1;
      if (arr[i][j] == arr[i][j - 1] && same[i][j] == same[i][j - 1] &&
          arr[pi][j] == arr[pi][j - 1] && same[i][j] == same[pi][j - 1] &&
          arr[ppi][j] == arr[ppi][j - 1] && same[i][j] <= same[ppi][j - 1]) {
        dp[i][j] += dp[i][j - 1];
      }
      res += dp[i][j];
    }
  }
  cout << res << '\n';
  return 0;
}
