cho.sh
Notes
Loading...

Maximum Sum

Time limit

2s

Memory limit

128 MB

Problem

You are given N numbers. Every number is a positive integer, but its decimal digits have been replaced by the letters A through J. Each letter represents exactly one digit, and each digit is represented by exactly one letter. No number starts with 0. Determine the maximum possible sum of the N numbers.

Input

The first line contains N, a positive integer no greater than 50. Each of the next N lines contains one number. The length of each number is at most 12. At least one letter never appears as the first character of a number.

Output

Print the maximum possible sum.