Under construction

Still being built. Things may change

Equilateral Triangles

Time limit2sMemory limit512 MB

Summary
Given an N by N grid of cows, count triples of cows that are pairwise equidistant under Manhattan distance, with N up to 300.
Level

Medium6 of 10

Topics
Math, Hash map, Implementation
Solved
No attempts yet

Problem

Farmer John's pasture is an N×NN\times N square grid (1≤N≤300)(1\le N\le 300) with positions (i,j)(i,j) for all 1≤i,j≤N1\le i,j\le N. A cell contains '*' if a single cow stands at that position, and '.' if no cow is there.

FJ believes the beauty of his pasture is directly proportional to the number of triples of cows whose positions are equidistant from each other, that is, triples that form an equilateral triangle. All cows are at integer coordinates, so no such triple can exist under Euclidean distance. FJ therefore switches to Manhattan distance. The Manhattan distance between (x0,y0)(x_0,y_0) and (x1,y1)(x_1,y_1) is ∣x0−x1∣+∣y0−y1∣|x_0-x_1|+|y_0-y_1|.

Given the grid, count the equilateral triples.

Input

The first line contains a single integer NN. For each 1≤i≤N1\le i\le N, line i+1i+1 contains a string of length NN made of the characters '*' and '.'. The jjth character describes whether there is a cow at position (i,j)(i,j).

Output

Output a single integer, the answer. The answer fits into a signed 32-bit integer.

Hint

There are three cows, and they form an equilateral triple because the Manhattan distance between each pair of cows is equal to two.

Examples1

  1. Example 1

    Input
    3
    *..
    .*.
    *..
    
    Expected output
    1