#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int n, lead[30] = {0}, pw[10] = {0}, flag = 10000;
  vector<pair<long long, int> > v;
  long long cnt[30] = {0}, ans = 0;
  string s;
  pw[0] = 1;
  for (int i = 1; i <= 6; i++) pw[i] = 10 * pw[i - 1];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    int len = s.length();
    lead[s[0] - 'a'] = 1;
    for (int i = 0; i < len; i++) {
      cnt[s[i] - 'a'] += pw[len - i - 1];
    }
  }
  for (int i = 0; i <= 26; i++) v.push_back(make_pair(cnt[i], i));
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (lead[v[i].second] == 0) {
      flag = i;
      break;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    if (i < flag)
      ans += (i + 1) * v[i].first;
    else if (i > flag)
      ans += i * v[i].first;
  }
  printf("%lld\n", ans);
  return 0;
}
