#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 100;
char a[N][N];
long long sum[N][N];
long long n, m, ans;
long long f(long long c, long long r) {
  long long l = 1;
  for (long long i = r + 1; i <= n && a[i][c] == a[r][c]; i++, l++)
    ;
  if (r <= l || r + 2 * l - 1 > n) return 0;
  for (long long i = r - 1; i >= r - l; i--)
    if (a[i][c] != a[r - 1][c]) return 0;
  for (long long i = r + l; i < r + 2 * l; i++)
    if (a[i][c] != a[r + l][c]) return 0;
  long long res = N;
  for (long long i = r - l; i < r + 2 * l; i++) res = min(res, sum[i][c]);
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  for (long long i = 1; i <= n; i++)
    for (long long j = m; j > 0; j--)
      sum[i][j] = 1 + (a[i][j] == a[i][j + 1] ? sum[i][j + 1] : 0);
  for (long long j = 1; j <= m; j++)
    for (long long i = 1; i <= n; i++)
      if (a[i][j] != a[i - 1][j]) ans += f(j, i);
  return cout << ans, 0;
}
