#include <bits/stdc++.h>
using namespace std;
int n;
bool bad[10];
int mult[10];
int pre[7];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  pre[0] = 1;
  for (int i = 1; i < 7; i++) pre[i] = pre[i - 1] * 10;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    bad[s[0] - 'a'] = true;
    for (int j = 0; j < s.length(); j++) {
      int idxFromRight = s.length() - j - 1;
      mult[s[j] - 'a'] += pre[idxFromRight];
    }
  }
  vector<pair<int, int> > pairs;
  for (int i = 0; i < 10; i++) pairs.push_back(make_pair(mult[i], i));
  sort(pairs.begin(), pairs.end());
  reverse(pairs.begin(), pairs.end());
  int biggestNotBad = -1;
  for (int k = 0; k < 10; ++k) {
    if (!bad[pairs[k].second]) {
      biggestNotBad = k;
      break;
    }
  }
  int idx = 1;
  long long res = 0;
  for (int i = 0; i < 10; i++) {
    if (i == biggestNotBad) continue;
    res += idx * pairs[i].first;
    idx++;
  }
  cout << res << "\n";
}
