#include <bits/stdc++.h>
using namespace std;
int n;
struct nani {
  int cif;
  int sum;
  int val;
} v[11];
char s[11];
int fr[11], ok0[11], j, t, i, r, nrcifc, cif, ss;
int pt[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
int compare(nani a, nani b) { return a.sum < b.sum; }
int main() {
  cin >> n;
  cin.get();
  for (j = 1; j <= n; j++) {
    cin.getline(s, 11);
    t = strlen(s);
    for (i = 0; i < t; i++) {
      r = s[i] - 96;
      if (fr[r] == 0) {
        fr[r]++;
      }
      v[r].sum += pt[t - i - 1];
      if (i == 0) {
        ok0[r] = 1;
      }
    }
  }
  for (i = 1; i <= 10; i++) {
    v[i].cif = i;
    v[i].val = -1;
  }
  sort(v + 1, v + 11, compare);
  for (i = 10; i >= 1; i--) {
    if (v[i].sum != 0) {
      if (ok0[v[i].cif] == 0) {
        v[i].val = 0;
        break;
      }
    }
  }
  cif = 1;
  for (i = 10; i >= 1; i--) {
    if (v[i].sum != 0 && v[i].val == -1) {
      ss = ss + v[i].sum * cif;
      v[i].val = cif;
      cif++;
    }
  }
  cout << ss;
  return 0;
}
