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 Ruby (2.3.3) (judge verdict: Runtime Error)


#### input

a = []
c = []

ln = gets
nx = ln.match(/([0-9]+)[ ]+([0-9]+)/)
h = nx[1].to_i
w = nx[2].to_i

#print "h:#{h} w:#{w}\n"
#exit

#### set a[], b[]

0.upto(h-1) { |i|
  ln = gets
  x = []
  0.upto(w-1) { |j|
    if ln[j] == "#"
      x << 1
      c << [i,j]
    else
      x << 0
    end
    #sz = ln.size
    #ln = ln.slice(1..(sz-1))
    #print "i:#{i} j:#{j} x:#{x} ln:#{ln}\n"
  }
  a << x
  #print "i:#{i} a:#{a} c:#{c}\n"
}

##

cnt = 0
nc = c.size
0.upto(nc-1) { |i|
  (i+1).upto(nc-1) { |j|
    c1 = c[i]
    c2 = c[j]
    x1 = c1[0]
    y1 = c1[1]
    x2 = c2[0]
    y2 = c2[1]
    if x1 > x2 || x1 == x2 && y1 > y2
      x1,y1,x2,y2 = x2,y2,x1,y1
    end

    if y1 == y2
      next if (x1+x2)%2 > 0
      x3 = (x1+x2)/2
      y3 = y1+(x2-x1)/2
      cnt += 1 if a[x3][y3] > 0

    elsif y2-y1 == x1-x2
      x3 = 2*x1 - x2
      y3 = y2
      while x3 >= x2
        cnt += 1 if a[x3][y3] > 0
        x3 -= 1
        y3 += 1
      end

      elsif y2-y1 == x2-x1
        x3 = x1
        y3 = 2*y2-y1
        while x3 > x1
          cnt += 1 if a[x3][y3] > 0
          x3 -= 1
          y3 -= 1
        end

    elsif x1 > x2 # must be y1<y2
      next if x1-x2 <= y2-y1 || (x1+x2+y1+y2)%2 > 0
      x3 = (x1+x2-y1+y2)/2
      y3 = (x1-x2-y1+3*y2)/2
      cnt += 1 if a[x3][y3] > 0

    elsif x1 < x2 # must be y1<y2
      next if x2-x1 <= y2-y1 || (x1+x2+y1+y2)%2 > 0
      x3 = (x1+x2-y1+y2)/2
      y3 = (x1-x2-y1+3*y2)/2
      cnt += 1 if a[x3][y3] > 0
    end
  }
}

#print "ans:#{ans}\n"
print cnt