https://www.acmicpc.net/problem/1339
n = int(input())
alpha = []
word = {}
for _ in range(n):
alpha.append(input().rstrip('\n'))
for i in alpha:
x = len(i)-1
for j in i:
if j in word:
word[j] += 10 ** x
else:
word[j] = 10 ** x
x -= 1
alphaSort = sorted(word.values(), reverse=True)
res = 0
num = 9
for i in alphaSort:
res += i * num
num -= 1
print(res)