Time limit
2s
Memory limit
256 MB
Assign a distinct decimal digit from 0 to 9 to each different uppercase letter. The same letter must always use the same digit, and no two different letters may use the same digit.
After replacing the letters, each word is interpreted as a base-10 number. Choose the digit assignment that maximizes the sum of all given words, and output that maximum sum.
The first line contains the number of words N (1 <= N <= 10).
Each of the next N lines contains one word. Every word consists only of uppercase English letters. Across all words, at most 10 different letters appear, and each word has length at most 8. Different letters represent different digits.
Print the maximum possible sum of the given words.