CF616F.Expensive Strings

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn strings tit_{i} . Each string has cost cic_{i} .

Let's define the function of string , where ps,ip_{s,i} is the number of occurrences of ss in tit_{i} , s|s| is the length of the string ss . Find the maximal value of function f(s)f(s) over all strings.

Note that the string ss is not necessarily some string from tt .

输入格式

The first line contains the only integer nn ( 1<=n<=1051<=n<=10^{5} ) — the number of strings in tt .

Each of the next nn lines contains contains a non-empty string tit_{i} . tit_{i} contains only lowercase English letters.

It is guaranteed that the sum of lengths of all strings in tt is not greater than 51055·10^{5} .

The last line contains nn integers cic_{i} ( 107<=ci<=107-10^{7}<=c_{i}<=10^{7} ) — the cost of the ii -th string.

输出格式

Print the only integer aa — the maximal value of the function f(s)f(s) over all strings ss . Note one more time that the string ss is not necessarily from tt .

输入输出样例

  • 输入#1

    2
    aa
    bb
    2 1
    

    输出#1

    4
    
  • 输入#2

    2
    aa
    ab
    2 1
    

    输出#2

    5
    
首页