Paint grid with color constraints

Write codeHard35 min

Your task

You must paint every cell of a grid that has 3 columns and n rows. Each cell is painted one of three colors (red, yellow, green). No two adjacent cells in the same row may share a color, and no two vertically adjacent cells (same column, consecutive rows) may share a color. Return the number of ways to paint the whole grid, modulo 1000000007. n is between 1 and 5000.

Examples

num_ways_paint(n: int) -> int
Example 1
Inputnum_ways_paint(1)
Output12