#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 62) - 1;
const long long MOD = 1e9 + 7;
const int MAX = 1e9;
const long long int N = 102;
using namespace std;
int bPow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1ll) {
      res = 1ll * res * a % MOD;
    }
    b >>= 1;
    a = 1ll * a * a % MOD;
  }
  return res;
}
int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> mpf(N, 0);
void sieve() {
  for (int i = 2; i < N; ++i) {
    if (!mpf[i])
      for (int j = 2 * i; j < N; j += i) {
        mpf[j] = i;
      }
  }
}
void solve() {
  int n;
  cin >> n;
  map<char, int> values;
  set<char> startChars;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    startChars.insert(s[0]);
    reverse(s.begin(), s.end());
    int it = 1;
    for (auto j : s) {
      values[j] += it;
      it *= 10;
    }
  }
  vector<pair<int, char>> a;
  for (auto val : values) {
    a.emplace_back(val.second, val.first);
  }
  sort(a.rbegin(), a.rend());
  bool start = false;
  int it = 1, ans = 0;
  for (auto i : a) {
    if (startChars.find(i.second) == startChars.end() and !start) {
      start = true;
    } else {
      ans += it * i.first;
      it++;
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
