#include <bits/stdc++.h>
using namespace std;
const int N = 15;
const int M = 1000 + 5;
const int INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
struct node {
  char ch;
  int sum;
} p[N];
char str[M][N];
int zero[N];
void init() {
  for (int i = (1); i <= (10); i++) {
    p[i].ch = i + 'a' - 1;
  }
}
bool cmp(node aa, node bb) { return aa.sum > bb.sum; }
int main() {
  init();
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%s", str[i] + 1);
    int len = strlen(str[i] + 1);
    int cnt = 1;
    for (int j = (len); j >= (1); j--) {
      p[str[i][j] - 'a' + 1].sum += cnt;
      cnt *= 10;
    }
    zero[str[i][1] - 'a' + 1] = 1;
  }
  sort(p + 1, p + 1 + 10, cmp);
  int cntt = 1;
  int flag = 0;
  long long ans = 0;
  for (int i = (1); i <= (10); i++) {
    if (flag == 0 && zero[p[i].ch - 'a' + 1] == 0) {
      flag = 1;
    } else {
      ans += p[i].sum * cntt;
      cntt++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
