#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> val(10), mrk(10);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    size_t len = str.size();
    long long c = 1;
    for (int j = len - 1; j >= 0; j--) {
      val[str[j] - 'a'] += c;
      c = c * 10;
    }
    mrk[str[0] - 'a'] = 1;
  }
  int p = 27;
  long long m = 0;
  for (int i = 0; i <= 9; i++) {
    if (mrk[i] == 0 && val[i] > m) {
      m = val[i];
      p = i;
    }
  }
  val[p] = 0;
  sort(val.begin(), val.end());
  p = 1;
  long long s = 0;
  for (int i = 9; val[i] > 0 && i >= 0; i--, p++) s += p * val[i];
  cout << s << endl;
  return 0;
}
