Under construction

Still being built. Things may change

Tetris

Time limit2sMemory limit128 MB

Summary
Count the number of ways to tile a 3xN grid using square, T, S, Z, L, and J tetrominoes (no straight piece), modulo 1,000,000.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Matrix
Solved
No attempts yet

Problem

You want to fill a 3×N3 \times N rectangle completely with Tetris pieces.

The available pieces are the six tetrominoes shaped like a square, T, S, Z, L, and J. You may use each piece as many times as needed, and each piece may be rotated by 90∘90^\circ, 180∘180^\circ, or 270∘270^\circ. The straight 1×41 \times 4 tetromino is not used.

Pieces must be placed on the grid, must not overlap, and must not extend outside the rectangle. Count the number of possible tilings.

Input

The first line contains a positive integer NN. NN is at most 300300.

Output

Print the number of ways to fill the 3×N3 \times N rectangle with the pieces, modulo 1,000,0001{,}000{,}000.

Examples1

  1. Example 1

    Input
    4
    
    Expected output
    16