#include <bits/stdc++.h>
using namespace std;
long long inf = (long long)10000000000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<string> str(n);
  unordered_set<char> begin;
  for (auto& i : str) {
    cin >> i;
    begin.insert(i.front());
    reverse(i.begin(), i.end());
  }
  vector<long long> weight(10, 0);
  for (auto i : str) {
    for (long long j = 0; j < i.size(); j++) {
      weight[i[j] - 'a'] += pow(10, j);
    }
  }
  vector<char> v;
  for (long long i = 'a'; i <= 'j'; i++) {
    v.push_back(i);
  }
  long long best = inf;
  do {
    if (begin.count(v[0]) > 0) {
      continue;
    }
    long long cost = 0;
    for (long long i = 0; i < 10; i++) {
      cost += weight[v[i] - 'a'] * i;
    }
    best = min(best, cost);
  } while (next_permutation(v.begin(), v.end()));
  cout << best << endl;
}
