#include <bits/stdc++.h>
using namespace std;
int n;
set<char> S;
string second;
pair<int, int> a[100];
int x, rs;
bool u;
bool comp(pair<int, int> l, pair<int, int> r) { return (l.second > r.second); }
int main() {
  cin >> n;
  for (int i = 0; i < 10; i++) a[i].first = i;
  for (int i = 0; i < n; i++) {
    cin >> second;
    S.insert((int)second[0] - 97);
    x = 1;
    for (int j = second.size() - 1; j >= 0; j--) {
      a[(int)(second[j]) - 97].second += x;
      x *= 10;
    }
  }
  sort(a, a + 10, comp);
  int k = 1;
  for (int i = 0; i < 10; i++) {
    if (!u && S.find(a[i].first) == S.end()) {
      u = 1;
    } else {
      rs += k * a[i].second;
      k++;
    }
  }
  cout << rs;
  return 0;
}
