Language: C++

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=303;
string f[N];
short pr[N][N][N],pl[N][N][N];
int n,m;
short g(short x,short y){
    if(1<=x&&x<=n&&1<=y&&y<=m)return f[x][y]=='#';
    return 0;
}
short tl(short x,short y,short d){
    if(x<=0||y<=0)return 0;
    short delta=max(x-n,y-m);
    upx(delta,0);
    return (x<=delta||y<=delta)?0:pl[x-delta][y-delta][d];
}
short tr(short x,short y,short d){
    if(x<=0||y>m)return 0;
    short delta=max(x-n,1-y);
    upx(delta,0);
    return (x<=delta||y+delta>m)?0:pr[x-delta][y+delta][d];
}
short gl(short x1,short y1,short x2,short y2,short d){//x1<x2,y1<y2
    return x2-x1+1<d?0:tl(x2,y2,d)-tl(x1-1+d,y1-1+d,d);
}
short gr(short x1,short y1,short x2,short y2,short d){//x1<x2,y1>y2
    return x2-x1+1<d?0:tr(x2,y2,d)-tr(x1-1+d,y1+1-d,d);
}
int32_t main(){
    cin>>n>>m;
    // n=m=300;
    int s=n+m;
    for(int i=1;i<=n;++i)
        cin>>f[i];
        for(int j=1;j<=m;++j){
            // f[i][j]='#';
            for(int d=0;d+d<=s;d++){
                pl[i][j][d]=pl[i-1][j-1][d]+g(i,j)*g(i-d,j-d);
                pr[i][j][d]=pr[i-1][j+1][d]+g(i,j)*g(i-d,j+d);
            }
        }
    uint ans=0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if(f[i][j]=='#'){
                for(int d=1;d+d<=s;d++){
                    if(g(i-d,j-d)){
                        ans+=gl(i-d-d+1,j+1,i-d,j+d,0);
                        ans+=gl(i+1,j-d-d+1,i+d,j-d,0);
                    }
                    if(g(i+d,j+d)){
                        ans+=gl(i-d,j+d,i-1,j+d+d-1,0);
                        ans+=gl(i+d,j-d,i+d+d-1,j-1,0);
                    }
                    if(g(i-d,j+d)){
                        ans+=gr(i-d-d+1,j-1,i-d-1,j-d+1,0);
                        ans+=gr(i+1,j+d+d-1,i+d-1,j+d+1,0);
                    }
                    if(g(i+d,j-d)){
                        ans+=gr(i-d+1,j-d-1,i-1,j-d-d+1,0);
                        ans+=gr(i+d+1,j+d-1,i+d+d-1,j+1,0);
                    }
                    ans+=gl(i-d-d,j,i,j+d+d,d);
                    ans+=gl(i,j-d-d,i+d+d,j,d);
                    ans+=gr(i-d-d,j,i,j-d-d,d);
                    ans+=gr(i,j+d+d,i+d+d,j,d);
                }
            }
        }
    }
    cout<<ans/3<<'\n';
    return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:56:20: error: 'i' was not declared in this scope
   56 |                 pl[i][j][d]=pl[i-1][j-1][d]+g(i,j)*g(i-d,j-d);
      |                    ^