This page is still under construction.

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

Sang-geun's Lock

Time limit1sMemory limit128 MB

Summary
Count the number of height-balanced binary trees with N nodes, print the last 9 digits padded to width 9.
Level

Medium6 of 10

Topics
Dynamic programming, Recursion, Combinatorics
Solved
No attempts yet

Problem

A certain lock uses a 9-digit number as its password. When you touch the lock, its LED display shows a single integer NN. The lock opens once you enter the last 9 digits of the number of trees that satisfy the condition below.

Consider binary trees with NN nodes. For every node, the difference between the heights of its left and right subtrees must be at most 11. The height of a subtree is the length of the longest path from that subtree's root down to a leaf. A subtree consisting of a single node has height 00, and an empty subtree (no nodes) has height −1-1.

Count how many distinct tree shapes there are.

Input

The input consists of several test cases. Each test case is a single integer NN with 1≤N≤14271 \le N \le 1427. Input continues until the end of the file.

Output

For each test case, print on its own line the last 9 digits of the number of trees corresponding to the given NN. If the value has fewer than 9 digits, pad it with leading zeros so that exactly 9 digits are printed.

Examples1

  1. Example 1

    Input
    1
    3
    6
    21
    
    Expected output
    000000001
    000000001
    000000004
    000036900