This page is still under construction.

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

Seongsipdang

Interview

Time limit3sMemory limit1024 MB

Summary
List all 2^N binary strings of length N, starting from a given string, so that the total number of matching positions between consecutive strings is minimized.
Level

Medium6 of 10

Topics
Bit manipulation, Greedy, Math, Combinatorics
Solved
No attempts yet

Problem

Suhyeon recently opened a bakery called . Every day it bakes and sells bread that is crunchier on the outside than a cracker and moist enough to be soft on the inside, and it soon became a popular bakery that even turned into a must-visit spot for Instagram bread tours, but unfortunately the tightened distancing rules have sharply reduced the number of customers.

Following the times, Seongsipdang began taking delivery orders. Each loaf of bread contains NN ingredients, and each ingredient has two variations, so one of the two can be chosen. For example, the dough can be either wheat flour or whole wheat flour, and the syrup can be either maple syrup or strawberry syrup. Therefore 2N2^N kinds of bread can be made. As if on cue, on the first day of delivery, 2N2^N orders came in, and every ordered bread was of a different kind.

Even Suhyeon, however skilled at baking, could not handle 2N2^N orders. Fortunately, the employees of Seongsipdang can each quickly prepare one kind of ingredient, so if several employees each prepare a different ingredient at the same time, time can be saved. Therefore Suhyeon wants to reorder the orders so that the following expression is minimized.

∑i=12N−1\displaystyle\sum_{i=1}^{2^N-1} (the number of ingredient kinds shared by the ii-th order and the i+1i + 1-th order)

However, the bread of the customer who ordered first is to be made first. Given NN and the first customer's order, tell us in what order the orders should be processed so that the expression above is minimized.

Input

The input is given as follows.

NN

p1p_1

Output

Print the 2N2^N orders, starting with p1p_1, one per line. Each order is printed as a string of length NN in the same way as the input format, where the ii-th character is the kind of the ii-th ingredient.

If several orderings satisfy the condition, print any one of them.

Constraints

  • NN is the number of ingredients in Seongsipdang bread. (1≤N≤201 \leq N \leq 20)
  • p1p_1 is the string representing the first order. The ii-th character is the kind of the ii-th ingredient, and to save bandwidth on the delivery order system, one variation is written as 0 and the other as 1. (∣c0∣=N\left|c_0\right|=N)

Examples2

  1. Example 1

    Input
    1
    0
    
    Expected output
    0
    1
    
  2. Example 2

    Input
    2
    00
    
    Expected output
    00
    11
    10
    01