#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  bool leads[10] = {};
  int frequency[10] = {};
  bool alloted[10] = {};
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    leads[v[i][0] - 97] = true;
    for (int j = v[i].size() - 1; j > -1; j--) {
      frequency[v[i][j] - 97] += pow(10, v[i].size() - j - 1);
    }
  }
  long long int result = 0;
  int max = INT_MIN, index = -1;
  for (int i = 0; i < 10; i++) {
    if (leads[i] == false) {
      if (frequency[i] > max) {
        max = frequency[i];
        index = i;
      }
    }
  }
  alloted[index] = true;
  for (int i = 1; i < 10; i++) {
    max = INT_MIN;
    index = -1;
    for (int j = 0; j < 10; j++) {
      if (alloted[j] == false) {
        if (frequency[j] > max) {
          max = frequency[j];
          index = j;
        }
      }
    }
    alloted[index] = true;
    result += i * frequency[index];
  }
  cout << result << endl;
  return 0;
}
