#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (int) (a); i < (int) (b); ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fi first
#define se second
#define ALL(c) (c).begin(),(c).end()
#ifndef DEBUG
#define endl (char)10
#endif
using namespace std;
using ll = long long;
using ld = long double;
typedef vector<vector<char> > vvc;
typedef vector<vector<ll> > vvll;

void printc(vvc a){
	FOR(i,0,a.size()){
		FOR(j,0,a[i].size()){
			cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}
}
void printll(vvll a){
	FOR(i,0,a.size()){
		FOR(j,0,a[i].size()){
			cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}
}
vvc rot(vvc a){
	int n = a.size();
	int m = a[0].size();
	vvc res(m, vector<char>(n));
	FOR(i,0,m) FOR(j,0,n) res[i][j] = a[n - j - 1][i];
	return res;
}


vvll pref(vvc & a){
	vvll res(a.size());
	FOR(i,0,a.size()){
		res[i].clear();
		FOR(j,0,a[i].size()){
			if(i==0) res[i].pb(1);
			else res[i].pb((a[i][j]==a[i-1][j]) ? res[i-1][j]+1 : 1ll);
		}
	}
	return res;
}

ll ans(vvc & a, vvll & pref){
	vvll dp(a.size());
	dp[0].clear();
	FOR(j,0,a[0].size()) dp[0].pb(0);
	FOR(i,1,a.size()){
		dp[i].clear();
		FOR(j,0,a[i].size()-1){
			ll res = min(pref[i][j]-1,dp[i-1][j+1]+1);
			if(a[i][j]==a[i-1][j+1]){
				dp[i].pb(res);
			}else{
				dp[i].pb(0);
			}
		}
		dp[i].pb(0);
	}
	ll sum =0;
	FOR(i,0,a.size()){
		FOR(j,0,dp[i].size()){
			sum+=dp[i][j];
		}
	}
	//printll(dp);
	return sum;
}


int main (){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	vvc a(n);
	char tmp;
	FOR(i,0,n){
		FOR(j,0,m){
			cin>>tmp;
			a[i].pb(tmp);
		}
	}
	ll res=0;
	FOR(z,0,4){
		vvll cnt = pref(a);
		//printc(a);
		//printll(cnt);
		//cout<<"\n\n\n";
		res += ans(a, cnt);
		a = rot(a);
	}
	cout<<res<<"\n";
}


