#pragma GCC optimize ("-Ofast")
#pragma GCC optimize ("-unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
const int nmax=2010;
using B=bitset<nmax>;
char buf[nmax][nmax];
int dif[nmax][nmax];
bool ok[nmax];
B sm[nmax];
vector<int> qs[nmax];
int main(){
int n,m;
scanf("%d%d",&n,&m);
rep(i,n)scanf("%s",buf[i]);
rep(j,m)dif[n-1][j]=n;
per(i,n-1)rep(j,m)if(buf[i][j]==buf[i+1][j])dif[i][j]=dif[i+1][j];
else dif[i][j]=i+1;
rep(i,n)rep(j,m-1)if(buf[i][j]!=buf[i][j+1])
sm[i].flip(j);
ll ans=0;
rep(i1,n){
rep(j,m)ok[j]=1;
rep(j,m)if(dif[i1][j]<n)qs[dif[i1][j]].pb(j);
rng(i2,i1+1,n){
B adj=sm[i1]|sm[i2];
for(auto j:qs[i2])ok[j]=false;
qs[i2].clear();
int cur=0,tot=0;
rep(j,m){
if(ok[j]){tot+=cur;cur+=1;}
if(adj[j])cur=0;
}
ans+=tot;
}
}
printf("%lld\n",ans);
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUgKCItT2Zhc3QiKQojcHJhZ21hIEdDQyBvcHRpbWl6ZSAoIi11bnJvbGwtbG9vcHMiKQoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp1c2luZyBsbD1sb25nIGxvbmc7CgojZGVmaW5lIHJuZyhpLGEsYikgZm9yKGludCBpPWludChhKTtpPGludChiKTtpKyspCiNkZWZpbmUgcmVwKGksYikgcm5nKGksMCxiKQojZGVmaW5lIGducihpLGEsYikgZm9yKGludCBpPWludChiKS0xO2k+PWludChhKTtpLS0pCiNkZWZpbmUgcGVyKGksYikgZ25yKGksM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