#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 100;
const int maxM = (int)1e7 + 100;
const int minn = (int)1e2 + 10;
const int maxlog = 22;
const int mod = (int)1e9 + 7;
const int P = mod;
int n, ans;
vector<string> v;
vector<pair<int, char> > k;
map<char, int> m, used;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string second;
    cin >> second;
    v.push_back(second);
    for (int j = 0; j < second.size(); j++) {
      m[second[j]] += (int)pow(10, second.size() - (j + 1));
    }
    used[second[0]] = 1;
  }
  for (char i = 'a'; i <= 'z'; i++) {
    if (m[i] == 0) m[i] = mod;
    if (m[i] != mod) k.push_back(make_pair(m[i], i));
  }
  sort(k.begin(), k.end());
  reverse(k.begin(), k.end());
  int c = 1, d = 0;
  for (int i = 0; i < k.size(); i++) {
    if (k[i].first == mod) {
      break;
    }
    if (!used[k[i].second] && d == 0) {
      d = 1;
      m[k[i].second] = 0;
    } else {
      m[k[i].second] = c;
      c++;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    int res = 0;
    for (int j = 0; j < v[i].size(); j++) {
      res *= 10;
      res += m[v[i][j]];
    }
    ans += res;
  }
  cout << ans;
}
