#include <bits/stdc++.h>
using namespace std;
int n;
char s[10];
int len;
int weight[10];
bool cannotzero[10];
vector<pair<int, int> > v;
int num[10];
int sum;
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) s[j] = '\0';
    scanf("%s", s);
    len = strlen(s);
    cannotzero[s[0] - 'a'] = 1;
    int t = 1;
    for (int j = len - 1; j >= 0; j--) {
      weight[s[j] - 'a'] += t;
      t *= 10;
    }
  }
  for (int i = 0; i < 10; i++) {
    if (cannotzero[i] == 0) v.push_back(make_pair(weight[i], i));
  }
  sort(v.begin(), v.end());
  int si = v.size(), zerosymbol = v[si - 1].second;
  num[zerosymbol] = 0;
  v.clear();
  for (int i = 0; i < 10; i++) {
    if (i != zerosymbol) v.push_back(make_pair(weight[i], i));
  }
  si = v.size();
  sort(v.begin(), v.end());
  for (int i = si - 1; i >= 0; i--) {
    num[v[i].second] = 9 - i;
  }
  for (int i = 0; i < 10; i++) sum += num[i] * weight[i];
  printf("%d", sum);
  return 0;
}
