Harmonics with Interference
Time limit1sMemory limit1024 MB
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 , which is a sequence of bits, is sent from Arthur to Bruna, along with a control sequence , also a sequence of bits. By composing the message and choosing the bits of , Arthur ensures that the integer encoded by is divisible by the integer represented by .
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 .
After the communication, if the message was sent successfully, Bruna can decode the original message (since ). 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 bits of the original pair 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 .
For example, suppose Bruna received 111* and 1*. Two transmissions could have been made.
1111with11. In this case, and represent 15 and 3.1110with10. In this case, and represent 14 and 2.
Given the received information, find a message 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 , with . The second line contains the sequence of characters representing , with . Every character in and is 0, 1, or *. The input contains at most 16 * characters in total. always contains at least one bit .
Output
Print a single line containing a message that is compatible with the information Bruna received.