#include <bits/stdc++.h>
using namespace std;
int n, tmp, info[23], res[23], maxi = 0, ans;
string s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    info[s[0] - 'a'] = tmp = 1;
    for (int j = (int)s.size() - 1; j >= 0; j--) {
      res[s[j] - 'a'] += tmp;
      tmp *= 10;
    }
  }
  for (int i = 0; i < 10; i++) {
    if (!info[i]) {
      maxi = max(maxi, res[i]);
    }
  }
  for (int i = 0; i < 10; i++) {
    if (!info[i] && maxi == res[i]) {
      swap(res[0], res[i]);
      break;
    }
  }
  sort(res + 1, res + 10);
  reverse(res + 1, res + 10);
  for (int i = 0; i < 10; i++) {
    ans += res[i] * i;
  }
  cout << ans << endl;
  ;
}
