#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000009;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000009;
    a = a * a % 1000000009, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 600000 + 10, maxn = 1000000 + 10, inf = 0x3f3f3f3f;
char s[N];
vector<char> v[100010];
struct SAM {
  int last, cnt;
  int ch[N << 1][26], fa[N << 1], l[N << 1];
  int a[N << 1], c[N << 1];
  long long sz[N << 1];
  SAM() { cnt = 1; }
  void ins(int c, int x) {
    if (ch[last][c]) {
      int p = last, q = ch[last][c];
      if (l[q] == l[p] + 1)
        last = q;
      else {
        int nq = ++cnt;
        l[nq] = l[p] + 1;
        memcpy(ch[nq], ch[q], sizeof ch[q]);
        fa[nq] = fa[q];
        fa[q] = last = nq;
        for (; ch[p][c] == q; p = fa[p]) ch[p][c] = nq;
      }
      sz[last] += x;
      return;
    }
    int p = last, np = ++cnt;
    last = np;
    l[np] = l[p] + 1;
    for (; p && !ch[p][c]; p = fa[p]) ch[p][c] = np;
    if (!p)
      fa[np] = 1;
    else {
      int q = ch[p][c];
      if (l[p] + 1 == l[q])
        fa[np] = q;
      else {
        int nq = ++cnt;
        l[nq] = l[p] + 1;
        memcpy(ch[nq], ch[q], sizeof(ch[q]));
        fa[nq] = fa[q];
        fa[q] = fa[np] = nq;
        for (; ch[p][c] == q; p = fa[p]) ch[p][c] = nq;
      }
    }
    sz[np] += x;
  }
  void build(int id, int x) {
    last = 1;
    for (int i = 0; i < v[id].size(); i++) ins(v[id][i] - 'a', x);
  }
  void topo() {
    for (int i = 1; i <= cnt; i++) c[l[i]]++;
    for (int i = 1; i <= cnt; i++) c[i] += c[i - 1];
    for (int i = 1; i <= cnt; i++) a[c[l[i]]--] = i;
  }
  void cal() {
    topo();
    for (int i = cnt; i; i--) sz[fa[a[i]]] += sz[a[i]];
    long long ans = 0;
    for (int i = 2; i <= cnt; i++) ans = max(ans, sz[i] * l[i]);
    printf("%lld\n", ans);
  }
} sam;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    for (int j = 0; s[j]; j++) v[i].push_back(s[j]);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    sam.build(i, x);
  }
  sam.cal();
  return 0;
}
