#include <bits/stdc++.h>
using namespace std;
void readi(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readll(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
void writes(string s) { puts(s.c_str()); }
void writeln() { writes(""); }
void writei(int x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
void writell(long long x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long qp(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long z = qp(x, y / 2);
  z = z * z % 1000000007;
  if (y & 1) z = z * x % 1000000007;
  return z;
}
map<char, long long> mm;
set<char> pre;
long long n, m, i, j, ans, cur = 1, u0 = 0, cnt = 0;
vector<pair<long long, char> > v;
string s;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    pre.insert(s[0]);
    cur = 1;
    for (j = s.size() - 1; ~j; j--) {
      mm[s[j]] += cur;
      cur *= 10;
    }
  }
  for (i = 'a'; i <= 'j'; i++) {
    v.push_back(make_pair(mm[i], i));
  }
  stable_sort((v).begin(), (v).end());
  reverse((v).begin(), (v).end());
  for (i = 0; i <= 9; i++) {
    if (!u0 && !pre.count(v[i].second)) {
      u0 = 1;
      continue;
    }
    ans += v[i].first * (++cnt);
  }
  cout << ans;
  return 0;
}
