#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t = 1;
  while (t--) {
    long long int n, sum = 0;
    string s;
    cin >> n;
    vector<long long int> v(25, 0), nonzeros, any;
    map<long long int, long long int> m;
    for (int i = 0; i < n; i++) {
      long long int place = 1;
      cin >> s;
      long long int sz = s.size() - 1;
      for (long long int j = sz; j >= 0; j--) {
        m[s[j] - 'a'] += (place);
        place = place * 10;
      }
      v[s[0] - 'a'] = 1;
    }
    for (auto obj : m) {
      if (v[obj.first])
        nonzeros.push_back(obj.second);
      else
        any.push_back(obj.second);
    }
    sort(any.begin(), any.end());
    long long int cur = 1;
    if (any.size()) {
      any.pop_back();
      while (any.size()) {
        nonzeros.push_back(any.back());
        any.pop_back();
      }
    }
    sort(nonzeros.begin(), nonzeros.end());
    ;
    while (nonzeros.size()) {
      sum = sum + (cur * nonzeros.back());
      cur++;
      nonzeros.pop_back();
    }
    cout << sum << endl;
  }
  return 0;
}
