In this problem a grid is an N×N array of cells, and each cell is either red or white.
Grid A is similar to grid B if and only if A can be turned into B by some sequence of changes. One change picks a 2×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 G grids. Count the pairs of grids that are similar. Number the grids from 1 to G, then count the pairs (i,j) with 1≤i<j≤G such that grid i and grid j are similar.