In the game of Scrabble you are given a number of tiles with letters on them. The challenge is to create a word using some (or all) of these tiles. Write a program which, with the help of a dictionary, determines the longest word you can make with the given letters. Those of you who know this game may note that we ignore the board upon which the letters are placed, as well as the value of the letters.
The input file consists of:
The words in the dictionary are given in alphabetical order.
Per test case:
6 algorithm balloon bapc code submit utrecht 5 abcdeop abcdeoq chuttep chutter iamhotgirl
bapc code IMPOSSIBLE utrecht algorithm