#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
const int maxm = 20;
int n;
char str[maxn][10];
int num[30];
struct node {
  int id;
  bool lead;
  int cnt[maxm];
  bool operator<(const node &rhs) const {
    for (int i = maxm - 1; i >= 0; i--)
      if (cnt[i] != rhs.cnt[i]) return cnt[i] < rhs.cnt[i];
    return 0;
  }
} a[30];
void init() {
  for (int i = 0; i < 26; i++) {
    a[i].id = i;
    a[i].lead = 0;
    memset(a[i].cnt, 0, sizeof(a[i].cnt));
  }
}
void solve() {
  int k = 9;
  for (int i = 0; i < 10; i++) num[a[i].id] = k--;
  k = 9;
  while (k && a[k].lead) {
    swap(num[a[k].id], num[a[k - 1].id]);
    k--;
  }
  long long ans = 0, sum;
  int sz;
  for (int i = 0; i < n; i++) {
    sz = strlen(str[i]);
    sum = 0;
    for (int k = 0; k < sz; k++) sum = sum * 10 + num[str[i][k] - 'a'];
    ans += sum;
  }
  printf("%I64d\n", ans);
}
int main() {
  int sz, j;
  while (scanf("%d", &n) == 1) {
    init();
    for (int i = 0; i < n; i++) {
      scanf("%s", str[i]);
      sz = strlen(str[i]);
      a[str[i][0] - 'a'].lead = 1;
      for (int k = 0; k < sz; k++) {
        j = str[i][sz - k - 1] - 'a';
        a[j].cnt[k]++;
      }
    }
    for (int i = 0; i < 10; i++) {
      for (int k = 0; k < maxm - 1; k++) {
        a[i].cnt[k + 1] += a[i].cnt[k] / 10;
        a[i].cnt[k] %= 10;
      }
    }
    sort(a, a + 10);
    solve();
  }
  return 0;
}
