favorite We need a little bit of your help to keep things running, click on this banner to learn more
Competitions

# Encoded Sum

You are given a set of strings, each element of which represents a positive integer written using the letters 'A' through 'J' instead of digits. You know that each letter represents exactly one digit, and each digit is represented by exactly one letter. You also know that none of the integers start with zero. Find the maximum possible sum of the given integers.

#### Input

Consists of multiple test cases. The first line of each test case contains the number of strings n (1n50). Then goes n strings of length no more than 12 that contains only the letters 'A' through 'J'. There will be always at least one letter between 'A' and 'J', inclusive, that never occurs as the first character of any input string.

#### Output

For each test case print in a separate line the maximum possible sum of the given integers.

Time limit 1 second
Memory limit 128 MiB
Input example #1
2
ABC
BCA
1
ABCDEFGHIJ

Output example #1
1875
9876543210