import sys
input = sys.stdin.readline
N = int(input())
word_list = []
alphabet_dict = {}
alphabet_value = []
answer = 0
for _ in range(N):
word = input().rstrip()
word_list.append(word)
for word in word_list:
for i in range(len(word)):
num = 10 ** (len(word) - i - 1)
try:
alphabet_dict[word[i]] += num
except:
alphabet_dict[word[i]] = num
for value in alphabet_dict.values():
alphabet_value.append(value)
sorted_list = sorted(alphabet_value, reverse=True)
for i in range(len(sorted_list)):
answer += sorted_list[i] * (9 - i)
print(answer)