#include <bits/stdc++.h>
using namespace std;
const int N = 1010, SIZE = 10, LEN = 10;
int n;
int cnt[SIZE];
char ch[LEN];
bool flag[SIZE];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch + 1);
    int len = strlen(ch + 1);
    flag[ch[1] - 97] = 1;
    for (int j = len, k = 1; j; --j, k = k * SIZE) cnt[ch[j] - 97] += k;
  }
  int Max = -1;
  for (int i = 0; i < SIZE; ++i)
    if (!flag[i]) {
      if (!~Max)
        Max = i;
      else if (cnt[Max] < cnt[i])
        Max = i;
    }
  swap(cnt[0], cnt[Max]);
  sort(cnt + 1, cnt + SIZE, greater<int>());
  int res = 0;
  for (int i = 1; i < SIZE; ++i) res += cnt[i] * i;
  printf("%d\n", res);
  return 0;
}
