#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n;
  std::cin >> n;
  int64_t bases[10] = {};
  bool forbidden[10] = {};
  for (size_t i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    forbidden[s[0] - 'a'] = true;
    reverse(s.begin(), s.end());
    int64_t pow = 1;
    for (size_t ptr = 0; ptr < s.size(); ++ptr) {
      bases[s[ptr] - 'a'] += pow;
      pow *= 10;
    }
  }
  std::vector<size_t> order(10);
  iota(order.begin(), order.end(), 0);
  int64_t result = std::numeric_limits<int64_t>::max();
  do {
    if (forbidden[order[0]]) {
      continue;
    }
    int64_t cur = 0;
    for (int64_t i = 1; i < 10; ++i) {
      cur += i * bases[order[i]];
    }
    result = std::min(result, cur);
  } while (next_permutation(order.begin(), order.end()));
  std::cout << result << '\n';
}
