Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int H, W, N, sum[605][605], ans; char str[305];
vector<int> r[605], c[605];

inline int calcr(int x, const int &l, const int &r){
	if(l > r || x < 1 || x > N) return 0;
	return sum[x][r] - sum[x - 1][r] - sum[x][l - 1] + sum[x - 1][l - 1];
}

inline int calcc(const int &d, const int &u, int y){
	if(d > u || y < 1 || y > N) return 0;
	return sum[u][y] - sum[u][y - 1] - sum[d - 1][y] + sum[d - 1][y - 1];
}

int main(){
	getint(H), getint(W), N = H + W;
	for(register int i = 1; i <= H; i++){
		scanf("%s", str + 1);
		for(register int j = 1; j <= W; j++) if(str[j] == '#'){
			sum[i + j][i - j + W]++;
			r[i + j].push_back(i - j + W);
			c[i - j + W].push_back(i + j);
		}
	}
	for(register int i = 1; i <= N; i++)
		for(register int j = 1; j <= N; j++)
			sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
	for(register int i = 1; i <= N; i++){
		sort(r[i].begin(), r[i].end());
		for(register int j = 0, siz = r[i].size(); j < siz; j++)
			for(register int k = j + 1; k < siz; k++){
				const int d = r[i][k] - r[i][j];
				ans += calcr(i - d, r[i][j], r[i][k]);
				ans += calcr(i + d, r[i][j], r[i][k]);
			}
		sort(c[i].begin(), c[i].end());
		for(register int j = 0, siz = c[i].size(); j < siz; j++)
			for(register int k = j + 1; k < siz; k++){
				const int d = c[i][k] - c[i][j];
				ans += calcc(c[i][j] + 1, c[i][k] - 1, i - d);
				ans += calcc(c[i][j] + 1, c[i][k] - 1, i + d);
			}
	}
	return printf("%d\n", ans), 0;
}

Compiler output:
a.cc: In function 'void getint(Tp&)':
a.cc:10:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |         register int ch, neg = 0;
      |                      ^~
a.cc:10:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |         register int ch, neg = 0;
      |                          ^~~
a.cc: At global scope:
a.cc:18:1: error: 'vector' does not name a type
   18 | vector<int> r[605], c[605];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:32:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         for(register int i = 1; i <= H; i++){
      |                          ^
a.cc:34:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |                 for(register int j = 1; j <= W; j++) if(str[j] == '#'){
      |                                  ^
a.cc:36:25: error: 'r' was not declared in this scope
   36 |                         r[i + j].push_back(i - j + W);
      |                         ^
a.cc:37:25: error: 'c' was not declared in this scope
   37 |                         c[i - j + W].push_back(i + j);
      |                         ^
a.cc:40:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |         for(register int i = 1; i <= N; i++)
      |                          ^
a.cc:41:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |                 for(register int j = 1; j <= N; j++)
      |                                  ^
a.cc:43:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         for(register int i = 1; i <= N; i++){
      |                          ^
a.cc:44:22: error: 'r' was not declared in this scope
   44 |                 sort(r[i].begin(), r[i].end());
      |                      ^
a.cc:45:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |                 for(register int j = 0, siz = r[i].size(); j < siz; j++)
      |                                  ^
a.cc:45:41: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |                 for(register int j = 0, siz = r[i].size(); j < siz; j++)
      |                                         ^~~
a.cc:46:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |                         for(register int k = j + 1; k < siz; k++){
      |                                          ^
a.cc:51:22: error: 'c' was not declared in this scope
   51 |                 sort(c[i].begin(), c[i].end());
      |                      ^
a.cc:52:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   52 |                 for(register int j = 0, siz = c[i].size(); j < siz; j++)
      |                                  ^
a.cc:52:41: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   52 |                 for(register int j = 0, siz = c[i].size(); j < siz; j++)
      |                                         ^~~
a.cc:53:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   53 |                         for(register int k = j + 1; k < siz; k++){
      |                                          ^
a.cc: In instantiation of 'void getint(Tp&) [with Tp = int]':
a.cc:31:8:   required from here
   31 |         getint(H), getint(W), N = H + W;
      |         ~~~~~~^~~
a.cc:10:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |         register int ch, neg = 0;
      |                      ^~
a.cc:10:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |         register int ch, neg = 0;
      |                          ^~~