#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long inf = 1000000000000;
int main() {
  int n;
  cin >> n;
  long long w[26] = {0};
  bool is[26] = {0};
  vector<string> vs;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    vs.push_back(s);
    int cnt = 0;
    for (int j = s.length() - 1; j >= 0; j--) {
      w[s[j] - 97] += pow(10, cnt);
      cnt++;
      if (j == 0) {
        is[s[j] - 97] = 1;
      }
    }
  }
  vector<pair<long long, int> > vp;
  for (int i = 0; i < 10; i++) {
    vp.push_back(make_pair(w[i], i));
  }
  sort(vp.begin(), vp.end());
  reverse(vp.begin(), vp.end());
  int num[11];
  int cnt = 1;
  bool iss = false;
  int allot[11];
  for (int i = 0; i < vp.size(); i++) {
    if (is[vp[i].second] == 0 && iss == false) {
      allot[vp[i].second] = 0;
      iss = true;
    } else {
      allot[vp[i].second] = cnt;
      cnt++;
    }
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = vs[i].length() - 1; j >= 0; j--) {
      sum += allot[vs[i][j] - 97] * pow(10, cnt);
      cnt++;
    }
  }
  cout << sum << '\n';
  return 0;
}
