#include <bits/stdc++.h>
using namespace std;
int dr[] = {0, -1, 1, 0, -1, 1, -1, 1};
int dc[] = {-1, 0, 0, 1, 1, -1, -1, 1};
pair<long long int, bool> say[10];
long long int poweroften[6];
int main() {
  int n;
  cin >> n;
  poweroften[0] = 1;
  for (int i = 1; i < 6; ++i) {
    poweroften[i] = poweroften[i - 1] * 10;
  }
  for (int i = 0; i < 10; ++i) {
    say[i] = make_pair(0, false);
  }
  for (int i = 0; i < n; ++i) {
    string temp;
    cin >> temp;
    int limit = temp.size();
    say[temp[0] - 'a'].second = true;
    for (int j = 0; j < limit; ++j) {
      say[temp[j] - 'a'].first += poweroften[limit - j - 1];
    }
  }
  sort(say, say + 10);
  long long int cavab = 0;
  bool zeroused = false;
  long long int hardadi = 1;
  for (int i = 9; i >= 0; --i) {
    if (say[i].second || zeroused) {
      cavab += hardadi * say[i].first;
      ++hardadi;
    } else {
      zeroused = true;
    }
  }
  cout << cavab << endl;
  return 0;
}
