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: Wrong Answer)

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        h: usize,
        w: usize,
        bd: [chars; h],
    }

    let mut ans = 0;
    for y1 in 0..h {
        for x1 in 0..w {
            if bd[y1][x1] != '#' {
                continue;
            }
            for y2 in 0..h {
                for x2 in 0..w {
                    if (x1, y1) == (x2, y2) || bd[y2][x2] != '#' {
                        continue;
                    }

                    if y1 == y2 {
                        let l = (x2 as i64 - x1 as i64).abs();
                        if l % 2 != 0 {
                            continue;
                        }
                        let x3 = x1 as i64 + l / 2;
                        {
                            let y3 = y1 as i64 + l / 2;
                            if x3 < w as _ && y3 < h as _ && bd[y3 as usize][x3 as usize] == '#' {
                                // println!("{:?} {:?} {:?}", (x1, y1), (x2, y2), (x3, y3));
                                ans += 2;
                            }
                        }
                        {
                            let y3 = y1 as i64 - l / 2;
                            if x3 < w as _ && y3 >= 0 as _ && bd[y3 as usize][x3 as usize] == '#' {
                                // println!("{:?} {:?} {:?}", (x1, y1), (x2, y2), (x3, y3));
                                ans += 2;
                            }
                        }
                    } else if x1 == x2 {
                        let l = (y2 as i64 - y1 as i64).abs();
                        if l % 2 != 0 {
                            continue;
                        }
                        let y3 = y1 as i64 + l / 2;
                        {
                            let x3 = x1 as i64 + l / 2;
                            if x3 < w as _ && y3 < h as _ && bd[y3 as usize][x3 as usize] == '#' {
                                // println!("{:?} {:?} {:?}", (x1, y1), (x2, y2), (x3, y3));
                                ans += 2;
                            }
                        }
                        {
                            let x3 = x1 as i64 - l / 2;
                            if x3 >= 0 as _ && y3 < h as _ && bd[y3 as usize][x3 as usize] == '#' {
                                // println!("{:?} {:?} {:?}", (x1, y1), (x2, y2), (x3, y3));
                                ans += 2;
                            }
                        }
                    } else {
                        // println!("** {:?} {:?}", (x1, y1), (x2, y2));

                        let l = (x1 as i64 - x2 as i64).abs() + (y1 as i64 - y2 as i64).abs();
                        let t = (x1 as i64 - x2 as i64).abs();
                        if l % 2 != 0 {
                            continue;
                        }

                        let u = 3 * l / 2 - t;
                        // println!("** {:?} {:?}, {} {} {}", (x1, y1), (x2, y2), l, u, t);
                        if l <= u {
                            continue;
                        }
                        let y3 = y1 as i64 + t;
                        let x3 = if x1 < x2 {
                            x1 as i64 + l - u
                        } else {
                            x1 as i64 - (l - u)
                        };

                        // println!("** {:?} {:?} {:?}", (x1, y1), (x2, y2), (x3, y3));

                        if x3 >= 0 as _ && y3 < h as _ && bd[y3 as usize][x3 as usize] == '#' {
                            // println!("{:?} {:?} {:?}", (x1, y1), (x2, y2), (x3, y3));
                            ans += 1;
                        }
                    }
                }
            }
        }
    }

    println!("{}", ans / 2);
}