Coloring a Rectangle 2
Time limit1sMemory limit512 MB
Count binary colorings of an N by M grid, N up to 1e18 and M at most 5, with no 2x2 block of a single color, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Matrix, Combinatorics, Bit manipulation
- Solved
- No attempts yet
Problem
You are given an rectangle divided into unit squares. Write a program to count the ways to color it so that the following conditions hold.
- Every cell must be colored either black or white.
- There must be no square whose four cells are all the same color.

A valid coloring when ,

An invalid coloring when ,
Given and , find the number of valid colorings of the rectangle, modulo .
Input
The first line contains () and ().
Output
Print the number of valid colorings of the rectangle modulo on the first line.