#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=998244353;
#define INF 1e9+7
#define N 310000
#define MAX_V 400010
#define vec vector<int>
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};
main(){
    int h,w;
    cin>>h>>w;
    int s[2000][2000]={};
    rep(i,h)rep(j,w){
        char c;cin>>c;
        if(c=='.')s[i][j]=0;
        else s[i][j]=1;
    }
    ll ans=0;
    int t[2000][2000]={};

    rep(i,h)rep(j,w)t[i+j][j]+=s[i][j];
    rep(i,h+w)rep(j,h+w)t[i][j+1]+=t[i][j];
    rep(i,h+w-2){
        if(i<h){
            rep(j,min(w,i+1)){
                rep2(k,j+1,min(w-1,i)){
                    if(s[i-j][j]&&s[i-k][k]){
                        int d=k-j;
                        ans+=t[i+(k-j)*2][j+2*d]-t[i+(k-j)*2][k-1];
                        if(i-2*d>=0){ans+=t[i-(k-j)*2][j];
                        if(k-2*d>=0)ans-=t[i-(k-j)*2][k-2*d-1];
                        }
                        if(i-j-2*d>=0)ans-=s[i-j-2*d][j];
                        if(k-2*d>=0)ans-=s[i-k][k-2*d];
                        ans-=s[i-j][j+2*d];
                        ans-=s[i-k+2*d][k];
                    }
                }
            }
        }
        else{
            rep(j,min(w+h-i-1,h)){
                rep2(k,j+1,min(w+h-i-2,h-1)){
                    if(s[h-1-j][i+1-h+j]&&s[h-1-k][i+1-h+k]){
                        int d=k-j;
                        ans+=t[i+(k-j)*2][i+1-h+j+2*d]-t[i+(k-j)*2][i+1-h+k-1];
                        if(i-2*d>=0){
                            ans+=t[i-d*2][i+1-h+j];
                            if(i+1-h+k-2*d>=0) ans-=t[i-d*2][i+1-h+k-2*d-1];
                        }
                        if(h-1-j-2*d>=0)ans-=s[h-1-j-2*d][i+1-h+j];
                        if(i+1-h+k-2*d>=0)ans-=s[h-1-k][i+1-h+k-2*d];
                        ans-=s[h-1-j][i+1-h+j+2*d];
                        ans-=s[h-1-k+2*d][i+1-h+k];
                    }
                }
            }
        }
    }
    rep(i,h)rep(j,w/2)swap(s[i][j],s[i][w-1-j]);
    rep(i,700)rep(j,700)t[i][j]=0;
    rep(i,h)rep(j,w)t[i+j][j]+=s[i][j];
    rep(i,h+w)rep(j,h+w)t[i][j+1]+=t[i][j];
    rep(i,h+w-2){
        if(i<h){
            rep(j,min(w,i+1)){
                rep2(k,j+1,min(w-1,i)){
                    if(s[i-j][j]&&s[i-k][k]){
                        int d=k-j;
                        ans+=t[i+(k-j)*2][j+2*d]-t[i+(k-j)*2][k-1];
                        if(i-2*d>=0){ans+=t[i-(k-j)*2][j];
                        if(k-2*d>=0)ans-=t[i-(k-j)*2][k-2*d-1];
                        }
                    }
                }
            }
        }
        else{
            rep(j,min(w+h-i-1,h)){
                rep2(k,j+1,min(w+h-i-2,h-1)){
                    if(s[h-1-j][i+1-h+j]&&s[h-1-k][i+1-h+k]){
                        int d=k-j;
                        ans+=t[i+(k-j)*2][i+1-h+j+2*d]-t[i+(k-j)*2][i+1-h+k-1];
                        if(i-2*d>=0){
                            ans+=t[i-d*2][i+1-h+j];
                            if(i+1-h+k-2*d>=0) ans-=t[i-d*2][i+1-h+k-2*d-1];
                        }
                    }
                }
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 31488