#include <bits/stdc++.h>
using namespace std;
class pas {
 public:
  long long x, y;
  pas(long long x = 0, long long y = 0) : x(x), y(y) {}
  pas operator+(pas p) { return pas(x + p.x, y + p.y); }
  pas operator-(pas p) { return pas(x - p.x, y - p.y); }
  pas operator*(long long a) { return pas(x * a, y * a); }
  pas operator/(long long a) { return pas(x / a, y / a); }
  long long norm() { return x * x + y * y; }
  bool operator<(const pas &p) const { return x != p.x ? x < p.x : y < p.y; }
  bool operator==(const pas &p) const { return x == p.x && y == p.y; }
};
long long zero[20] = {0};
long long wa[20] = {0};
vector<pair<long long, long long> > ve;
signed main() {
  long long n;
  cin >> n;
  for (long long h = 0; h < n; h++) {
    string s;
    cin >> s;
    zero[s[0] - 'a'] = 1;
    reverse(s.begin(), s.end());
    long long l = s.length();
    long long d = 1;
    for (long long i = 0; i < l; i++) {
      wa[s[i] - 'a'] += d;
      d *= 10;
    }
  }
  for (long long i = 0; i < 10; i++) {
    ve.push_back(make_pair(wa[i], i));
  }
  sort(ve.begin(), ve.end(), greater<pair<long long, long long> >());
  long long dame;
  for (long long i = 0; i < 10; i++) {
    if (zero[ve[i].second] == 0) {
      dame = i;
      break;
    }
  }
  long long ans = 0;
  long long cn = 0;
  for (long long i = 0; i < 10; i++)
    if (i != dame) {
      cn++;
      ans += cn * ve[i].first;
    }
  cout << ans << endl;
  return 0;
}
