#include <bits/stdc++.h>
using namespace std;
bool flag = 0;
long long n, t, sum;
map<char, long long> f;
map<char, bool> sta;
vector<pair<long long, char>> v;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> s;
    sta[s[0]] = 1;
    reverse(s.begin(), s.end());
    t = 1;
    for (long long j = 0; j < (long long)s.size(); j++) {
      f[s[j]] += t;
      t *= 10;
    }
  }
  for (char ch = 'a'; ch <= 'j'; ch++) {
    if (f[ch]) v.push_back({f[ch], ch});
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  t = 1;
  for (long long i = 0; i < (long long)v.size(); i++) {
    if (!flag && !sta[v[i].second])
      flag = 1;
    else {
      sum += t * v[i].first;
      t++;
    }
  }
  cout << sum;
  return 0;
}
