CF1327G.Letters and Question Marks

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string SS and an array of strings [t1,t2,,tk][t_1, t_2, \dots, t_k] . Each string tit_i consists of lowercase Latin letters from a to n; SS consists of lowercase Latin letters from a to n and no more than 1414 question marks.

Each string tit_i has its cost cic_i — an integer number. The value of some string TT is calculated as i=1kF(T,ti)ci\sum\limits_{i = 1}^{k} F(T, t_i) \cdot c_i , where F(T,ti)F(T, t_i) is the number of occurences of string tit_i in TT as a substring. For example, F(aaabaaa,aa)=4F(\text{aaabaaa}, \text{aa}) = 4 .

You have to replace all question marks in SS with pairwise distinct lowercase Latin letters from a to n so the value of SS is maximum possible.

输入格式

The first line contains one integer kk ( 1k10001 \le k \le 1000 ) — the number of strings in the array [t1,t2,,tk][t_1, t_2, \dots, t_k] .

Then kk lines follow, each containing one string tit_i (consisting of lowercase Latin letters from a to n) and one integer cic_i ( 1ti10001 \le |t_i| \le 1000 , 106ci106-10^6 \le c_i \le 10^6 ). The sum of lengths of all strings tit_i does not exceed 10001000 .

The last line contains one string SS ( 1S41051 \le |S| \le 4 \cdot 10^5 ) consisting of lowercase Latin letters from a to n and question marks. The number of question marks in SS is not greater than 1414 .

输出格式

Print one integer — the maximum value of SS after replacing all question marks with pairwise distinct lowercase Latin letters from a to n.

输入输出样例

  • 输入#1

    4
    abc -10
    a 1
    b 1
    c 3
    ?b?

    输出#1

    5
  • 输入#2

    2
    a 1
    a 1
    ?

    输出#2

    2
  • 输入#3

    3
    a 1
    b 3
    ab 4
    ab

    输出#3

    8
  • 输入#4

    1
    a -1
    ?????????????

    输出#4

    0
  • 输入#5

    1
    a -1
    ??????????????

    输出#5

    -1
首页