#include <bits/stdc++.h>
using namespace std;
struct letter {
  long long rate;
  bool first;
  char value;
  int index;
  letter(long long Rate, bool First, char Value, int Index)
      : rate(Rate), first(First), value(Value), index(Index) {}
};
bool rate_comparer(const letter& a, const letter& b) { return a.rate > b.rate; }
bool value_comparer(const letter& a, const letter& b) {
  return a.value < b.value;
}
int main() {
  int n;
  cin >> n;
  string s[n];
  vector<letter> arr;
  for (int i = 0; i < 10; i++) arr.push_back(letter(0, 0, i + 'a', 1));
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    arr[s[i][0] - 'a'].first = true;
    for (int j = 0; j < s[i].length(); j++)
      arr[s[i][j] - 'a'].rate += (int)pow(10, s[i].length() - j - 1);
  }
  sort(arr.begin(), arr.end(), rate_comparer);
  for (int i = 0; i < n; i++)
    if (!arr[i].first) {
      arr[i].index = 0;
      break;
    }
  int g = 1;
  int obs = 0;
  for (int i = 0; i < 10; i++)
    if (arr[i].index != 0) {
      arr[i].index = g;
      g++;
    }
  sort(arr.begin(), arr.end(), value_comparer);
  for (int i = 0; i < n; i++) {
    int ka = 0;
    for (int j = 0; j < s[i].length(); j++)
      ka = (ka * 10) + arr[s[i][j] - 'a'].index;
    obs += ka;
  }
  cout << obs;
  return 0;
}
