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 Rust (1.15.1) (judge verdict: Accepted)

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//


fn run() {
    input! {
        h: usize,
        w: usize,
        s: [chars; h],
    }
    let mut b = vec![vec!['.'; h + w]; h + w];
    for i in 0..h {
        for j in 0..w {
            b[i + j][j - i + h - 1] = s[i][j];
        }
    }
    let mut row = vec![vec![0; h + w]; h + w];
    let mut col = vec![vec![0; h + w]; h + w];
    for i in 0..(h + w) {
        for j in 0..(h + w) {
            if b[i][j] == '#' {
                row[i][j] = 1;
                col[i][j] = 1;
            }
        }
    }
    for i in 0..(h + w) {
        for j in (0..(h + w - 1)).rev() {
            row[i][j] += row[i][j + 1];
        }
    }
    for i in (0..(h + w - 1)).rev() {
        for j in 0..(h + w) {
            col[i][j] += col[i + 1][j];
        }
    }
    let mut ans = 0u64;
    for i in 0..(h + w) {
        for j in 0..(h + w) {
            if b[i][j] == '.' {
                continue;
            }
            for k in (j + 1)..(h + w) {
                if b[i][k] == '.' {
                    continue;
                }
                let d = k - j;
                if i + d < h + w {
                    ans += row[i + d][j] - row[i + d][k + 1];
                }
                if i >= d {
                    ans += row[i - d][j] - row[i - d][k + 1];
                }
            }
        }
    }
    for j in 0..(h + w) {
        for i in 0..(h + w) {
            if b[i][j] == '.' {
                continue;
            }
            for k in (i + 1)..(h + w) {
                if b[k][j] == '.' {
                    continue;
                }
                let d = k - i;
                if j + d < h + w {
                    ans += col[i + 1][j + d] - col[k][j + d];
                }
                if j >= d {
                    ans += col[i + 1][j - d] - col[k][j - d];
                }
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}