#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool canbezero[10];
pair<int, int> coeff[10];
bool cmp(pair<int, int> u, pair<int, int> v) { return u.first > v.first; }
int main() {
  int n;
  cin >> n;
  string str;
  for (int i = 0; i < 10; ++i) {
    canbezero[i] = 1;
    coeff[i].second = i;
  }
  for (int i = 0; i < n; ++i) {
    cin >> str;
    canbezero[str[0] - 'a'] = 0;
    int power = 1;
    for (int j = str.size() - 1; j >= 0; --j) {
      coeff[str[j] - 'a'].first += power;
      power *= 10;
    }
  }
  sort(coeff, coeff + 10, cmp);
  int factor[10];
  bool m = 0;
  for (int i = 0; i < 10; ++i) {
    if (!m)
      factor[i] = i + 1;
    else
      factor[i] = i;
    if (!m && canbezero[coeff[i].second]) {
      m = 1;
      factor[i] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < 10; ++i) {
    ans += coeff[i].first * factor[i];
  }
  cout << ans << endl;
  return 0;
}
