#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t, i, m, x, y, z, u, v, ans, b, c, r, l, q, p, j, sum, d, k, n;
  t = 1;
  char ch;
  string s = "", shin;
  while (t--) {
    cin >> n;
    vector<string> v;
    vector<pair<long long int, long long int>> a(10);
    for (i = 0; i < 10; i++) {
      a[i].second = 0;
    }
    long long int ans[10] = {0};
    int lead[10] = {0};
    for (i = 0; i < n; i++) {
      cin >> s;
      for (j = 0; j < s.length(); j++) {
        a[s[j] - 'a'].first += pow(10, s.length() - j - 1);
        a[s[j] - 'a'].second = s[j] - 'a';
        if (j == 0) lead[s[j] - 'a'] = 1;
      }
    }
    sort(a.begin(), a.end());
    x = 1;
    int flag = 0;
    sum = 0;
    for (i = 9; i >= 0; i--) {
      if (flag == 0 && lead[a[i].second] == 0) {
        ans[a[i].second] = 0;
        flag = 1;
      } else {
        ans[a[i].second] = x;
        sum += a[i].first * x;
        x++;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
