Under construction

Still being built. Things may change

ПОДНИЗ

Interview

Time limit1sMemory limit1024 MB

Summary
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.
Level

Medium5 of 10

Topics
String, Greedy, Sorting, Hash map
Solved
No attempts yet

Problem

You are given two strings aa and bb made of lowercase Latin letters. Write a program substring that finds the longest string which is both a substring of some permutation of aa and a substring of some permutation of bb.

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 aa and of the permutation ornamntuet of bb.

Examples1

  1. Example 1

    Input
    autumn
    tournament
    
    Expected output
    amntu