#include <bits/stdc++.h>
using namespace std;
int CMP(pair<int, int> x, pair<int, int> y) {
  if (x.second != y.second) return x.second > y.second;
  return x.first <= y.first;
}
int DM[26];
int main() {
  int N, i, j, L = 1, P = 0, K = 0, DD[] = {1, 10, 100, 1000, 10000, 100000};
  string S;
  cin >> N;
  vector<string> V(N);
  set<int> DS;
  for (i = 0; i < N; i++) {
    cin >> V[i];
    DS.insert(V[i][0] - 'a');
    for (j = 0; j < V[i].size(); j++)
      DM[V[i][j] - 'a'] += DD[V[i].size() - 1 - j];
  }
  vector<pair<int, int> > W;
  for (i = 0; i < 26; i++)
    if (DM[i]) W.push_back(make_pair(i, DM[i]));
  sort(W.begin(), W.end(), CMP);
  for (i = 0; i < W.size(); i++)
    if (DS.count(W[i].first))
      P += W[i].second * L++;
    else if (!K)
      K = 1;
    else
      P += W[i].second * L++;
  cout << P;
}
