#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
int num[11], n;
string s[1005];
int appear[11], cnt;
struct alph {
  int god;
  char su;
  inline bool operator<(const alph &rhs) const { return god > rhs.god; }
} p[11];
int now[11];
bool fst[11], o[11];
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    int len = s[i].length();
    for (int j = 0; j < len; j++) {
      if (!now[s[i][j] - 'a']) {
        now[s[i][j] - 'a'] = ++cnt;
        p[cnt].su = s[i][j];
      }
      p[now[s[i][j] - 'a']].god += pow(10, len - j - 1);
    }
    fst[s[i][0] - 'a'] = 1;
  }
  sort(p + 1, p + cnt + 1);
  long long ans = 0;
  for (int i = 1; i <= cnt; i++) {
    for (int j = 0; j < 10; j++) {
      if (o[j]) continue;
      if (fst[p[i].su - 'a'] && j == 0) continue;
      ans += j * p[i].god;
      o[j] = 1;
      break;
    }
  }
  printf("%lld\n", ans);
}
