#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<string> a(n);
  vector<pair<long long, long long> > cc(10);
  vector<long long> val(10, -1);
  vector<bool> lead(10, false);
  for (long long i = 0; i < 10; i++) {
    cc[i].second = i;
  }
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    lead[a[i][0] - 'a'] = true;
    long long pow10 = 1;
    for (long long j = a[i].size() - 1; j >= 0; j--) {
      cc[a[i][j] - 'a'].first += pow10;
      pow10 *= 10;
    }
  }
  sort(cc.begin(), cc.end(), greater<pair<long long, long long> >());
  for (long long i = 0; i < 10; i++) {
    if (lead[cc[i].second]) continue;
    val[cc[i].second] = 0;
    break;
  }
  long long working = 1, res = 0;
  for (long long i = 0; i < 10; i++) {
    if (val[cc[i].second] >= 0) continue;
    val[cc[i].second] = working;
    res += working * cc[i].first;
    working++;
  }
  cout << res;
  return 0;
}
