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 PyPy3 (2.4.0) (judge verdict: Accepted)

H,W=map(int,input().split())
S=[input() for i in range(H)]
table=[[0]*(H+W-1) for i in range(H+W-1)]
for j in range(H):
    for i in range(W):
        table[i+j][i-j+H-1]=S[j][i]
yoko=[[0]*(H+W) for i in range(H+W-1)]
for j in range(H+W-1):
    for i in range(1,H+W):
        if table[j][i-1]=='#':
            yoko[j][i]=yoko[j][i-1]+1
        else:
            yoko[j][i]=yoko[j][i-1]
tate=[[0]*(H+W-1) for i in range(H+W)]
for j in range(1,H+W):
    for i in range(H+W-1):
        if table[j-1][i]=='#':
            tate[j][i]=tate[j-1][i]+1
        else:
            tate[j][i]=tate[j-1][i]

ans=0
for y in range(H+W-1):
    for x in range((y+H-1)%2,H+W-1,2):
        if table[y][x]!='#':
            continue
        for z in range(x+2,H+W-1,2):
            if table[y][z]=='#':
                d=z-x
                if y+d<H+W-1:
                    ans+=yoko[y+d][z+1]-yoko[y+d][x]
                    #print(1,'.',ans,':',x,y,z)
                if y-d>=0:
                    ans+=yoko[y-d][z+1]-yoko[y-d][x]
                    #print(2,'.',ans,':',x,y,z)
        for w in range(y+2,H+W-1,2):
            if table[w][x]=='#':
                e=w-y
                if x+e<H+W-1:
                    ans+=tate[w][x+e]-tate[y+1][x+e]
                    #print(3,'.',ans,':',x,y,w)
                if x-e>=0:
                    ans+=tate[w][x-e]-tate[y+1][x-e]
                    #print(4,'.',ans,':',x,y,w)

print(ans)