#include <bits/stdc++.h>
using namespace std;
struct node {
  int p = 8, to, al = 15;
} cnt[15];
bool cmp(node a, node b) { return a.to > b.to; }
int val[15];
int main() {
  int n;
  cin >> n;
  vector<string> all;
  string s;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> s;
    all.push_back(s);
    sum = 1;
    for (int j = s.length() - 1; j >= 0; j--) {
      cnt[s[j] - 'a'].p = min(j, cnt[s[j] - 'a'].p);
      cnt[s[j] - 'a'].to += sum;
      cnt[s[j] - 'a'].al = (int)s[j] - 'a';
      sum *= 10;
    }
  }
  sort(cnt, cnt + 10, cmp);
  bool p = 1;
  int m = 1;
  for (int i = 0; i < 10; i++) {
    if (p == 1 && cnt[i].p != 0) {
      val[cnt[i].al] = 0;
      p = 0;
    } else {
      val[cnt[i].al] = m++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < all[i].size(); j++) {
      sum *= 10;
      sum += val[all[i][j] - 'a'];
    }
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}
