The Rabbit's Escape Route

Count self-avoiding walks on a 3 by N grid from the top left cell to the bottom right cell, modulo 1e9+9.

Hard8Dynamic programmingCombinatoricsImplementationBrute forceNo attempts yetTime limit1sMemory limit256 MB

Problem

A fox and a rabbit are on a 3×N3 \times N grid. The rabbit starts at the top left cell and runs for the bottom right cell.

The fox chases the rabbit and drops a trap on every cell the rabbit has already crossed, so the rabbit can never step on the same cell twice. In one move the rabbit goes to a cell that shares a side with its current cell, that is, one step up, down, left, or right.

Count the routes the rabbit can take from the start cell to the goal cell. Two routes are different when the sequence of visited cells differs anywhere.

Input

The first line contains the width NN of the grid. (1N10001 \le N \le 1000)

Output

Print the number of routes on the 3×N3 \times N grid that go from the top left cell to the bottom right cell without visiting any cell twice, modulo 10000000091000000009 (109+910^9 + 9).