Symmetry
Time limit2sMemory limit1024 MB
Count the subgrids with an even number of columns that are mirror-symmetric across their vertical center line.
Problem
You are given an grid . The cell in row and column contains an uppercase English letter .
A grid is called a symmetric grid if it satisfies all of the following conditions.
- It has at least 1 row and an even number of columns, at least 2.
- When the grid is folded along its exact vertical center line, every pair of characters that touch is the same.
- Specifically, for a grid of size , holds for all with and .
Count the subgrids of that are symmetric grids. A subgrid is formed by choosing consecutive rows and consecutive columns of .
Input
The first line contains two integers and , the number of rows and columns of , separated by a space. ()
Each of the next lines contains with no spaces. is the character in row , column of , and it is one of the uppercase English letters.
Output
Print the number of subgrids of that are symmetric grids.
Hint
This problem is not guaranteed to be solvable with Python3. If you use Python, submit with PyPy3. It has the same syntax as Python3 and usually runs faster.