This page is still under construction.

Parts of this page are still being built. What you see may change.

Tetris 2

Time limit2sMemory limit256 MB

Summary
Count the ways to tile a 3 by N rectangle with the six tetrominoes except the straight piece, modulo 1,000,000.
Level

Medium7 of 10

Topics
Dynamic programming, Matrix
Solved
No attempts yet

Problem

Count the ways to cover a 3×N3 \times N rectangle completely with tetris pieces.

A tetris piece is four unit squares joined edge to edge, and there are seven of them. This problem does not use the 1×41 \times 4 piece whose four squares sit in a single line. The remaining six pieces are:

O      T      S      Z      J      L

##     ###    .##    ##.    #..    ..#
##     .#.    ##.    .##    ###    ###

A # is a square the piece covers and a . is empty. You can rotate a piece by 9090, 180180, or 270270 degrees before placing it. You can use the same piece any number of times. Pieces must not overlap and must not stick out of the rectangle. Two coverings are different when the rectangle is split into pieces differently.

Input

The first line contains a natural number NN (1≤N≤1 000 0001 \le N \le 1\,000\,000).

Output

Print the number of ways to cover the 3×N3 \times N rectangle, modulo 1 000 0001\,000\,000.

Examples3

  1. Example 1

    Input
    4
    
    Expected output
    16
    
  2. Example 2

    Input
    1
    
    Expected output
    0
    
  3. Example 3

    Input
    8
    
    Expected output
    388