#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18 + 7;
int n, m;
map<char, int> ch_num;
int main() {
  int n;
  cin >> n;
  vector<string> ee(n);
  for (int i = 0; i < n; i++) {
    cin >> ee[i];
  }
  vector<int> can_zero(27, -1);
  vector<pair<int, int> > let_sum(27);
  for (int i = 0; i < 26; i++) {
    let_sum[i] = make_pair(0, i);
  }
  for (auto cp : ee) {
    for (int i = 0; i < (int)cp.size(); i++) {
      if (i == 0) {
        can_zero[cp[i] - 'a'] = 0;
      } else if (can_zero[cp[i] - 'a'] != 0) {
        can_zero[cp[i] - 'a'] = 1;
      }
      let_sum[cp[i] - 'a'].first += pow(10, (int)cp.size() - i - 1);
    }
  }
  sort(let_sum.begin(), let_sum.end());
  reverse(let_sum.begin(), let_sum.end());
  bool z_used = false;
  int cur_n = 1;
  for (auto cp : let_sum) {
    if (can_zero[cp.second] == -1) {
      break;
    }
    if (can_zero[cp.second] && !z_used) {
      ch_num[(char)('a' + cp.second)] = 0;
      z_used = true;
    } else {
      ch_num[(char)('a' + cp.second)] = cur_n;
      cur_n++;
    }
  }
  int ans = 0;
  for (auto hui : ee) {
    for (int i = 0; i < (int)hui.size(); i++) {
      ans += ch_num[hui[i]] * pow(10, (int)hui.size() - i - 1);
    }
  }
  cout << ans;
}
