Buying shares X39187


Statement
 

pdf   zip

html

You have c coins, and you must make n stock transactions. Each transaction involves buying or selling a share. All shares are worth one coin each. You can only buy if you have a coin, and can only sell if you have a share.

Given n and c, print all possible sequences of operations.

Input

Input consists of n and c. Suppose 1 ≤ cn ≤ 16.

Output

Print in alphabetical order all possible sequences of n operations when we start with c coins. Use ‘b’ to buy and ‘s’ to sell.

Public test cases
  • Input

    4 1
    

    Output

    bsbs
    
  • Input

    7 3
    

    Output

    bbbsbsb
    bbbsbss
    bbbssbb
    bbbssbs
    bbbsssb
    bbsbbsb
    bbsbbss
    bbsbsbb
    bbsbsbs
    bbsbssb
    bbssbbb
    bbssbbs
    bbssbsb
    bsbbbsb
    bsbbbss
    bsbbsbb
    bsbbsbs
    bsbbssb
    bsbsbbb
    bsbsbbs
    bsbsbsb
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python