Under construction

Still being built. Things may change

Ciphertext

Interview

Time limit1sMemory limit1024 MB

Summary
Given a sorted key of K digits, list every 0/1 mask of positions where exactly X distinct positions have digits summing to Z.
Level

Medium4 of 10

Topics
Backtracking, Brute force
Solved
No attempts yet

Problem

Ivica studies cryptography, the science of encrypting messages so that only the intended recipient can read them. He found a method that turns a chosen digit Z into a record (the ciphertext) made of K zeros and ones. First, a key is chosen. The key is a sequence of K digits sorted in non-decreasing order. The digits do not have to be distinct. For example, when K=5, "01248", "12345", and "00122" are possible keys.

If the digit Z can be written as a sum of X digits that appear in the key, then the ciphertext gets a "1" at position i (counting from the left) when the i-th digit of the key (counting from the left) is one of the digits used in the sum. Otherwise the ciphertext gets a "0" at that position. If there are several possible ciphertexts for Z, all of them must be printed. Each digit of the key can be used in the sum at most once.

For example, let Z=8, K=5, X=2, and the chosen key be "01236". The required ciphertext is "00101", because 8 can be written as a sum of two digits from the key in only one way (2+6=8, "01236" gives "00101").

Write a program that, given the digit Z, the numbers K and X, and a key of length K, finds and prints the ciphertext or ciphertexts of Z as described above. The given digit can always be encrypted.

Input

The first line contains the natural number K (1 ≤ K ≤ 20), the length of the key.

The second line contains the key, a sequence of K digits.

The third line contains the natural number X (1 ≤ X ≤ K).

The fourth line contains the digit Z (0 ≤ Z ≤ 9).

Output

Print every ciphertext of the digit Z, one per line. The order of the output does not matter.

Hint

In the first test, "01247": 1+4=5, so the ciphertext is 01010.

In the second test, "001234": 0+2+4 gives 100101, 0+2+4 (using the other 0) gives 010101, and 1+2+3 gives 001110.

Examples3

  1. Example 1

    Input
    5
    01247
    2
    5
    
    Expected output
    01010
    
  2. Example 2

    Input
    6
    001234
    3
    6
    
    Expected output
    100101
    010101
    001110
    
  3. Example 3

    Input
    5
    01236
    2
    8
    
    Expected output
    00101