#include <bits/stdc++.h>
using namespace std;
char arr[1005][10];
struct mak {
  char ch;
  long long val = 0;
};
long long sv[10] = {1, 10, 100, 1000, 10000, 100000, 1000000};
mak p[15];
map<char, long long> m;
bool compare(mak a, mak b) { return a.val > b.val; }
int main() {
  long long tst, a, b, n, res = 0, ans = 0;
  for (long long i = 0; i < 10; i++) {
    p[i].ch = 97 + i;
    p[i].val = 0;
  }
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%s", arr[i]);
    long long ln = strlen(arr[i]);
    char c[10];
    strcpy(c, arr[i]);
    m[c[0]] = 1;
    reverse(c, c + ln);
    long long x = 1;
    for (long long j = 0; j < ln; j++) {
      for (long long k = 0; k < 10; k++) {
        if (p[k].ch == c[j]) {
          p[k].val += (sv[x++]);
        }
      }
    }
  }
  sort(p, p + 10, compare);
  long long maxi = 1;
  bool flag = 0;
  for (long long i = 0; i < 10; i++) {
    if (m[p[i].ch] == 0 && !flag) {
      p[i].val = 0;
      flag = 1;
    } else {
      p[i].val = maxi;
      maxi++;
    }
  }
  for (long long i = 0; i < n; i++) {
    char c[10];
    strcpy(c, arr[i]);
    long long ln = strlen(c);
    long long temp = 0;
    long long t = 1;
    for (long long j = ln; j >= 0; j--) {
      for (long long k = 0; k < 10; k++) {
        if (c[j] == p[k].ch) {
          temp += (p[k].val * t);
          t *= 10;
          break;
        }
      }
    }
    res += temp;
  }
  printf("%lld\n", res);
  return 0;
}
