#include <bits/stdc++.h>
using namespace std;
long long int em(long long int x, long long int Mod, long long int n) {
  if (n == 0)
    return 1ll;
  else if (n % 2 == 0)
    return em((x % Mod * x % Mod) % Mod, Mod, n / 2) % Mod;
  else
    return (x % Mod * em((x % Mod * x % Mod) % Mod, Mod, (n - 1) / 2)) % Mod;
}
long long int powe[9];
long long int val[20], arr[20];
set<long long int> all, s;
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, j, k, l;
  cin >> n;
  string str[n + 1];
  powe[0] = 1;
  for (i = 1; i <= 6; i++) powe[i] = powe[i - 1] * 10;
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    cin >> str[i];
    l = str[i].length();
    for (j = 0; j < l; j++) {
      arr[str[i][j] - 'a'] += powe[l - j - 1];
      if (j == 0) s.insert(str[i][j] - 'a');
    }
  }
  vector<pair<long long int, long long int> > v;
  for (i = 0; i <= 9; i++) {
    if (arr[i] != 0) v.push_back({arr[i], i});
  }
  sort(v.begin(), v.end(), greater<pair<long long int, long long int> >());
  for (i = 0; i <= 9; i++) all.insert(i);
  for (pair<long long int, long long int> y : v) {
    if (all.empty()) break;
    auto itr = all.begin();
    if (*itr == 0) {
      if (s.find(y.second) == s.end()) {
        val[y.second] = *itr;
        all.erase(itr);
      } else {
        itr++;
        val[y.second] = *itr;
        all.erase(itr);
      }
    } else {
      val[y.second] = *itr;
      all.erase(itr);
    }
  }
  long long int ans = 0;
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    l = str[i].length();
    long long int num = 0;
    for (j = 0; j < l; j++) num = num * 10 + val[str[i][j] - 'a'];
    ans += num;
  }
  cout << ans;
}
