#include <bits/stdc++.h>
using namespace std;
int n;
long long a[256], kt[256];
string s;
int main() {
  cin >> n;
  for (int t = 0; t < n; t++) {
    cin >> s;
    kt[s[0]] = 1;
    long k = 1;
    for (int i = s.size() - 1; i >= 0; i--) {
      a[s[i]] += k;
      k *= 10;
    }
  }
  long long mi = -1;
  char z = 'z';
  for (int i = 'a'; i <= 'j'; i++) {
    if (kt[i] == 0 && a[i] > mi && a[i] != 0) {
      mi = a[i];
      z = i;
    }
  }
  a[z] = 0;
  sort(a + 'a', a + 'j' + 1);
  long long kq = 0;
  z = 1;
  for (int i = 'j'; i >= 'b'; i--)
    if (a[i] != 0) {
      kq += (long long)z * a[i];
      z++;
    }
  cout << kq;
}
