#include <bits/stdc++.h>
using namespace std;
int const bound = 1e6 + 2, N = 4e5 + 2;
long long OO = 1e18;
double eps = 1e-6;
int oo = 1e9, mod = oo + 7;
int n;
string cc[1001];
int qq[26] = {}, perm[26] = {}, beg[26] = {};
char inc[26];
set<char> st;
int main() {
  cin >> n;
  for (int(i) = 0; (i) < (n); (i)++) {
    cin >> cc[i];
    int ten = 1;
    beg[cc[i][0] - 'a'] = 1;
    for (int j = (int)cc[i].size() - 1; j > -1; j--) {
      st.insert(cc[i][j]);
      qq[cc[i][j] - 'a'] += ten;
      ten *= 10;
    }
  }
  vector<pair<long long, long long> > vv;
  for (auto y : st) vv.push_back({qq[y - 'a'], y - 'a'});
  sort(vv.begin(), vv.end(), greater<pair<long long, long long> >());
  int mul = 0, cost = 0;
  for (int(i) = 0; (i) < (vv.size()); (i)++) {
    if (beg[vv[i].second]) continue;
    mul++;
    vv[i].second = -1;
    break;
  }
  if (!mul) mul = 1;
  for (int(i) = 0; (i) < (vv.size()); (i)++) {
    if (vv[i].second == -1) continue;
    cost += mul * vv[i].first;
    mul++;
  }
  cout << cost << endl;
  return 0;
}
