Under construction

Still being built. Things may change

Harmonics with Interference

Time limit1sMemory limit1024 MB

Summary
Fill the * bits of M' and N' with 0 or 1 so that the binary value of M is divisible by the binary value of N.
Level

Medium6 of 10

Topics
Dynamic programming, Number theory, Brute force
Solved
No attempts yet

Problem

Transmitting messages by electromagnetic means presents several challenges, such as interference from other natural or artificial signals that can corrupt a transmission.

A common strategy is to send additional information so that a received message can be validated. Some more robust protocols can even correct some errors in the sent message.

Arthur and Bruna are testing a new transmission protocol on a device they have developed. A message MM, which is a sequence of bits, is sent from Arthur to Bruna, along with a control sequence NN, also a sequence of bits. By composing the message MM and choosing the bits of NN, Arthur ensures that the integer encoded by MM is divisible by the integer represented by NN.

For each bit received by Bruna, if the bit was transmitted without problems, the value 0 or 1 is stored in the receiving device. If there was any interference, the symbol * is stored in place of the bit. The result of the transmission is stored in the pair (M′,N′)(M', N').

After the communication, if the message was sent successfully, Bruna can decode the original message MM (since M=M′M = M'). If there was a problem, the protocol may still allow decoding. If many bits were lost, Bruna discards the message. But for transmissions where at most 1616 bits of the original pair (M,N)(M, N) were lost, Bruna wants to recover the message without asking for a retransmission. She needs your help to recover one of the possible messages encoded by the received pair (M′,N′)(M', N').

For example, suppose Bruna received M′=M'=111* and N′=N'=1*. Two transmissions could have been made.

  1. M=M=1111 with N=N=11. In this case, MM and NN represent 15 and 3.
  2. M=M=1110 with N=N=10. In this case, MM and NN represent 14 and 2.

Given the received information, find a message MM that Arthur could have sent. If more than one message is possible, you may print any of them.

Input

The first line contains the sequence of characters representing M′M', with 1≤∣M′∣≤5001 \le |M'| \le 500. The second line contains the sequence of characters representing N′N', with 1≤∣N′∣≤161 \le |N'| \le 16. Every character in M′M' and N′N' is 0, 1, or *. The input contains at most 16 * characters in total. N′N' always contains at least one bit 11.

Output

Print a single line containing a message MM that is compatible with the information Bruna received.

Examples2

  1. Example 1

    Input
    111*
    1*
    
    Expected output
    1111
    
  2. Example 2

    Input
    101**
    11
    
    Expected output
    10101