#include <bits/stdc++.h>
using namespace std;
long long modPow(long long a, long long b);
long long modInv(long long a);
vector<long long> prim;
void seive(long long n) {
  prim.resize(n + 1);
  for (long long i = 0; i < n + 1; i++) prim[i] = 1;
  prim[0] = prim[1] = 0;
  for (long long i = 2; i <= sqrt(n); i++) {
    for (long long j = i * i; j <= n; j += i) {
      prim[j] = 0;
    }
  }
}
long long is_prime(long long n) {
  if (prim.size() <= n) {
    cout << "Initiate Seive"
         << "\n";
    return 0;
  }
  return prim[n];
}
vector<long long> kmp(vector<long long> s) {
  long long n = (long long)s.size();
  vector<long long> pi(n);
  for (long long i = 1; i < n; i++) {
    long long j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) j++;
    pi[i] = j;
  }
  return pi;
}
vector<long long> fact(1);
long long facto(long long n) {
  fact[0] = 1;
  if (fact.size() > n) return fact[n];
  fact.push_back((n * facto(n - 1)) % 1000000007);
  return fact[n];
}
long long ExGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long tmp = ExGCD(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return tmp;
}
void solve() {
  long long n;
  cin >> n;
  string s[n];
  for (long long i = 0; i < n; i++) cin >> s[i];
  pair<long long, pair<char, long long> > cnt[10];
  for (long long i = 0; i < 10; i++) {
    cnt[i] = {0, {(char)('a' + i), -1}};
  }
  for (long long i = 0; i < n; i++) {
    long long mul = 1;
    for (long long j = s[i].length() - 1; j >= 0; j--) {
      cnt[s[i][j] - 'a'].first += mul;
      mul *= 10;
    }
    cnt[s[i][0] - 'a'].second.second = 100;
  }
  long long ans = 0;
  sort(cnt, cnt + 10,
       [](pair<long long, pair<char, long long> > a,
          pair<long long, pair<char, long long> > b) {
         return a.first > b.first;
       });
  for (long long i = 0; i < 10; i++) {
    if (cnt[i].second.second == -1) {
      cnt[i].second.second = 0;
      break;
    }
  }
  long long itr = 1;
  for (long long i = 0; i < 10; i++) {
    if (cnt[i].second.second != 0) {
      ans += cnt[i].first * itr;
      itr++;
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
long long modPow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long x = a * a;
    x %= 1000000007;
    return modPow(x, b / 2);
  }
  return (a * modPow(a, b - 1)) % 1000000007;
}
long long modInv(long long a) { return modPow(a, 1000000007 - 2); }
