#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int N = 2e3 + 10;
vector<vector<int> > dp1(N, vector<int>(N, 1));
vector<vector<int> > dp2(N, vector<int>(N, 1));
vector<vector<int> > dp3(N, vector<int>(N, 1));
vector<vector<int> > dp4(N, vector<int>(N, 1));
vector<vector<int> > board(N, vector<int>(N, -1));
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  ;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    s = "#" + s;
    ;
    for (int j = 1; j <= m; j++) board[i][j] = s[j] - '0';
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((board[i][j] == board[i][j - 1]) && (board[i][j] == board[i - 1][j]))
        dp1[i][j] = 1 + min(dp1[i][j - 1], dp1[i - 1][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      if ((board[i][j] == board[i][j + 1]) && (board[i][j] == board[i - 1][j]))
        dp2[i][j] = 1 + min(dp2[i][j + 1], dp2[i - 1][j]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if ((board[i][j] == board[i][j + 1]) && (board[i][j] == board[i + 1][j]))
        dp3[i][j] = 1 + min(dp3[i][j + 1], dp3[i + 1][j]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      if ((board[i][j] == board[i][j - 1]) && (board[i][j] == board[i + 1][j]))
        dp4[i][j] = 1 + min(dp4[i][j - 1], dp4[i + 1][j]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      ans += min({dp1[i][j], dp2[i][j], dp3[i][j], dp4[i][j]});
  cout << ans;
  return 0;
}
