#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  int a[10] = {0};
  int b[10] = {0};
  for (int i = 0; i < n; ++i) {
    cin >> s;
    for (int i = 0; i < int(s.length()); ++i) {
      a[s[i] - 'a'] += pow(10, s.length() - i - 1);
    }
    b[s[0] - 'a'] = 1;
  }
  int c[10];
  int d[10];
  for (int i = 0; i < 10; ++i) {
    c[i] = a[i];
  }
  int max;
  int ptr;
  for (int i = 0; i < 10; ++i) {
    max = -1;
    for (int i = 0; i < 10; ++i) {
      if (max < a[i]) {
        max = a[i];
        ptr = i;
      }
    }
    a[ptr] = -1;
    d[i] = ptr;
  }
  for (int i = 0; i < 10; ++i) {
  }
  int j = 0;
  while (b[d[j]] == 1) {
    j++;
  }
  int tmp;
  for (int i = 0; i < j; ++i) {
    tmp = d[j - i - 1];
    d[j - i - 1] = d[j - i];
    d[j - i] = tmp;
  }
  int sum = 0;
  for (int i = 0; i < 10; ++i) {
    sum += c[d[i]] * i;
  }
  cout << sum;
  return 0;
}
