#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, int> > k(10);
int ans[10];
int ch[90];
int main() {
  for (int i = 0; i < 10; i++) k[i].second = i;
  bool dis = 0;
  int n;
  cin >> n;
  string s[n];
  for (string &x : s) {
    cin >> x;
    ch[x[0] - 'a'] = 1;
  }
  long long d = 1;
  for (int i = 1; i < 7; i++) {
    for (string &x : s) {
      if (x.size() >= i) {
        k[x[x.size() - i] - 'a'].first += d;
      }
    }
    d *= 10;
  }
  sort(k.rbegin(), k.rend());
  int r = 1;
  for (auto x : k) {
    if (!ch[x.second] && !dis) {
      ans[x.second] = 0;
      dis = 1;
    } else {
      ans[x.second] = r++;
    }
  }
  long long mans = 0;
  for (string &x : s) {
    d = 0;
    for (int i = 0; i < x.size(); i++) {
      d *= 10;
      d += ans[x[i] - 'a'];
    }
    mans += d;
  }
  cout << mans;
  return 0;
}
