#include <bits/stdc++.h>
using namespace std;
const int N = 1001000;
int tot = 1;
int ch[N][26];
int fa[N], dep[N];
void expand(int p, int x) {
  if (!ch[p][x]) {
    int np = ++tot;
    dep[np] = dep[p] + 1;
    for (; p && ch[p][x] == 0; p = fa[p]) ch[p][x] = np;
    if (p == 0) {
      fa[np] = 1;
      return;
    }
    int q = ch[p][x];
    if (dep[q] == dep[p] + 1) {
      fa[np] = q;
    } else {
      int nq = ++tot;
      fa[nq] = fa[q];
      dep[nq] = dep[p] + 1;
      for (int i = 0; i <= 25; i++) ch[nq][i] = ch[q][i];
      fa[q] = fa[np] = nq;
      for (; p && ch[p][x] == q; p = fa[p]) ch[p][x] = nq;
    }
  } else {
    int q = ch[p][x];
    if (dep[q] != dep[p] + 1) {
      int nq = ++tot;
      fa[nq] = fa[q];
      dep[nq] = dep[p] + 1;
      for (int i = 0; i <= 25; i++) ch[nq][i] = ch[q][i];
      fa[q] = nq;
      for (; p && ch[p][x] == q; p = fa[p]) ch[p][x] = nq;
    }
  }
}
char s[N];
long long ans[N];
int val[N], mul[N];
int cnt[N], rak[N], vec[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + val[i - 1]);
    val[i] = val[i - 1] + strlen(s + val[i - 1]);
  }
  for (int i = 1; i <= n; i++) scanf("%d", mul + i);
  for (int _ = 1; _ <= n; _++) {
    int p = 1;
    for (int i = val[_ - 1]; i <= val[_] - 1; i++) {
      expand(p, s[i] - 'a');
      p = ch[p][s[i] - 'a'];
    }
  }
  for (int _ = 1; _ <= n; _++) {
    int p = 1;
    for (int i = val[_ - 1]; i <= val[_] - 1; i++) {
      p = ch[p][s[i] - 'a'];
      ans[p] += mul[_];
    }
  }
  for (int i = 1; i <= tot; i++) cnt[dep[i]]++;
  for (int i = 1; i <= tot; i++) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= tot; i++) rak[i] = cnt[dep[i]]--;
  for (int i = 1; i <= tot; i++) vec[rak[i]] = i;
  for (int _ = tot; _ >= 1; _--) {
    int i = vec[_];
    ans[fa[i]] += ans[i];
  }
  long long res = 1LL << 63;
  for (int i = 1; i <= tot; i++) res = max(res, dep[i] * ans[i]);
  cout << res << endl;
  return 0;
}
