#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
void makedata() {
  freopen("input.txt", "w", stdout);
  cout << 200000 << endl;
  for (int i = 0; i < 200000; i++) cout << 1000000000 << ' ';
  fclose(stdout);
}
int a[10];
string str;
bool f[10], ff[10];
int main() {
  std::ios::sync_with_stdio(0), cin.tie(0);
  int n;
  memset(a, 0, sizeof(a));
  memset(f, true, sizeof(f));
  memset(ff, true, sizeof(ff));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    f[str[0] - 'a'] = false;
    int b = 1;
    for (int i = str.size() - 1; i >= 0; i--) {
      a[str[i] - 'a'] += b;
      b *= 10;
    }
  }
  int ans = 0;
  for (int i = 0; i < 10; i++) {
    int m = 0;
    for (int j = 0; j < 10; j++) {
      if (a[j] > a[m]) m = j;
    }
    if (f[m] && ff[0]) {
      a[m] = 0;
      ff[0] = false;
      continue;
    } else {
      for (int j = 1; j < 10; j++) {
        if (ff[j]) {
          ans += a[m] * j;
          a[m] = 0;
          ff[j] = false;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
