#include <bits/stdc++.h>
using namespace std;
int v[12], f[12], u[12];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int len = s.size(), t = 1;
    for (int j = len - 1; j >= 0; j--) v[s[j] - 'a'] += t, t *= 10;
    f[s[0] - 'a'] = 1;
  }
  vector<pair<int, int> > e;
  for (int i = 0; i < 10; i++)
    if (v[i]) e.push_back(pair<int, int>{v[i], f[i]});
  sort(e.begin(), e.end());
  reverse(e.begin(), e.end());
  int res = 0;
  for (int i = 0; i < e.size(); i++) {
    for (int j = (e[i].second ? 1 : 0); j < 10; j++)
      if (!u[j]) {
        res += e[i].first * j, u[j] = 1;
        break;
      }
  }
  cout << res;
  return 0;
}
