There is a grid with rows and columns and an unlimited supply of dominoes in each of distinct colors. A domino covers two cells sharing a side and may be placed horizontally or vertically.
Cover every cell without overlap and without extending outside the grid. If any cell covered by one domino shares a side with a cell covered by another domino, those two dominoes must have different colors. Meeting only at a corner imposes no restriction.
Count the ways to choose both the domino placement and the color of every domino, modulo . You need not use all colors. Two ways are different if their placements differ or if any domino in the same position has a different color. Rotations and reflections are counted separately whenever they change the placement or colors on the original grid. Dominoes of the same color are indistinguishable.
The input is given in the following format:
Print the number of valid ways modulo . If there is no valid way, print .
The grid can be covered by two horizontal dominoes or two vertical dominoes. In either placement, the dominoes are adjacent and must use different colors. Thus there are ways.
Nine cells cannot be completely covered by dominoes of two cells each.