#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 2e5 + 10, NN = 1e6 + 10;
int n, a, b;
bool can_be_zero[111];
string s[N];
int main() {
  memset(can_be_zero, 1, sizeof(can_be_zero));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    can_be_zero[s[i][s[i].size() - 1] - 'a'] = 0;
  }
  long long ans = 0;
  set<char> used;
  map<char, long long> value;
  for (int j = 0; j < n; j++) {
    long long pw = 1;
    for (int k = 0; k < s[j].size(); k++, pw *= 10) {
      if (!can_be_zero[s[j][k] - 'a']) continue;
      value[s[j][k]] += pw * 1;
    }
  }
  if (value.size()) {
    char mnc;
    long long mnv = 0;
    for (map<char, long long>::iterator it = value.begin(); it != value.end();
         it++) {
      if (it->second > mnv) mnc = it->first, mnv = it->second;
    }
    used.insert(mnc);
  }
  for (int i = 1; i < 10; i++) {
    map<char, long long> value;
    for (int j = 0; j < n; j++) {
      long long pw = 1;
      for (int k = 0; k < s[j].size(); k++, pw *= 10) {
        if (used.count(s[j][k])) continue;
        value[s[j][k]] += pw * i;
      }
    }
    if (!value.size()) continue;
    char mnc;
    long long mnv = 0;
    for (map<char, long long>::iterator it = value.begin(); it != value.end();
         it++) {
      if (it->second > mnv) mnc = it->first, mnv = it->second;
    }
    used.insert(mnc);
    ans += mnv;
  }
  cout << ans;
  return 0;
}
