My daughter's alphabet The other day we were writing sentences with my daughter with a fridge magnet letter. While we were able to make some(I love cat), we didn't have enough letters to make the others (I love you too) due to an insufficient amount of letters o (4)

I then found out that while one set included 3 e letters it had only 2 o letters. Probably inspired by http://en.wikipedia.org/wiki/Letter_frequency this would still not reflect the actual situation "on the fridge".

Problem

Given the text file where each line contains a "sample sentence" one would want to write on the fridge, propose an alphabet set with minimum amount of letters but still sufficient to write each sentence individually.

Note: ignore cases, all magnet letters are capitals anyway.

Input

The file contain newline separated sentences:

hello
i love cat
i love dog
i love mommy
mommy loves daddy


Output

Provide back sorted list of letters, where each letter appears only as many times to be sufficient to write any sentence:

acdddeghillmmmoostvyy


(thanks, isaacg!)

Winner

Shortest implementation (code)

UPDATED: Testing

I have created an extra test and tried with various answers here:

https://gist.github.com/romaninsh/11159751
GolfScript, 28 / 34 chars

n/:a{|}*{a{.[2$]--}%*$-1=}%$


The 28-character program above assumes that all the input letters are in the same case.  If this is not necessarily so, we can force them into upper case by prepending {95&amp;}% to the code, for a total of 34 chars:

{95&amp;}%n/:a{|}*{a{.[2$]--}%*$-1=}%$


Notes:


For correct operation, the input must include at least one newline.  This will be true for normal text files with newlines at the end of each line, but might not be true if the input consists of just one line with no trailing newline.  This could be fixed at the cost of two extra chars, by prepending n+ to the code.
The uppercasing used in the 34-character version is really crude &mdash; it maps lowercase ASCII letters to their uppercase equivalents (and spaces to NULs), but makes a complete mess of numbers and most punctuation.  I'm assuming that the input will not include any such characters.
The 28-character version treats all input characters (except newlines and NULs) equally.  In particular, if the input contains any spaces, some will also appear in the output; conveniently, they will sort before any other printable ASCII characters.  The 34-character version, however, does ignore spaces (because it turns out I can do that without it costing me any extra chars).


Explanation:


The optional {95&amp;}% prefix uppercases the input by zeroing out the sixth bit of the ASCII code of each input byte (95 = 64 + 31 = 10111112).  This maps lowercase ASCII letters to uppercase, spaces to null bytes, and leaves newlines unchanged.
n/ splits the input at newlines, and :a assigns the resulting array into the variable a.  Then {|}* computes the set union of the strings in the array, which (assuming that the array has at least two elements) yields a string containing all the unique (non-newline) characters in the input.
The following { }% loop then iterates over each of these unique characters.  Inside the loop body, the inner loop a{.[2$]--}% iterates over the strings in the array a, removing from each string all characters not equal to the one the outer loop is iterating over.

The inner loop leaves the ASCII code of the current character on the stack, below the filtered array.  We make use of this by repeating the filtered array as many times as indicated by the ASCII code (*) before sorting it ($) and taking the last element (-1=).  In effect, this yields the longest string in the filtered array (as they all consist of repeats of the same character, lexicographic sorting just sorts them by length), except if the character has ASCII code zero, in which case it yields nothing.
Finally, the $ at the end just sorts the output alphabetically.