This page is still under construction.

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

Filling a 4 × n Rectangle with Dominoes

Time limit1sMemory limit128 MB

Summary
Count the tilings of a 4 by n board with dominoes and print the count modulo 1000 without leading zeros.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

You have 2n2n dominoes of width 1 and length 2, where nn is an integer smaller than 10001000. These dominoes can be arranged without overlap so that they exactly cover a 4×n4 \times n rectangle. Figure 1 covers a 4×64 \times 6 rectangle with 12 dominoes.

Figure 1: an example with n=6n = 6.

For n>1n > 1 there is more than one arrangement. Figure 2 shows all 5 ways of covering a 4×24 \times 2 rectangle.

Figure 2: the 5 ways of covering a 4×24 \times 2 rectangle.

Let RnR_n be the number of different ways to cover a 4×n4 \times n rectangle with 2n2n dominoes. Figure 2 gives R2=5R_2 = 5. Even for small nn the value of RnR_n becomes very large, so what you report is its last three digits, that is RnR_n modulo 10001000.

Input

One integer nn on a single line. Remember that n<1000n < 1000.

Output

Print RnR_n modulo 10001000 on one line, without leading zeros. For example R17=26915305R_{17} = 26915305, so n=17n = 17 gives 305305, and R2=5R_2 = 5, so n=2n = 2 gives 55 and not 005005. When the remainder is zero, print a single 00.

Examples2

  1. Example 1

    Input
    2
    
    Expected output
    5
    
  2. Example 2

    Input
    17
    
    Expected output
    305