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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int sz;
int solve(vector<int> &A, vector<int> &B, int o) {
	int N = A.size();
	set<pair<int, int> > st;
	vector<vector<int> > Xs(sz);
	int res = 0;
	for (int i = 0; i < N; i++) {
		Xs[A[i] + B[i]].push_back(A[i] - B[i]);
		st.emplace(A[i] + B[i], A[i] - B[i]);
	}
	for (int i = 0; i < Xs.size(); i++) {
		sort(Xs[i].begin(), Xs[i].end());
	}
	int m, x;
	int d;
	for (int i = 0; i < Xs.size(); i++) {
		for (int j = 0; j < Xs[i].size(); j++) {
			for (int k = 0; k < j; k++) {
				m = (Xs[i][j] - Xs[i][k]);
				for (int t = -1; t <= 1; t += 2) {
					x = i + t*m;
					if (x >= 0 && x < Xs.size()) {
						
						res += upper_bound(Xs[x].begin(), Xs[x].end(), Xs[i][j] - o)
							- lower_bound(Xs[x].begin(), Xs[x].end(), Xs[i][k] + o);
					/*	d = upper_bound(Xs[x].begin(), Xs[x].end(), Xs[i][j] - o)
							- lower_bound(Xs[x].begin(), Xs[x].end(), Xs[i][k] + o);
						if (d > 0) {
							cerr << (i + Xs[i][j]) / 2 << " " << (i - Xs[i][j]) / 2 << endl;
							cerr << (i + Xs[i][k]) / 2 << " " << (i - Xs[i][k]) / 2 << endl;
						}*/
					}
				}
			}
		}
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	sz = H + W - 1;
	vector<string> S(H);
	int res = 0;
	vector<int> X;
	vector<int> Y;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				X.push_back(i);
				Y.push_back(j);
			}
		}
	}
	res = solve(X, Y, 0);
	//cerr << res << endl;
	for (int i = 0; i < X.size(); i++)(X[i] = H - 1 - X[i]);
	res += solve(X, Y, 1);
	cout << res << endl;
}