#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 9;
long long QPow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
long long toInt(string str) {
  long long ans = 0;
  for (int i = 0; i < str.size(); i++) {
    ans *= 10;
    ans += str[i] - '0';
  }
  return ans;
}
string toString(long long a) {
  if (a == 0) return "0";
  string temp = "";
  long long tp = a;
  while (tp) {
    temp.push_back('0' + tp % 10);
    tp /= 10;
  }
  string temp2 = temp;
  for (int ii = 0; ii < temp.size(); ii++) {
    temp[ii] = temp2[temp.size() - 1 - ii];
  }
  return temp;
}
const int MAXN = 1;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
int b[4][4];
int ans[4][4];
int md[4][4];
inline long long add(const long long &a, const long long &b) {
  return (a + b) >= mod ? (a + b) - mod : (a + b < 0 ? (a + b) + mod : a + b);
}
inline long long mul(const long long &a, const long long &b) {
  return 1LL * a * b % mod;
}
void matrixPow(int n) {
  while (n) {
    if (n & 1) {
      for (int i = 0; i < 4; i++)
        for (int j = 0; j < 4; j++) {
          md[i][j] = 0;
          for (int k = 0; k < 4; k++)
            md[i][j] = add(md[i][j], mul(ans[i][k], b[k][j]));
        }
      memcpy(ans, md, sizeof ans);
    }
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) {
        md[i][j] = 0;
        for (int k = 0; k < 4; k++)
          md[i][j] = add(md[i][j], mul(b[i][k], b[k][j]));
      }
    memcpy(b, md, sizeof b);
    n >>= 1;
  }
}
inline void read(int &n) {
  char c = '+';
  bool flag = 0;
  n = 0;
  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') flag = 1;
  }
  while (c >= '0' && c <= '9') n = n * 10 + c - 48, c = getchar();
}
int pos[26];
struct let {
  int val;
  char key;
  bool friend operator<(const let &a, const let &b) {
    if (a.val > b.val)
      return 1;
    else if (a.val == b.val)
      return a.key < b.key;
    else
      return 0;
  }
} les[1002];
string arr[1002];
int val[26];
bool hed[26];
bool used[10];
signed main() {
  ifstream in("Text.txt");
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  long long n;
  int m;
  for (int i = 0; i < 26; i++) val[i] = 0;
  cin >> n;
  string tep;
  for (int i = 0; i < n; i++) {
    cin >> tep;
    arr[i] = tep;
    hed[tep[0] - 'a'] = 1;
    for (int j = 0; j < tep.size(); j++) {
      pos[tep[j] - 'a'] += QPow(10, tep.size() - j - 1);
    }
  }
  for (int i = 0; i < 10; i++) {
    les[i].key = 'a' + i;
    les[i].val = pos[i];
  }
  sort(les, les + 10);
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (j == 0)
        if (hed[les[i].key - 'a']) continue;
      if (!used[j]) {
        val[les[i].key - 'a'] = j;
        used[j] = 1;
        break;
      }
    }
  }
  long long ans1 = 0;
  for (int i = 0; i < n; i++) {
    long long tep = 0;
    for (int j = 0; j < arr[i].size(); j++) {
      tep *= 10;
      tep += val[arr[i][j] - 'a'];
    }
    ans1 += tep;
  }
  cout << ans1 << endl;
  return 0;
}
