This page is still under construction.

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

Stamps

Time limit1sMemory limit128 MB

Summary
For each h and k with h+k<=9, find k stamp values whose at-most-h sums cover 1..n consecutively for the longest range, then print the lexicographically smallest such set and n.
Level

Medium7 of 10

Topics
Dynamic programming, Brute force, Combinatorics, Greedy
Solved
No attempts yet

Problem

The government of Nova Mareterrania attaches revenue stamps to legal documents so that it can collect income from them. By recent law, each class of document may carry only a limited number of stamps. The government wants to decide how many stamp denominations to print, and of what values, so that the widest possible range of totals can be assembled within that limit. Every stamp is worth a whole number of dollars.

When a document may carry at most hh stamps and kk different denominations are available, let n(h,k)n(h,k) be the largest value NN such that every amount from 11 to NN can be formed using at most hh stamps. A denomination may be used more than once, and there is no limit on how many stamps of each denomination are available (only the total count hh is limited). One denomination is always 11, since otherwise the amount 11 could not be formed.

For example, with h=3h = 3 and k=2k = 2: using denominations 11 and 44 you can form every amount from 11 to 66, but using denominations 11 and 33 you can form every amount from 11 to 77. The second choice is better, so n(3,2)=7n(3, 2) = 7.

Given hh and kk, choose the kk denominations that maximize n(h,k)n(h,k), and report both the chosen denominations and the value n(h,k)n(h,k).

Input

The input consists of several lines. Each line contains two integers hh and kk separated by a space, with h≥1h \ge 1, k≥1k \ge 1, and h+k≤9h + k \le 9.

The input ends with a line containing 0 0, which is not a query and must not be processed.

Output

For each query, print one line: the kk chosen denominations in ascending order, each right-justified in a field 3 characters wide, followed by a space, an arrow ->, and the value n(h,k)n(h,k) right-justified in a field 3 characters wide.

Several different sets of denominations can reach the same maximum n(h,k)n(h,k). When that happens, output the lexicographically smallest such set: compare the two ascending denomination sequences position by position and take the one whose value is smaller at the first position where they differ.

Examples3

  1. Example 1

    Input
    3 2
    0 0
    
    Expected output
      1  3 ->  7
    
  2. Example 2

    Input
    1 1
    0 0
    
    Expected output
      1 ->  1
    
  3. Example 3

    Input
    3 2
    1 1
    0 0
    
    Expected output
      1  3 ->  7
      1 ->  1