Hexagonal Tiles

Interview

Time limit1sMemory limit128 MB

Summary
Count the sequences of increasing tile numbers from the start tile to tile N, where each move goes forward by 1 or 2.
Level

Medium4 of 10

Topics
Dynamic programming, Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

Mary's route to school is a straight strip paved with hexagonal tiles.

The tiles are laid out in an offset, brick-like pattern, so every tile shares an edge with the two tiles that come immediately after it. At the very front of the strip there is a special tile marked with a smiling face; the remaining tiles are numbered 1,2,3,…1, 2, 3, \dots consecutively in ascending order.

On her way to school Mary steps from tile to tile following these rules:

  • She always starts on the smiling-face tile, which sits before tile 11 and touches both tile 11 and tile 22.
  • She may never step onto a tile whose number is smaller than the tile she is standing on, so the numbers she steps on strictly increase.
  • Each step must go to a neighboring tile. Because of the layout, from the tile numbered kk she can move forward only to tile k+1k+1 or tile k+2k+2.
  • She must finish on the highest-numbered tile.

A step sequence is the ordered list of numbered tiles she steps on. Mary never wants to repeat a sequence, and she wonders: for a strip with NN numbered tiles (plus the smiling-face tile), how many days would it take to walk every possible sequence exactly once, one sequence per day?

For instance, with N=4N = 4 tiles there are five possible sequences: 1-2-3-4, 1-2-4, 1-3-4, 2-3-4, and 2-4.

Given NN, determine how many different step sequences exist.

Input

The input consists of several test cases. Each test case is a single line containing one integer NN (1≤N≤401 \le N \le 40), the number of numbered tiles on the strip.

The list of test cases ends with a line containing a single 00, which must not be processed.

Output

For each test case, print a single line containing one integer: the number of different step sequences for a strip with NN numbered tiles.

Examples1

  1. Example 1

    Input
    1
    4
    2
    10
    0
    
    Expected output
    1
    5
    2
    89