#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int inf = 1e9;
const int BufferSize = 1 << 16;
char buffer[BufferSize], *head, *tail;
inline char Getchar() {
  if (head == tail) {
    long long l = fread(buffer, 1, BufferSize, stdin);
    tail = (head = buffer) + l;
  }
  return *head++;
}
inline long long read() {
  long long x = 0, f = 1;
  char c = Getchar();
  for (; !isdigit(c); c = Getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = Getchar()) x = x * 10 + c - '0';
  return x * f;
}
char maze[1005][1005];
int suf[1005][1005];
int down[1005][1005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> maze[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (maze[i][j] == maze[i][j + 1]) suf[i][j] = suf[i][j + 1] + 1;
      if (maze[i][j] == maze[i + 1][j]) down[i][j] = down[i + 1][j] + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int a = i, b = a + down[i][j] + 1;
      if (b >= n || b + down[b][j] + 1 > n) continue;
      int c = b + down[b][j] + 1, d = c + down[c][j] + 1;
      if (b - a != c - b || c - b > d - c) continue;
      int h = b - a, l = N;
      for (int t = a; t <= a + h * 3 - 1; t++) l = min(l, suf[t][j] + 1);
      ans += l * (l + 1) / 2;
      j = j + l - 1;
    }
  }
  cout << ans << endl;
}
