#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  vector<pair<int, char>> weights(10);
  for (int i = 0; i < 10; i++) {
    weights[i].second = 'a' + i;
  }
  vector<bool> leading(10);
  for (int i = 0; i < n; i++) {
    cin >> s;
    leading[s[0] - 'a'] = true;
    int mult = 1;
    for (int j = s.size() - 1; j >= 0; j--) {
      weights[s[j] - 'a'].first += mult;
      mult *= 10;
    }
  }
  sort(weights.begin(), weights.end());
  int assign = 0;
  int sum = 0;
  bool assignedZero = false;
  for (int i = 9; i >= 0; i--) {
    if (leading[weights[i].second - 'a'] || assignedZero) {
      assign++;
      sum += assign * weights[i].first;
    } else {
      assignedZero = true;
    }
  }
  cout << sum << endl;
}
