Word Math
InterviewTime limit2sMemory limit256 MB
Assign distinct digits 0-9 to letters so that the sum of several words, read as base-10 numbers, is as large as possible.
Problem
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.
Input
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.
Output
Print the maximum possible sum of the given words.