This page is still under construction.

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

Xenospeak

Time limit1sMemory limit128 MB

Summary
Given words per page and a page number, print the first and last words on that page over tilings of a, ab and bb ordered by length then alphabetically.
Level

Medium7 of 10

Topics
Combinatorics, Dynamic programming, String
Solved
No attempts yet

Problem

Bob Roberts is a linguist who studies the language of the alien M'ca. Every word in that language is built by joining the pieces a, ab and bb. The real M'ca characters cannot be printed, so a and b stand in for them here. For example aaabbbbb and aababb are M'ca words, but babb is not, and you would be a laughingstock in any M'ca establishment if you tried to use babb in a sentence. The alphabet is small enough that every string the three pieces can build is a legal word, up to a certain length that does not matter in this problem.

Bob is compiling a dictionary that renders every legal M'ca word into English. The words follow the traditional M'ca ordering. All words of length 1 come first in alphabetical order, then all words of length 2 in alphabetical order, and so on.

Within one dictionary every page holds the same number of words, though that number changes from edition to edition with the page size and the font size. As in any dictionary, the first and the last word of a page are printed at the top of that page so readers can search faster. Given the number of words per page and a page number, report the two words printed at the top of that page.

Input

Each test case is a single line with two positive integers n and m. n is the number of words per page and m is the page number. n≤30n \le 30 and m≤1018m \le 10^{18}.

The last line of input contains 0 0 and is not a test case.

Output

For each test case print Case k: x y on one line, where k is the test case number counted from 1, x is the first word on page m and y is the last word on page m. Separate the three parts with single spaces.

Examples2

  1. Example 1

    Input
    4 2
    9 10
    0 0
    
    Expected output
    Case 1: aaa abb
    Case 2: bbbbaa aaaabab
    
  2. Example 2

    Input
    1 1
    1 2
    1 3
    1 4
    1 5
    0 0
    
    Expected output
    Case 1: a a
    Case 2: aa aa
    Case 3: ab ab
    Case 4: bb bb
    Case 5: aaa aaa