#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static inline void amin(T& x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T& x, U y) {
  if (x < y) x = y;
}
int mod;
void solve() {
  int n;
  cin >> n;
  string s[n];
  for (auto& i : s) cin >> i;
  vector<pair<int, bool> > w(10, make_pair(0, 0));
  for (auto i : s) {
    w[i[0] - 'a'].second = 1;
    for (int j = 1; j <= i.size(); j++) {
      w[i[j - 1] - 'a'].first += pow(10, i.size() - j);
    }
  }
  sort(w.begin(), w.end(), [&](pair<int, bool>& x, pair<int, bool>& y) {
    return x.first > y.first;
  });
  bool f = 0;
  for (auto& i : w) {
    if (!i.second && !f) {
      i.second = 1;
      f = 1;
    } else
      i.second = 0;
  }
  int sum = 0, x = 1;
  for (auto& i : w) {
    if (!i.second) {
      i.second = 1;
      sum += i.first * x;
      x++;
    }
  }
  cout << sum << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
