#include <bits/stdc++.h>
using namespace std;
vector<long long> nb(10, 0);
vector<bool> isFirst(10, false);
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long tempo = 1;
    isFirst[s[0] - 'a'] = true;
    for (long long j = s.size() - 1; j >= 0; j--) {
      nb[s[j] - 'a'] += tempo;
      tempo *= 10;
    }
  }
  long long tot = 0;
  long long best = 0;
  long long index = 0;
  bool verif = false;
  for (long long i = 0; i < nb.size(); i++) {
    if (nb[i] > best && !isFirst[i]) {
      best = nb[i];
      index = i;
      verif = true;
    }
  }
  if (verif) nb[index] = 0;
  sort(nb.begin(), nb.end());
  reverse(nb.begin(), nb.end());
  long long curr = 1;
  for (long long i = 0; i < nb.size(); i++) {
    tot += nb[i] * curr;
    if (nb[i] != 0) curr++;
  }
  cout << tot << endl;
}
