#include <bits/stdc++.h>
using namespace std;
bool is_first[500];
int num[501];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    is_first[s[0]] = true;
    int l = 1;
    for (int j = s.size() - 1; j >= 0; j--) {
      num[s[j]] += l;
      l *= 10;
    }
  }
  vector<pair<int, char> > ve;
  for (char c = 'a'; c <= 'j'; c++) ve.push_back({num[c], c});
  sort(ve.rbegin(), ve.rend());
  int to = 0;
  long long res = 0;
  for (int i = 0, t = 1; i < ve.size(); i++) {
    if (!to && !is_first[ve[i].second]) {
      to = true;
      continue;
    }
    res += t * ve[i].first;
    t++;
  }
  cout << res << endl;
  return 0;
}
