Under construction

Still being built. Things may change

Blocks for Kids

Time limit5sMemory limit1024 MB

Summary
Count the ways to cut a 2xN Pango board into two tileable boards at some point k, modulo 10007, for up to 300 values of N up to 1e9.
Level

Medium7 of 10

Topics
Dynamic programming, Math, Matrix
Solved
No attempts yet

Problem

Wango is a brilliant maths teacher. He has two sons, Kango and Dango, born two years apart on the same day. Kango is 9 and Dango is 7. Their birthdays are approaching again. Wango wants to buy each son a piece of the Pango board to introduce them to higher mathematics.

A size nn (n≥0n \ge 0) Pango board is a 2×n2 \times n rectangle of unit squares. A Pango board must be tiled completely with Pango pieces. Any tiling is acceptable. A size 0 board exists, is unique, and represents the empty set.

There are four types of Pango pieces. Each type can be used an unlimited number of times. Pieces cannot be rotated.

Wango buys one board of size NN, chooses an integer kk (0≤k≤N0 \le k \le N), and gives a size kk board to Kango and a size N−kN-k board to Dango. Both boards must be tiled completely. Count the number of ways Wango can give the presents. Two ways are distinct if Dango gets a different board or Kango gets a different board. Two boards are the same if they have the same tiling from left to right. Rotating a board is not allowed when comparing.

Input

The input consists of several test cases, one per line. Each line contains one integer NN (0≤N≤10000000000 \le N \le 1000000000), the size of the board Wango buys. The input ends with a line containing -1, which is not processed. There are at most 300 test cases.

Output

For each test case, print one line with the number of ways Wango can distribute the presents, modulo 10007.

Examples1

  1. Example 1

    Input
    0
    1
    2
    -1
    
    Expected output
    1
    4
    16