#include <bits/stdc++.h>
using namespace std;
int n, no[10], f[10], ans;
struct node {
  char c;
  int v;
  bool operator<(const node &o) const { return v > o.v; }
} cnt[10];
char s[1002][10];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (char ch = 'a'; ch <= 'j'; ch++) cnt[ch - 'a'].c = ch;
  for (int i = 1; i <= n; i++) {
    int x = 1;
    no[s[i][0] - 'a'] = 1;
    for (int j = strlen(s[i]) - 1; j >= 0; j--)
      cnt[s[i][j] - 'a'].v += x, x *= 10;
  }
  sort(cnt, cnt + 10);
  for (int i = 0; i <= 9; i++)
    for (int j = 0; j <= 9; j++) {
      if ((j == 0 && no[cnt[i].c - 'a']) || f[j]) continue;
      f[j] = 1;
      ans += cnt[i].v * j;
      break;
    }
  cout << ans;
}
