You are given a character matrix of size
.
Let’s call a matrix
beautiful if and only if
and
.
Let’s call a matrix’s beauty the number of beautiful submatrices in it.
Your task is to calculate the beauty of the given character matrix.
A submatrix of a matrix is formed by selecting some contiguous rows and columns in the matrix and forming a new matrix by using those entries in the same relative positions.
Please pay attention to the the time complexity of the program.
The first line contains two integers
and
(
) — the size of the given matrix.
Then there are
lines, each line contains a string of lowercase English characters with length
— the matrix.
Output a single integer — the beauty of the given matrix.