def func(strings_list):
the_all_big = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J')
D = {i: {j: 0 for j in the_all_big} for i in range(1, 12 + 1)}
G = {i: 0 for i in the_all_big}
result, h = 0, set(i[0] for i in strings_list)
for each_string in strings_list:
for i, a in enumerate(reversed(each_string), 1):
D[i][a] += 1
for i in range(1, 12 + 1):
for a, j in D[i].items():
if i 0: G[a] += j * 10 ** (i - 1)
sorted_result = sorted(G.iteritems(), key=lambda k: k[1])
for i in range(0, 10):
if i == 0:
for j in range(0, 10):
if sorted_result[j][0] not in h:
sorted_result.pop(j)
break
else:
result += i * sorted_result[i - 1][1]
return result
if __name__ == '__main__':
while True:
try:
strings_list = [raw_input() for i in range(int(raw_input()))]
print func(strings_list)
except:
break