#include <bits/stdc++.h>
using namespace std;
class TaskC {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    vector<string> arr;
    vector<int> weight(255, 0), num(255, 0);
    set<char> first;
    for (int i = 0; i < n; i++) {
      string temp;
      in >> temp;
      arr.push_back(temp);
      first.insert(temp[0]);
      reverse(temp.begin(), temp.end());
      for (int i = 0; i < temp.length(); i++) {
        weight[temp[i]] += pow(10, i + 1);
      }
    }
    bool vis[255] = {false};
    bool flag = true;
    int cnt = 1;
    for (int i = 0; i < 255; i++) {
      int ma = -1, ch;
      for (int j = 0; j < 255; j++) {
        if (weight[j] and !vis[j] and weight[j] > ma) ma = weight[j], ch = j;
      }
      if (ma == -1) break;
      if (flag and first.find(ch) == first.end())
        flag = false, num[ch] = 0, vis[ch] = true;
      else
        num[ch] = cnt++, vis[ch] = true;
    }
    long long int sum = 0;
    for (string x : arr) {
      int k = 0;
      for (char c : x) {
        k *= 10;
        k += num[c];
      }
      sum += k;
    }
    out << sum;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskC solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
