#include <bits/stdc++.h>
using namespace std;
bool v[30];
int power[30];
char ch[20];
int main() {
  int n, i, aux, solutie = 0;
  cin >> n;
  cin.get();
  for (i = 1; i <= n; i++) {
    cin >> (ch + 1);
    int m = strlen(ch + 1), put = 1;
    v[ch[1] - 'a'] = 1;
    for (int i = m; i >= 1; i--) {
      power[ch[i] - 'a'] += put;
      put *= 10;
    }
  }
  int Max = 0;
  for (i = 0; i <= 9; i++)
    if (v[i] == 0) Max = max(Max, power[i]);
  for (i = 0; i <= 9; i++)
    if (v[i] == 0 and power[i] == Max) {
      aux = power[0];
      power[0] = power[i];
      power[i] = aux;
      break;
    }
  sort(power + 1, power + 10);
  for (i = 1; i <= 9; i++) solutie = solutie + power[i] * (10 - i);
  cout << solutie;
  return 0;
}
