#include <bits/stdc++.h>
using namespace std;
string inttostr(int n) {
  stringstream rr;
  rr << n;
  return rr.str();
}
int main() {
  int n, i, j, ans = 0, k, a[20], prefix[20], flag;
  vector<pair<int, int>> v;
  string s;
  cin >> n;
  memset(a, 0, sizeof(a));
  memset(prefix, 0, sizeof(prefix));
  while (n--) {
    cin >> s;
    k = 1;
    prefix[s[0] - 'a'] = 1;
    for (i = s.length() - 1; i >= 0; i--) {
      a[s[i] - 'a'] += k;
      k *= 10;
    }
  }
  for (i = 0; i < 10; i++)
    if (a[i] > 0) v.push_back(make_pair(a[i], i));
  sort(v.begin(), v.end(), greater<pair<int, int>>());
  flag = 0;
  k = 1;
  for (i = 0; i < v.size(); i++) {
    if (!prefix[v[i].second] && flag == 0) {
      flag = 1;
    } else {
      ans += v[i].first * k++;
    }
  }
  cout << ans << "\n";
  return 0;
}
