#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7;
long long n;
string a[N];
long long mrk[10], val[10], freq[10][6];
pair<char, long long> x[10];
bool comp(pair<char, long long> a, pair<char, long long> b) {
  return (a.second > b.second);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n;
  for (long long i = 0; i < 10; i++) val[i] = -1;
  long long max = -1;
  for (long long i = 1; i <= n; i++) {
    string s;
    cin >> s;
    mrk[s[0] - 'a']++;
    while (s.length() != 6) s = " " + s;
    a[i] = s;
  }
  for (long long i = 0; i < 6; i++)
    for (long long j = 1; j <= n; j++)
      if (a[j][i] != ' ') freq[a[j][i] - 'a'][i]++;
  for (long long i = 0; i < 10; i++) {
    x[i].first = 'a' + i;
    for (long long j = 0; j < 6; j++)
      x[i].second = (x[i].second * 10) + freq[i][j];
  }
  sort(x, x + 10, comp);
  long long k = 1, flag = 0;
  for (long long i = 0; i < 10; i++) {
    if (!flag && !mrk[x[i].first - 'a']) {
      flag++;
      val[x[i].first - 'a'] = 0;
      continue;
    }
    if (x[i].second != 0) val[x[i].first - 'a'] = k++;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < 6; j++) {
      if (a[i][j] != ' ')
        a[i][j] = val[a[i][j] - 'a'] + '0';
      else
        a[i][j] = '0';
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) ans += stoll(a[i]);
  cout << ans;
  return 0;
}
