Problem:
Score : 700 points

Problem Statement

There are some coins in the xy-plane.
The positions of the coins are represented by a grid of characters with H rows and W columns.
If the character at the i-th row and j-th column, s_{ij}, is #, there is one coin at point (i,j); if that character is ., there is no coin at point (i,j). There are no other coins in the xy-plane.

There is no coin at point (x,y) where 1\leq i\leq H,1\leq j\leq W does not hold.
There is also no coin at point (x,y) where x or y (or both) is not an integer.
Additionally, two or more coins never exist at the same point.

Find the number of triples of different coins that satisfy the following condition:

Choosing any two of the three coins would result in the same Manhattan distance between the points where they exist.

Here, the Manhattan distance between points (x,y) and (x',y') is |x-x'|+|y-y'|.
Two triples are considered the same if the only difference between them is the order of the coins.

Constraints

1 \leq H,W \leq 300

s_{ij} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{11}...s_{1W}
:
s_{H1}...s_{HW}

Output

Print the number of triples that satisfy the condition.

Sample Input 1

5 4
#.##
.##.
#...
..##
...#

Sample Output 1

3

((1,1),(1,3),(2,2)),((1,1),(2,2),(3,1)) and ((1,3),(3,1),(4,4)) satisfy the condition.

Sample Input 2

13 27
......#.........#.......#..
#############...#.....###..
..............#####...##...
...#######......#...#######
...#.....#.....###...#...#.
...#######....#.#.#.#.###.#
..............#.#.#...#.#..
#############.#.#.#...###..
#...........#...#...#######
#..#######..#...#...#.....#
#..#.....#..#...#...#.###.#
#..#######..#...#...#.#.#.#
#..........##...#...#.#####

Sample Output 2

870

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <algorithm>
using namespace std;
int N,M,F[2][305][305];
char A[305][305];
long long Ans;
inline int LU(int x,int y,int k){
	if (k<1) return 0;
	k+=min(0,min(x-k,y-k));
	return F[0][x][y]-F[0][x-k][y-k];
}
inline int RU(int x,int y,int k){
	if (k<1) return 0;
	k+=max(0,min(x-k,y+k-M-1));
	return F[1][x][y]-F[1][x-k][y+k];
}
inline int Calc(int x_1,int y_1,int x_2,int y_2){
	if (x_2<x_1) swap(x_1,x_2),swap(y_1,y_2);
	if (y_1<=y_2){
		int z=max(x_2-N,y_2-M);
		if (z>0) x_2-=z,y_2-=z;
		if (x_2<1||y_2<1) return 0;
		return LU(x_2,y_2,x_2-x_1+1);
	}
	if (y_1>=y_2){
		int z=max(x_2-N,1-y_2);
		if (z>0) x_2-=z,y_2+=z;
		if (x_2<1||y_2>M) return 0;
		return RU(x_2,y_2,x_2-x_1+1);
	}
}
int main(){
	scanf("%d%d",&N,&M);
	for (int i=1;i<=N;++i) scanf("%s",A[i]+1);
	for (int i=1;i<=N;++i)
		for (int j=1;j<=M;++j) F[0][i][j]=F[0][i-1][j-1]+(A[i][j]=='#'),F[1][i][j]=F[1][i-1][j+1]+(A[i][j]=='#');
	int KS=min(N,M);
	for (int i=1;i<=N;++i)
		for (int j=1;j<=M;++j)
			for (int k=KS;k;--k){
				if (i>k&&j>k&&A[i-k][j]=='#'&&A[i][j-k]=='#') Ans+=Calc(i-k,j-2*k,i-2*k+1,j-k-1);
				if (i+k<=N&&j+k<=M&&A[i+k][j]=='#'&&A[i][j+k]=='#') Ans+=Calc(i+k,j+2*k,i+2*k-1,j+k+1);
				if (i>k&&j+k<=M&&A[i-k][j]=='#'&&A[i][j+k]=='#') Ans+=Calc(i-2*k,j+k,i-k-1,j+2*k-1);
				if (i+k<=N&&j>k&&A[i+k][j]=='#'&&A[i][j-k]=='#') Ans+=Calc(i+2*k,j-k,i+k+1,j-2*k+1);
			}
	printf("%lld\n",Ans);
	return 0;
}