rows rows and cols columns. Every cell must be painted red, green or blue, and cells that share a side must get different colors.
Return the number of ways to paint the grid. The answer can be huge, so return it modulo 10⁹ + 7.rows=1, cols=3 → 12
The first cell has 3 choices and each next one has 2: 3 · 2 · 2 = 12.
rows=2, cols=2 → 18
The first column can be colored in 6 ways, and each fits exactly 3 choices for the second column: 18.
rows=3, cols=4 → 1122
rows ≤ 5cols ≤ 1000rows=1, cols=3
12
Run checks the first 3 tests in your browser. Submit checks all 64 tests on the server, hidden ones included.