#include <bits/stdc++.h>
using namespace std;
struct SAM {
  static const int N = 1e6 + 5;
  int go[N][26], len[N], link[N], tot, lst;
  long long ed[N];
  void init() {
    memset(go, 0, sizeof(go));
    tot = lst = 1;
  }
  void add(int c) {
    int p = lst, np = ++tot;
    lst = np;
    len[np] = len[p] + 1;
    while (!go[p][c]) go[p][c] = np, p = link[p];
    if (!p)
      link[np] = 1;
    else {
      int q = go[p][c];
      if (len[q] == len[p] + 1)
        link[np] = q;
      else {
        int nq = ++tot;
        len[nq] = len[p] + 1;
        memcpy(go[nq], go[q], sizeof(go[q]));
        link[nq] = link[q];
        link[q] = link[np] = nq;
        while (go[p][c] == q) go[p][c] = nq, p = link[p];
      }
    }
  }
  void add_string(string s) {
    lst = 1;
    for (int i = 0; i < s.size(); ++i) add(s[i] - 'a');
  }
  int cnt[N], id[N];
  void solve() {
    for (int i = 1; i <= tot; ++i) cnt[len[i]]++;
    for (int i = 1; i < N; ++i) cnt[i] += cnt[i - 1];
    for (int i = tot; i; --i) id[cnt[len[i]]--] = i;
    for (int i = tot; i; --i) ed[link[id[i]]] += ed[id[i]];
    long long ans = -1e18;
    for (int i = 1; i <= tot; ++i) ans = max(ans, len[i] * ed[i]);
    cout << ans << endl;
  }
} sam;
const int N = 1e5 + 5;
int n;
string s[N];
int c[N];
int main() {
  ios ::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i) cin >> c[i];
  sam.init();
  for (int i = 0; i < n; ++i) sam.add_string(s[i]);
  for (int i = 0; i < n; ++i) {
    int u = 1;
    for (int j = 0; j < s[i].size(); ++j) {
      u = sam.go[u][s[i][j] - 'a'];
      sam.ed[u] += c[i];
    }
  }
  sam.solve();
  return 0;
}
