#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1000;
const int M = 1e9 + 7;
int n, m;
bool comp(pair<int64_t, char> a, pair<int64_t, char> b) { return !(a <= b); }
map<char, int64_t> val;
int pos[300];
int64_t ans;
int64_t cur;
set<int> av;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  string s[N];
  for (int i = 0; i < 10; i++) av.insert(i);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    for (int j = s[i].size() - 1, p = 0; j >= 0; j--, p++)
      val[s[i][j]] += pow(10, p);
    pos[s[i][0]] = 1;
  }
  vector<pair<int64_t, char> > v;
  for (auto i : val) v.push_back(make_pair(i.second, i.first));
  sort(v.begin(), v.end(), comp);
  for (int i = 0; i < v.size(); i++)
    if (!pos[v[i].second]) {
      v.erase(v.begin() + i);
      break;
    }
  for (int i = 0, f = 1; i < v.size(); i++, f++) ans += f * v[i].first;
  cout << ans << '\n';
}
