#P2786. 英语1(eng1)- 英语作文

    ID: 1818 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>字符串树形结构平衡树洛谷原创

英语1(eng1)- 英语作文

Description

In front of "juruo" HansBug is an English essay. However, with his anxious IQ, HansBug has already scribbled a draft. He then notices there are still 4040 minutes left before the exam ends, so he decides to estimate the "value" (also called "gold content") of this English essay, which contains MM words in total. As we all know, using advanced vocabulary in English essays for entrance exams can effectively raise the essay’s "gold content", thus earning a better score. It is known that "juruo" HansBug knows NN advanced words, denoted as AiA_i (each word has length LiL_i and consists of digits and letters in both uppercase and lowercase). The "gold content" value of this advanced word is BiB_i, meaning every occurrence of this word increases the total value by BiB_i. But his brain cells and RP ("luck") are already exhausted, so this great task is left to you!

Input Format

  • The first line contains two positive integers NN and PP, where NN is the number of advanced words HansBug knows, and PP is the modulus.
  • The next NN lines each contain a word AiA_i (of length LiL_i) and an integer BiB_i, where BiB_i satisfies 0<Bi1050 < B_i \le 10^5, representing the value of that word.
  • The following lines until the end of input form an English essay, which contains MM words in total, along with some separators (the separators include and only include ,, ., !, ?).

Output Format

Output one line containing a single integer: the total value of the essay modulo PP.

5 99
hansbug 1
kkksc03 2
yyy 3
absi2011 4
lzn 100
hansbug is a juruo!but absi2011 not.!?!
one day absi2011 laughed at yyy and hansbug.
then kkksc03 and lzn blamed him for that.

16
5 99
yyyy 1
kkksc03 2
yyy 3
absi2011 4
lzn 100
yyyy is a juruo!but absi2011 not.!?!
one day absi2011 laughed at yyy and yyyy.
then kkksc03 and lzn blamed him for that.

16

Hint

In sample 11, there are 22 occurrences of hansbug, 22 of absi2011, 11 of yyy, 11 of kkksc03, and 11 of lzn, so the total value is $1 \times 2 + 2 \times 4 + 3 \times 1 + 4 \times 1 + 100 \times 1 = 115$, and 115mod99=16115 \bmod 99 = 16.

In sample 22, it is basically the same as sample 11. Note that the whole yyyy cannot be considered as yyy appearing 22 times. Please note this is an English essay; treat the word as the smallest unit.

This problem is case-sensitive.

Constraints (let the maximum length of all words be Lmax\rm{Lmax}):

Test point ID NN MM Lmax\rm{Lmax}
131\sim 3 10\le 10 100\le 100 4\le 4
454\sim 5 105\le 10^5 3×104\le 3 \times 10^4 ^
676\sim 7 5×104\le 5 \times 10^4 104\le 10^4 50\le 50
8108\sim 10 105\le 10^5 3×104\le 3 \times 10^4 ^

For all testdata, 1N1051 \le N \le 10^5, 1M3×1041 \le M \le 3 \times 10^4, 1P1091 \le P \le 10^9.

Translated by ChatGPT 5