#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxm = 2e3 + 10;
const int inf = 0x3f3f3f3f;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
  return 1;
}
inline bool read(char &x) {
  while ((x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                           (iS == iT ? EOF : *iS++))
                        : *iS++)) == ' ' ||
         x == '\n' || x == '\r')
    ;
  return x != EOF;
}
inline bool read(char *x) {
  while ((*x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                            (iS == iT ? EOF : *iS++))
                         : *iS++)) == '\n' ||
         *x == ' ' || *x == '\r')
    ;
  if (*x == EOF) return 0;
  while (!(*x == '\n' || *x == ' ' || *x == '\r' || *x == EOF))
    *(++x) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                          (iS == iT ? EOF : *iS++))
                       : *iS++);
  *x = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &x, B &...y) {
  return read(x) && read(y...);
}
template <typename A>
inline bool write(A x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char x) {
  putc(x);
  return 0;
}
inline bool write(const char *x) {
  while (*x) {
    putc(*x);
    ++x;
  }
  return 0;
}
inline bool write(char *x) {
  while (*x) {
    putc(*x);
    ++x;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A x, B... y) {
  return write(x) || write(y...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
int top[maxm][maxm], down[maxm][maxm];
int last[30];
char s[maxm][maxm];
char t[maxm];
int main() {
  int n, m;
  read(n, m);
  for (int i = 1; i <= n; i++) {
    read(t + 1);
    for (int j = 1; j <= m; j++) s[i][j] = t[j];
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 0; i < 26; i++) last[i] = inf;
    for (int i = 1; i <= n; i++) {
      for (int k = 0; k < 26; k++) {
        if (k == s[i][j] - 'a') continue;
        last[k] = inf;
      }
      last[s[i][j] - 'a'] = min(last[s[i][j] - 'a'], i);
      top[i][j] = last[s[i][j] - 'a'];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 0; i < 26; i++) last[i] = 0;
    for (int i = n; i; i--) {
      for (int k = 0; k < 26; k++) {
        if (k == s[i][j] - 'a') continue;
        last[k] = 0;
      }
      last[s[i][j] - 'a'] = max(last[s[i][j] - 'a'], i);
      down[i][j] = last[s[i][j] - 'a'];
    }
  }
  for (int i = 1; i <= n; i++) {
    top[i][0] = i + 1;
    down[i][0] = i - 1;
    top[i][m + 1] = i + 1;
    down[i][m + 1] = i - 1;
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == s[i][j - 1]) {
        top[i][j] = max(top[i][j], top[i][j - 1] - 1);
        down[i][j] = min(down[i][j], down[i][j - 1] + 1);
      } else {
        top[i][j] = max(top[i][j], i);
        down[i][j] = min(down[i][j], i);
      }
    }
    for (int j = m; j; j--) {
      if (s[i][j] == s[i][j + 1]) {
        top[i][j] = max(top[i][j], top[i][j + 1] - 1);
        down[i][j] = min(down[i][j], down[i][j + 1] + 1);
      } else {
        top[i][j] = max(top[i][j], i);
        down[i][j] = min(down[i][j], i);
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans += min(i - top[i][j] + 1, down[i][j] - i + 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
