#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
char a[N][N];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%s", a + i);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < i; j++)
            swap(a[i][j], a[j][i]);
    long long ans = 0;
    for (int i = 0; i < n; i++)
        for (int l = 1; l <= (n - i) / 3; l++)
            for (int j = 0; j < m; j++)
            {
                bool flag = a[j][i] != a[j][i + l] && a[j][i + l] != a[j][i + l + l];
                for (int t = 0; t < 3; t++)
                    for (int k = 0; k < l && flag; k++)
                        if (a[j][i + l * t] != a[j][i + l * t + k])
                            flag = false;
                int rmost = j;
                while (flag && memcmp(a[j] + i, a[rmost] + i, l * 3) == 0) rmost++;
                if (rmost != j)
                {
                    ans += (rmost - j) * (rmost - j + 1) / 2;
                    j = rmost - 1;
                }
            }
    cout << ans;
    return 0;
}