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 Fortran (gfortran v4.8.4) (judge verdict: Accepted)

program equilateral
  implicit none
  integer :: h, w, a(0:600,0:600) = 0, i, j, k, d
  integer :: x(0:600,0:600) = 0, y(0:600,0:600) = 0
  integer(8) :: ans = 0_8
  character(300) :: s
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      if (s(j:j) == "#") a(i+j-1,i-j+w) = 1
    end do
  end do
  do i = 1, h+w
    do j = 1, h+w
      x(i,j) = x(i,j-1)+a(i,j)
      y(i,j) = y(i-1,j)+a(i,j)
    end do
  end do
  do i = 0, h+w
    do j = 0, h+w
      do k = j+1, h+w
        d = k-j
        if (a(i,j)*a(i,k) == 1) then
          if (i-d >= 0) ans = ans+int(x(i-d,k)-x(i-d,j-1)-a(i-d,k)-a(i-d,j),8)
          if (i+d <= h+w) ans = ans+int(x(i+d,k)-x(i+d,j-1)-a(i+d,k)-a(i+d,j),8)
        end if
        if (a(j,i)*a(k,i) == 1) then
          if (i-d >= 0) ans = ans+int(y(k,i-d)-y(j-1,i-d),8)
          if (i+d <= h+w) ans = ans+int(y(k,i+d)-y(j-1,i+d),8)
        end if
      end do
    end do
  end do
  write(*,'(i0)') ans
  stop
end program equilateral