#include <bits/stdc++.h>
using namespace std;
struct Data {
  int value;
  bool nonzero;
  bool use;
  Data() {
    value = 0;
    nonzero = false;
    use = false;
  }
  friend bool operator<(Data a, Data b) { return (a.value > b.value); }
};
vector<Data> Latin_set(10);
void process(string& str) {
  int size = str.size();
  int base = 1;
  for (int i = size - 1; i >= 0; i--) {
    Latin_set[str[i] - 'a'].value += base;
    Latin_set[str[i] - 'a'].use = true;
    base *= 10;
  }
  Latin_set[str[0] - 'a'].nonzero = true;
}
int main() {
  int n;
  bool used;
  int sum, current;
  sum = 0;
  used = false;
  current = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    process(str);
  }
  sort(Latin_set.begin(), Latin_set.end());
  for (int i = 0; i < 10; i++) {
    if (!Latin_set[i].use) continue;
    if (!used && !Latin_set[i].nonzero)
      used = true;
    else {
      sum += Latin_set[i].value * current;
      current++;
    }
  }
  printf("%d\n", sum);
}
