#Lutece1300. Easy Problem

Easy Problem

Migrated from Lutece 1300 Easy Problem

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Given nn strings AiA_i, Each string has a non-negative cost CiC_i.

Let’s define the function of string ss: f(s)=i=1nCitot(s,i)f(s) = \sum_{i=1}^n C_i * tot(s,i)

tot(s,i)tot(s,i) represents the number of occurrences of ss in AiA_i

Find the maximal value of function f(s)f(s) over all strings.

Note that ss is not necessary to be some string from AA, and its length must be greater than zero.

Input

The first line is nn (n105)(n \le 10^5), denoting the number of strings,containing only a to z.

Then nn lines each line is a string AiA_i.

Then a line contains nn integers CiC_i.

The sum of length of all the string will no more than 10510^5

Ci10000C_i \le 10000

Output

Output one line representing the maximal value.

Samples

3
abc
abcd
cdab
1 2 3
6

Note

Let SS be ab, then the value will be 66, it’s the maximal value.

Resources

The 14th UESTC Programming Contest Preliminary