p:array[1..200,1..200] of char;
i,j,k,m,n,max,u:integer;
t:longint;
function can(i,j,k:integer):boolean;
var m:integer;
begin
can:=true;
for m:=j-k to j+1 do
if p[i-k,m]<>p[i+1,m] then begin can:=false; exit; end;
for m:=i-k to i+1 do
if p[m,j-k]<>p[m,j+1] then begin can:=false; exit; end;
end;
function can2(i,j:integer):boolean;
begin
can2:=true;
if (p[i-1,j-1]<>p[i,j-1]) or (p[i-1,j-1]<>p[i-1,j])
or (p[i-1,j-1]<>p[i,j]) or (p[i,j-1]<>p[i,j])
or(p[i,j-1]<>p[i-1,j]) or (p[i-1,j]<>p[i,j]) then can2:=false;
end;
begin
readln(m,n);
for i:=1 to m do
begin
for j:=1 to n do read(p[i,j]);
readln;
end;
if m>n then max:=n else max:=m;
fillchar(f,sizeof(f),0);
fillchar(b,sizeof(b),0);
for i:=1 to m do
for j:=1 to n do begin f[i,j,1]:=true; b[i,j,1]:=true; end;
for i:=2 to m do
for j:=2 to n do begin
f[i,j,2]:=can2(i,j);
b[i,j,2]:=true;
if not(b[i,j,2]) then begin
for u:=1 to ((max-2) div 2) do
begin
if ((i-2-2*u)>0) and ((j-2-2*u)>0)
and ((i+u)<=n) and ((j+u)<=n) then
begin
f[i+u,j+u,2+2*u]:=false;
b[i+u,j+u,2+2*u]:=true;
end;
end;
end;
end;
for k:=1 to max-2 do
begin
for i:=1 to m do
for j:=1 to n do
begin
if ((i-k)>0) and ((j-k)>0) and ((i+1)<=n) and ((j+1)<=n)
and f[i,j,k] and (not(b[i+1,j+1,k+2])) then begin
f[i+1,j+1,k+2]:=can(i,j,k);
b[i+1,j+1,k+2]:=true;
if not(f[i+1,j+1,k+2]) then begin
for u:=2 to ((max-k) div 2) do
begin
if ((i-k-2*u)>0) and ((j-k-2*u)>0)
and ((i+u)<=n) and ((j+u)<=n) then
begin
f[i+u,j+u,k+2*u]:=false;
b[i+u,j+u,k+2*u]:=true;
end;
end;
end;
end;
end;
end;
for k:=1 to max do
for i:=1 to m do
for j:=1 to n do if f[i,j,k] then inc(t);
write(t);
end.