#include <bits/stdc++.h>
using namespace std;
pair<int, int> c[15];
bool mrk[15], mark;
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < 10; i++) c[i].second = i;
  while (n--) {
    string s;
    cin >> s;
    int po = 1;
    for (int i = s.size() - 1; i >= 0; i--) c[s[i] - 'a'].first += po, po *= 10;
    mrk[s[0] - 'a'] = true;
  }
  sort(c, c + 10);
  reverse(c, c + 10);
  int x = 1;
  for (int i = 0; i < 10; i++) {
    if (!mark && !mrk[c[i].second]) {
      mark = true;
      continue;
    }
    ans += c[i].first * x, x++;
  }
  cout << ans;
  return 0;
}
