#include <bits/stdc++.h>
using namespace std;
int a[100], lead[1000], vis[100], b[100];
char s[1000];
int qmi(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int cmp(int x, int y) { return a[x] > a[y]; }
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s + 1;
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) {
      a[s[i] - 'a' + 1] += qmi(10, len - i);
      if (i == 1) lead[s[i] - 'a' + 1] = 1;
    }
  }
  for (int i = 1; i <= 10; i++) b[i] = i;
  sort(b + 1, b + 11, cmp);
  int sum = 0, res = 0;
  for (int i = 1; i <= 10; i++) {
    res = 0;
    if (a[b[i]]) {
      if (lead[b[i]] && !res) res++;
      while (vis[res]) res++;
      sum += a[b[i]] * res;
      vis[res] = 1;
    }
  }
  cout << sum << endl;
}
signed main() {
  solve();
  return 0;
}
