#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j;
  cin >> n;
  string arr[n + 1];
  for (i = 1; i <= n; i++) cin >> arr[i];
  int front[10] = {};
  int sum[10] = {};
  for (i = 1; i <= n; i++) {
    int p = arr[i].length();
    int val = 1;
    for (j = p - 1; j >= 0; j--) {
      sum[arr[i][j] - 'a'] = sum[arr[i][j] - 'a'] + val;
      val = val * 10;
    }
    front[arr[i][0] - 'a'] = 1;
  }
  vector<pair<int, int> > vec;
  for (i = 0; i < 10; i++) vec.push_back({sum[i], front[i]});
  sort(vec.begin(), vec.end());
  int val = 1, flag = 0, ans = 0;
  for (i = 9; i >= 0; i--) {
    if (vec[i].second) {
      ans = ans + vec[i].first * val;
      val++;
    } else if (flag) {
      ans = ans + vec[i].first * val;
      val++;
    } else
      flag = 1;
  }
  cout << ans << endl;
}
