Block stacking
Time limit2sMemory limit512 MB
Count structures built on one 1x1xw base block using unlimited 1x1x1, 1x1x2, and 1x1x3 blocks with height at most h, where long blocks need both ends supported.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Yeongseon can use as many blocks of size , , and as she wants. She also has one block of size , which is called the base block.

Yeongseon builds a structure from one base block and the other blocks. Every block must be connected to the base block, and no block can be placed at a non-integer position. A long block ( or ) must have both of its ends resting on other blocks. For a block, the cell under its middle part may be empty.
The picture on the left is a valid structure. The picture on the right cannot be built.


The height of a structure is the number of layers stacked on top of the base block. The structure with no block at all has height , and it counts as one structure.
Given the length of the base block and the height limit , write a program that counts the structures of height at most that can be built from one base block and an unlimited number of the other blocks.
The picture below shows all 84 structures for and .

Input
The first line contains and , separated by a space. ()
Output
Print the number of structures modulo on the first line.