You are on page 1of 1

Always Take the Lightest Word

You are given two types of command:


1 word: put the given word into storage.
2: withdraw the lexicographically lightest word from the storage, and output it. If
nothing in the storage, output “###”

Input
A number of lines (1,000,000). Each contains one command specified above. All
words in the command are in lower case and without space in int. There may be
multiple instances of the same word in the storage.

Output
Upon receiving command of 2, output the lexicographically lightest word from the
storage.

Sample Input
2
1 one
1 two
1 three
1 four
2
2
1 five
2
2
2
2

Sample Output
###
four
one
five
three
two
###

You might also like