#include <bits/stdc++.h>
long long int MOD = 1000000007;
using namespace std;
template <class T>
inline void sary(T* st, T* nd) {
  while (st < nd) cin >> *st++;
}
template <class T>
inline double sarys(T* st, T* nd, T sum) {
  while (st < nd) {
    cin >> *st++;
    sum += *st;
  }
  return sum;
}
template <class T>
inline void saryp(T* st, T* nd) {
  while (st < nd) {
    cout << *st++ << " ";
  }
  cout << endl;
}
const int N = 1000005;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1 == 1) {
      ans = ans * a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
bool cmp(pair<char, pair<int, long long int> >& p1,
         pair<char, pair<int, long long int> >& p2) {
  return p1.second.second > p2.second.second;
}
int main() {
  int t;
  cin >> t;
  int visited[26];
  long long int val[26];
  int flag[26];
  memset(val, 0, sizeof(val));
  memset(flag, 0, sizeof(flag));
  while (t--) {
    string s;
    cin >> s;
    int l = s.length();
    for (int i = 0; i <= l - 1; i++) {
      int ch = s[i] - 'a';
      if (i == 0) {
        flag[ch] = 1;
      }
      visited[ch] = 1;
      val[ch] += power(10 * 1ll, (l - i - 1) * 1ll);
    }
  }
  vector<pair<char, pair<int, long long int> > > v;
  for (int i = 0; i <= 25; i++) {
    if (visited[i] == 1)
      v.push_back(make_pair((char)(i + 97), make_pair(flag[i], val[i])));
  }
  sort(v.begin(), v.end(), cmp);
  char ch;
  for (vector<pair<char, pair<int, long long int> > >::iterator it = v.begin();
       it != v.end(); it++) {
    int fl = (*it).second.first;
    if (fl == 0) {
      ch = (*it).first;
      break;
    }
  }
  int c = 0;
  long long int sum = 0;
  for (vector<pair<char, pair<int, long long int> > >::iterator it = v.begin();
       it != v.end(); it++) {
    char cc = (*it).first;
    if (cc != ch) {
      long long int contri = (*it).second.second * 1ll;
      sum += (++c) * contri;
    }
  }
  cout << sum << "\n";
  return 0;
}
