#d1406. “Z”型矩阵

“Z”型矩阵

"Z" Matrix

Problem Description

For a matrix containing only . and z, it is called a Z matrix when all of the following hold:

  1. The matrix has equal numbers of rows and columns.
  2. The first row and the last row are entirely z.
  3. The diagonal from the top-right corner to the bottom-left corner is entirely z.

Now given an n×mn \times m matrix, count how many of its submatrices are Z matrices.

Input Format

The first line contains two integers n,mn, m, the number of rows and columns of the matrix respectively (1≤n,m≤3×1031 \le n, m \le 3 \times 10^3).

The next nn lines each contain mm characters, describing the matrix.

Output Format

Output one integer: the number of Z matrices.

Sample Input

4 4
zzzz
z.z.
.zz.
zzzz

Sample Output

14