|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||512 MB||2||2||2||100.000%|
Jokey Smurf loves to make fun of other Smurfs, now he wants to make fun of Poet Smurf. However, Poet Smurf is not so easily tricked (an exploding present didn't work) so Jokey needs to find another way. Smurfily for him, Poet has just finished his newest poem about Smurfette. Jokey now wants to erase some letters of this poem so that all occurrences of words praising Smurfette are damaged. However, some letters take more time to erase and Jokey doesn't want to raise suspicion of other Smurfs so he wants to minimize total time spent on his work.
First line of input contains Poet's poem. On the next line there is a single integer $k$ ($1 \leq k \leq 10$) -- the number of words praising Smurfette. Each of the next $k$ lines contains one of those words. Last line of input contains 26 integers $c_a, \ldots, c_z$ ($0 \leq c_\alpha \leq 1000$). $c_\alpha$ is the number of seconds it takes to erase single occurence of the letter $\alpha$. Poem and all words praising Smurfette are nonempty sequences of small letters from latin alphabet. Erased letter is replaced by space, so resulting parts of Poem does not merge. The length of Poem and each of those words does not exceed $2\cdot 10^5$.
Output the minimal number of seconds Jokey needs to spend on his work.
chryzantematematyka 3 chryzantema matematyka tematem 3 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1