ПОДНИЗ
InterviewTime limit1sMemory limit1024 MB
Find the longest string that can appear as a substring of some permutation of a and of some permutation of b, breaking ties by lexicographic order.
Problem
You are given two strings and made of lowercase Latin letters. Write a program substring that finds the longest string which is both a substring of some permutation of and a substring of some permutation of .
By a "permutation of a string" we mean a string of the same length that contains the characters of the original string in some order.
By a "substring of a string" we mean a string made of a nonzero number of consecutive characters of the given string.
Input
The standard input contains the two strings, each on a separate line. The maximum length of each string is 1000 characters.
Output
On the single line of the standard output, print the sought string. If more than one string of maximum length satisfies the condition, print the lexicographically smallest one.
Hint
The given string is a substring of the permutation uamntu of and of the permutation ornamntuet of .