Blocks for Kids
Time limit5sMemory limit1024 MB
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 () Pango board is a 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 , chooses an integer (), and gives a size board to Kango and a size 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 (), 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.