#include <bits/stdc++.h>
using namespace std;
const long long M = 1e6 + 1, MOD = 1e9 + 7;
long long prefixsum[M];
long long arr[M];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int test_case;
  cin >> test_case;
  map<char, long long> mp;
  set<char> st;
  vector<pair<long long, char>> v;
  vector<string> vec;
  set<char> digit;
  for (char ch = '0'; ch <= '9'; ch++) digit.insert(ch);
  while (test_case--) {
    string s;
    cin >> s;
    int len = s.size();
    vec.push_back(s);
    for (int i = len - 1; i >= 0; i--) {
      if (!i) st.insert(s[i]);
      long long c = 1;
      int dif = len - i - 1;
      while (dif > 0) c *= 10, dif--;
      mp[s[i]] += c;
    }
  }
  for (auto it : mp) v.push_back({it.second, it.first});
  sort(v.begin(), v.end());
  map<char, char> save;
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    for (auto it : digit) {
      if (it == '0' && st.find(v[i].second) == st.end()) {
        digit.erase(it);
        save[v[i].second] = it;
        break;
      }
      if (it != '0') {
        digit.erase(it);
        save[v[i].second] = it;
        break;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < (int)vec.size(); i++) {
    string p = vec[i];
    for (int j = 0; j < (int)p.size(); j++) p[j] = save[p[j]];
    long long c = 1;
    int len = (int)p.size() - 1;
    long long sum = 0;
    while (len >= 0) {
      sum += ((p[len] - '0') * c);
      c *= 10;
      len--;
    }
    ans += sum;
  }
  cout << ans << "\n";
  return 0;
}
