#include <bits/stdc++.h>
using namespace std;
string s[1100];
int n;
struct Node {
  int num, sum;
  bool first;
} word[11];
int p[11];
bool vis[11];
inline bool cmp(Node u, Node v) { return u.sum > v.sum; }
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= 10; i++) word[i].num = i;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    word[s[i][0] - 'a' + 1].first = 1;
    for (int j = 0; j < s[i].size(); j++) {
      word[s[i][j] - 'a' + 1].sum += pow(10, s[i].size() - j);
    }
  }
  sort(word + 1, word + 11, cmp);
  for (int i = 1; i <= 10; i++) {
    if (word[i].first) {
      for (int j = 1; j <= 9; j++)
        if (!vis[j]) {
          vis[j] = 1;
          p[word[i].num] = j;
          break;
        }
    } else {
      for (int j = 0; j <= 9; j++)
        if (!vis[j]) {
          vis[j] = 1;
          p[word[i].num] = j;
          break;
        }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 0; j < s[i].size(); j++) {
      cnt = cnt * 10 + p[s[i][j] - 'a' + 1];
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}
