#include <bits/stdc++.h>
using namespace std;
const long long md = 998244353;
long long cnt[15][7];
bool fo[15];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> v1;
  for (long long i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (long long j = (long long)s.size() - 1; j > -1; --j) {
      cnt[s[j] - 'a'][(long long)s.size() - 1 - j]++;
    }
    fo[s[0] - 'a'] = 1;
  }
  set<pair<long long, long long> > v;
  for (long long i = 0; i < 11; ++i) {
    long long val = 0;
    for (long long j = 0; j < 6; ++j) val += (long long)pow(10, j) * cnt[i][j];
    v.insert({-1 * val, i});
  }
  for (auto &x : v) {
    if (!fo[x.second]) {
      v.erase({x.first, x.second});
      break;
    }
  }
  long long ans = 0, i = 1;
  for (auto &x : v) {
    ans -= i * x.first;
    ++i;
  }
  cout << ans << "\n";
  return 0;
}
