#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
const long long INF = 1e12;
vector<long long> vec;
string X;
long long N, res, mx, ind, arr[MAX], beg[MAX], value[MAX], mark[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  mx = -INF;
  cin >> N;
  for (int A = 1; A <= N; A++) {
    cin >> X;
    for (int B = X.size() - 1; B >= 0; B--)
      value[X[B]] += pow(10, X.size() - 1 - B);
    beg[X[0]] = 1;
  }
  for (int A = 'a'; A <= 'j'; A++) {
    if (beg[A]) continue;
    if (value[A] > mx) mx = value[A], ind = A;
  }
  for (int A = 'a'; A <= 'j'; A++) {
    if (A == ind) continue;
    vec.push_back(value[A]);
  }
  sort(vec.begin(), vec.end());
  for (int A = vec.size() - 1; A >= 0; A--) res += vec[A] * (vec.size() - A);
  cout << res;
  return 0;
}
