CF332E Binary Key
Description
Let's assume that $ p $ and $ q $ are strings of positive length, called the container and the key correspondingly, string $ q $ only consists of characters 0 and 1. Let's take a look at a simple algorithm that extracts message $ s $ from the given container $ p $ :
`
i = 0;
j = 0;
s = ;
while i is less than the length of the string p
{
if q[j] == 1, then add to the right of string s character p[i];
increase variables i, j by one;
if the value of the variable j equals the length of the string q, then j = 0;
}
`In the given pseudocode $ i $ , $ j $ are integer variables, $ s $ is a string, '=' is an assignment operator, '==' is a comparison operation, '\[\]' is the operation of obtaining the string character with the preset index, '' is an empty string. We suppose that in all strings the characters are numbered starting from zero. We understand that implementing such algorithm is quite easy, so your task is going to be slightly different. You need to construct the lexicographically minimum key of length $ k $ , such that when it is used, the algorithm given above extracts message $ s $ from container $ p $ (otherwise find out that such key doesn't exist).
i = 0;
j = 0;
s = ;
while i is less than the length of the string p
{
if q[j] == 1, then add to the right of string s character p[i];
increase variables i, j by one;
if the value of the variable j equals the length of the string q, then j = 0;
}
`In the given pseudocode $ i $ , $ j $ are integer variables, $ s $ is a string, '=' is an assignment operator, '==' is a comparison operation, '\[\]' is the operation of obtaining the string character with the preset index, '' is an empty string. We suppose that in all strings the characters are numbered starting from zero. We understand that implementing such algorithm is quite easy, so your task is going to be slightly different. You need to construct the lexicographically minimum key of length $ k $ , such that when it is used, the algorithm given above extracts message $ s $ from container $ p $ (otherwise find out that such key doesn't exist).
Input Format
The first two lines of the input are non-empty strings $ p $ and $ s $ ( $ 1
Output Format
Print the required key (string of length $ k $ , consisting only of characters 0 and 1). If the key doesn't exist, print the single character 0.
Explanation/Hint
String $ x=x_{1}x_{2}...\ x_{p} $ is lexicographically smaller than string $ y=y_{1}y_{2}...\ y_{q} $ , if either $ p<q $ and $ x_{1}=y_{1},x_{2}=y_{2},...\ ,x_{p}=y_{p} $ , or there exists such integer $ r $ ( $ 0