#include <bits/stdc++.h>
const int p10[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int N, S[10], can_be_zero[10], L, p[10], fill[10], O;
char a[7];
int main() {
  for (int i = 0; i < 10; i++) can_be_zero[i] = 1;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", a);
    L = 0;
    while (a[L]) L++;
    can_be_zero[a[0] - 'a'] = 0;
    for (int i = 0; i < L; i++) S[a[i] - 'a'] += p10[L - 1 - i];
  }
  for (int i = 0; i < 10; i++) p[i] = i;
  std::sort(p, p + 10, [](int x, int y) { return S[x] > S[y]; });
  for (int i = 0; i < 10; i++) fill[i] = -1;
  for (int i = 0; i < 10; i++)
    if (can_be_zero[p[i]]) {
      fill[p[i]] = 0;
      break;
    }
  for (int i = 0, u = 1; i < 10; i++)
    if (fill[p[i]] == -1) fill[p[i]] = u++;
  for (int i = 0; i < 10; i++) O += fill[i] * S[i];
  printf("%d\n", O);
  return 0;
}
