"""
merging two strings based on occurence of the chars and then 
lexcicographically smallest
"""

s1=input()
s2=input()
i=j=0
ans=''
while(i<len(s1) and j<len(s2)):
    if(s1.count(s1[i]) == s2.count(s2[j])):
        if(s1[i] <= s2[j]):
            ans+=s1[i]
            i+=1
        else:
            ans+=s2[j]
            j+=1
    elif(s1.count(s1[i]) < s2.count(s2[j])):
        ans+=s1[i]
        i+=1
    else:
        ans+=s2[j]
        j+=1
while(i<len(s1)):
    ans+=s1[i]
    i+=1
while(j<len(s2)):
    ans+=s2[j]
    j+=1
print(ans)    

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: