#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
namespace IO {
bool REOF = 1;
inline char nc() {
  static char buf[1 << 20], *p1 = buf, *p2 = buf;
  return p1 == p2 && REOF &&
                 (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? (REOF = 0, EOF)
             : *p1++;
}
template <typename T>
inline bool read(T &x) {
  char c = nc();
  bool f = 0;
  x = 0;
  while (c < '0' || c > '9') c == '-' && (f = 1), c = nc();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = nc();
  if (f) x = -x;
  return REOF;
}
template <typename T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
template <typename T, typename... T2>
inline bool read(T &x, T2 &...rest) {
  read(x);
  return read(rest...);
}
inline bool need(char &c) {
  return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) ||
         ((c >= 'A') && (c <= 'Z')) || c == '.' || c == '#';
}
inline bool read_str(char *a) {
  while ((*a = nc()) && need(*a) && REOF) ++a;
  *a = '\0';
  return REOF;
}
inline bool read_db(double &x) {
  bool f = 0;
  char ch = nc();
  x = 0;
  while (ch < '0' || ch > '9') {
    f |= (ch == '-');
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10.0 + (ch ^ 48);
    ch = nc();
  }
  if (ch == '.') {
    double temp = 1;
    ch = nc();
    while (ch >= '0' && ch <= '9') {
      temp = temp / 10.0;
      x = x + temp * (ch ^ 48);
      ch = nc();
    }
  }
  if (f) x = -x;
  return REOF;
}
template <typename TH>
inline void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << '\n';
}
template <typename TH, typename... TA>
inline void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',' << ' ';
  _dbg(sdbg + 1, a...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[ ";
  for (auto vv : V) os << vv << ",";
  return os << " ]";
}
template <typename T>
ostream &operator<<(ostream &os, set<T> V) {
  os << "[ ";
  for (auto vv : V) os << vv << ",";
  return os << " ]";
}
template <typename T>
ostream &operator<<(ostream &os, map<T, T> V) {
  os << "[ ";
  for (auto vv : V) os << vv << ",";
  return os << " ]";
}
template <typename L, typename R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <typename TH>
TH MIN(TH a, TH b) {
  return min(a, b);
}
template <typename TH, typename... TA>
TH MIN(TH a, TA... c) {
  TH b = MIN(c...);
  return min(a, b);
}
template <typename TH>
TH MAX(TH a, TH b) {
  return max(a, b);
}
template <typename TH, typename... TA>
TH MAX(TH a, TA... c) {
  TH b = MIN(c...);
  return max(a, b);
}
}  // namespace IO
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
using namespace IO;
const int N = 5e5 + 5;
const int M = 5e5 + 5;
const int V = 3e7 + 5;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
int n, m;
char s[2005][2005];
int dp1[2005][2005], dp2[2005][2005], dp3[2005][2005], dp4[2005][2005];
void solve(int Case) {
  read(n, m);
  for (int i = (1); i <= (n); ++i) read_str(s[i] + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i][j] == s[i - 1][j] && s[i][j] == s[i][j - 1]) {
        dp1[i][j] = min(dp1[i - 1][j], dp1[i][j - 1]) + 1;
      } else {
        dp1[i][j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = m; j >= 1; --j) {
      if (s[i][j] == s[i - 1][j] && s[i][j] == s[i][j + 1]) {
        dp2[i][j] = min(dp2[i - 1][j], dp2[i][j + 1]) + 1;
      } else {
        dp2[i][j] = 1;
      }
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j - 1]) {
        dp3[i][j] = min(dp3[i + 1][j], dp3[i][j - 1]) + 1;
      } else {
        dp3[i][j] = 1;
      }
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = m; j >= 1; --j) {
      if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j + 1]) {
        dp4[i][j] = min(dp4[i + 1][j], dp4[i][j + 1]) + 1;
      } else {
        dp4[i][j] = 1;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int ma = MIN(dp1[i][j], dp2[i][j], dp3[i][j], dp4[i][j]);
      ans += ma;
    }
  }
  printf("%lld\n", ans);
}
int main() {
  solve(1);
  return 0;
}
