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: Accepted)

#include <iostream>
using namespace std;

int H,W;
char S[310][310],T[710][710];
int R[710][710] = {{0}},C[710][710] = {{0}};

int main(){
	cin >> H >> W;
	for(int i=0;i<=709;i++){
		for(int j=1;j<=709;j++){
			T[i][j] = '.';
		}
	}
	for(int i=1;i<=H;i++){//適当に回転
		for(int j=1;j<=W;j++){
			cin >> S[i][j];
			T[i-j+350][i+j] = S[i][j];
		}
	}
	for(int i=1;i<=700;i++){
		for(int j=1;j<=700;j++){
			if(T[i][j]=='#'){
				C[i][j]++; R[i][j]++;
			}
		}
	}
	for(int i=1;i<=700;i++){//横の累積和
		for(int j=1;j<=700;j++){
			C[i][j] += C[i][j-1];
		}
	}
	for(int i=1;i<=700;i++){//縦の累積和
		for(int j=1;j<=700;j++){
			R[i][j] += R[i-1][j];
		}
	}
	int ans = 0;
	for(int i=1;i<=700;i++){//横の#のペアの計算
		for(int j=1;j<700;j++){
			if(T[i][j]=='.') continue;
			for(int k=j+1;k<=700;k++){
				if(T[i][k]=='#'){
					int d = k-j;
					if(i-d>=0) ans += C[i-d][k-1]-C[i-d][j-1];
					if(i+d<=700) ans += C[i+d][k]-C[i+d][j];
				}
			}
		}
	}
	for(int j=1;j<=700;j++){//縦の#のペアの計算
		for(int i=1;i<700;i++){
			if(T[i][j]=='.') continue;
			for(int k=i+1;k<=700;k++){
				if(T[k][j]=='#'){
					int d = k-i;
					if(j-d>=0) ans += R[k][j-d]-R[i][j-d];
					if(j+d<=700) ans += R[k-1][j+d]-R[i-1][j+d];
				}
			}
		}
	}
	cout << ans << endl;
}