#include <bits/stdc++.h>
using namespace std;
int v[10];
bool cantBeZero[10];
void f() {
  int ans = 0;
  int n;
  cin >> n;
  int m[6] = {1, 10, 100, 1000, 10000, 100000};
  vector<int> values;
  bool zero = true;
  for (int i = 9; i > 0; i--) {
    values.push_back(i);
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = s.length() - 1; j >= 0; j--) {
      if (j == 0) {
        cantBeZero[s[j] - 97] = true;
      }
      v[s[s.length() - 1 - j] - 97] += m[j];
    }
  }
  for (int i = 0; i < 10; i++) {
    int mx = 0, mxid = -1;
    for (int j = 0; j < 10; j++) {
      if (v[j] > mx) {
        mx = v[j];
        mxid = j;
      }
    }
    if (mxid == -1) break;
    if (zero && !cantBeZero[mxid]) {
      zero = false;
      v[mxid] = 0;
    } else {
      ans += values.back() * v[mxid];
      v[mxid] = 0;
      values.pop_back();
    }
  }
  cout << ans;
}
int main() {
  f();
  return 0;
}
