O Canada

Each move flips a 2x2 block of an N x N red/white grid. Count pairs of given grids that can reach each other by such moves.

Medium6Bit manipulationHash mapMathMatrixNo attempts yetTime limit1sMemory limit512 MB

Problem

In this problem a grid is an N×NN \times N array of cells, and each cell is either red or white.

Grid AA is similar to grid BB if and only if AA can be turned into BB by some sequence of changes. One change picks a 2×22 \times 2 square in the grid and flips the colour of all four cells inside it. Red cells in the square become white, and white cells in the square become red.

You are given GG grids. Count the pairs of grids that are similar. Number the grids from 11 to GG, then count the pairs (i,j)(i, j) with 1i<jG1 \le i < j \le G such that grid ii and grid jj are similar.

Input

The first line contains the grid size NN (2N102 \le N \le 10). The second line contains the number of grids GG (2G100002 \le G \le 10000). The next N×GN \times G lines each contain NN characters, and each character is R or W, giving the colour of that cell. R is red and W is white. After the first two lines, the next NN lines describe the first grid, the following NN lines describe the second grid, and so on.

Output

Print the number of pairs of grids that are similar.