#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
#define ll long long
#define ld long double
#define base 31
#define mod 1000000007
#define M 100005
#define zero(x) memset(x,0,sizeof(x))
#define oo INT_MAX
#define fo(i,n) for(i=0;i<n;i++)
#define foo(i,n) for(i=1;i<=n;i++)
#define fa(i,I,n) for(i=I;i<n;i++)
int n,m,t,sum[105][105],tmp[105];
char ma[105][105];
int inter(int a,int b){
if(a<0||b<0)return 0;
return sum[a][b];
}
int suma(int a,int b,int c,int d){
return inter(c,d)-inter(c,b-1)-inter(a-1,d)+inter(a-1,b-1);
}
int main(){
while(1){
ll sol=0;
scanf("%d",&n);
if(!n)break;
scanf("%d",&m);
zero(sum);
for(int i=0;i<n;i++)scanf("%s",ma[i]);
sum[0][0]=(ma[0][0]=='1'?1:0);
for(int i=1;i<m;i++)sum[0][i]=sum[0][i-1]+(ma[0][i]=='1'?1:0);
for(int i=1;i<n;i++){
tmp[0]=(ma[i][0]=='1'?1:0);
sum[i][0]=sum[i-1][0]+tmp[0];
for(int j=1;j<m;j++){
tmp[j]=tmp[j-1]+(ma[i][j]=='1'?1:0);
sum[i][j]=sum[i-1][j]+tmp[j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
for(int k=j;k<m;k++){
int a=i,b=n,p=(b+a)/2;
while(b-a>1){
if(suma(i,j,p-1,k)==(k-j+1)*(p-i)){
a=p;
}else{
b=p;
}
p=(b+a)/2;
}
if(suma(i,j,b-1,k)==(k-j+1)*(b-i))p=b;
if(suma(i,j,p-1,k)==(k-j+1)*(p-i)&&p>i){
sol++;
if(p-i>1)sol+=p-i-1;
}
}
}
}
printf("%lld\n",sol);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBkb3VibGUgRVBTID0gMWUtODsKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIGJhc2UgMzEKI2RlZmluZSBtb2QgMTAwMDAwMDAwNwojZGVmaW5lIE0gMTAwMDA1CiNkZWZpbmUgemVybyh4KSBtZW1zZXQoeCwwLHNpemVvZih4KSkKI2RlZmluZSBvbyBJTlRfTUFYCiNkZWZpbmUgZm8oaSxuKSBmb3IoaT0wO2k8bjtpKyspCiNkZWZpbmUgZm9vKGksbikgZm9yKGk9MTtpPD1uO2krKykKI2RlZmluZSBmYShpLEksbikgZm9yKGk9STtpPG47aSsrKQppbnQgbixtLHQsc3VtWzEwNV1bMTA1XSx0bXBbMTA1XTsKY2hhciBtYVsxMDVdWzEwNV07CmludCBpbnRlcihpbnQgYSxpbnQgYil7CiAgICBpZihhPDB8fGI8MClyZXR1cm4gMDsKICAgIHJldHVybiBzdW1bYV1bYl07Cn0KaW50IHN1bWEoaW50IGEsaW50IGIsaW50IGMsaW50IGQpewogICAgcmV0dXJuIGludGVyKGMsZCktaW50ZXIoYyxiLTEpLWludGVyKGEtMSxkKStpbnRlcihhLTEsYi0xKTsKfQppbnQgbWFpbigpewogICAgd2hpbGUoMSl7CiAgICAgICAgbGwgc29sPTA7CiAgICAgICAgc2NhbmYoIiVkIiwmbik7CiAgICAgICAgaWYoIW4pYnJlYWs7CiAgICAgICAgc2NhbmYoIiVkIiwmbSk7CiAgICAgICAgemVybyhzdW0pOwogICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspc2NhbmYoIiVzIixtYVtpXSk7CiAgICAgICAgc3VtWzBdWzBdPShtYVswXVswXT09JzEnPzE6MCk7CiAgICAgICAgZm9yKGludCBpPTE7aTxtO2krKylzdW1bMF1baV09c3VtWzBdW2ktMV0rKG1hWzBdW2ldPT0nMSc/MTowKTsKICAgICAgICBmb3IoaW50IGk9MTtpPG47aSsrKXsKICAgICAgICAgICAgdG1wWzBdPShtYVtpXVswXT09JzEnPzE6MCk7CiAgICAgICAgICAgIHN1bVtpXVswXT1zdW1baS0xXVswXSt0bXBbMF07CiAgICAgICAgICAgIGZvcihpbnQgaj0xO2o8bTtqKyspewogICAgICAgICAgICAgICAgdG1wW2pdPXRtcFtqLTFdKyhtYVtpXVtqXT09JzEnPzE6MCk7CiAgICAgICAgICAgICAgICBzdW1baV1bal09c3VtW2ktMV1bal0rdG1wW2pdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICAgICAgICBmb3IoaW50IGo9MDtqPG07aisrKXsKICAgICAgICAgICAgICAgIGZvcihpbnQgaz1qO2s8bTtrKyspewogICAgICAgICAgICAgICAgICAgIGludCBhPWksYj1uLHA9KGIrYSkvMjsKICAgICAgICAgICAgICAgICAgICB3aGlsZShiLWE+MSl7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKHN1bWEoaSxqLHAtMSxrKT09KGstaisxKSoocC1pKSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhPXA7CiAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgICAgICAgICAgICAgYj1wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIHA9KGIrYSkvMjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYoc3VtYShpLGosYi0xLGspPT0oay1qKzEpKihiLWkpKXA9YjsKICAgICAgICAgICAgICAgICAgICBpZihzdW1hKGksaixwLTEsayk9PShrLWorMSkqKHAtaSkmJnA+aSl7CiAgICAgICAgICAgICAgICAgICAgICAgIHNvbCsrOwogICAgICAgICAgICAgICAgICAgICAgICBpZihwLWk+MSlzb2wrPXAtaS0xOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwcmludGYoIiVsbGRcbiIsc29sKTsKICAgIH0KICAgIHJldHVybiAwOwp9