#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, bool> p, pair<int, bool> q) { return p.first > q.first; }
int main() {
  int n;
  cin >> n;
  unordered_map<char, pair<int, bool> > freq;
  for (int i = 0; i < 10; i++) {
    freq['a' + i].first = 0;
    freq['a' + i].second = true;
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int i = s.length() - 1; i >= 0; i--) {
      char ch = s[i];
      int ans = pow(10, s.length() - i - 1);
      freq[ch].first += (ans);
      if (i == 0) freq[s[i]].second = false;
    }
  }
  vector<pair<int, bool> > v;
  for (int i = 0; i < 10; i++) {
    char ch = 'a' + i;
    pair<int, bool> p = freq[ch];
    v.push_back(p);
  }
  sort(v.begin(), v.end(), compare);
  int ans = 0;
  bool flag;
  flag = v[0].second;
  if (flag) {
    for (int i = 0; i < v.size(); i++) {
      int k = v[i].first * (i);
      ans += k;
    }
  } else {
    for (int i = 0; i < v.size(); i++) {
      if (!flag) {
        if (v[i].second)
          flag = true;
        else {
          int k = v[i].first * (i + 1);
          ans += (k);
        }
      } else {
        int k = v[i].first * i;
        ans += k;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
