#include <bits/stdc++.h>
char v[1000];
int puteri_sortate[10];
struct numar {
  int putere;
  int tip;
};
struct numar numere[10];
bool comp(numar a, numar b) {
  if (a.putere > b.putere) return true;
  return false;
}
int main() {
  int n, i, s, m, put, j, putmax, count;
  scanf("%d", &n);
  putmax = 0;
  for (j = 1; j <= n; j++) {
    scanf("%s", &v);
    m = strlen(v);
    put = 1;
    for (i = m - 1; i >= 0; i--) {
      if (put > putmax) putmax = put;
      numere['j' - v[i]].putere += put;
      put *= 10;
    }
    numere['j' - v[i + 1]].tip = 1;
  }
  std::sort(numere, numere + 10, comp);
  i = 0;
  while (numere[i].tip == 1) i++;
  numere[i].putere = 0;
  count = 1;
  s = 0;
  for (i = 0; i <= 9; i++) {
    s += numere[i].putere * count;
    if (numere[i].putere != 0) count++;
  }
  printf("%d", s);
  return 0;
}
