시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB146440.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.

예제 입력 1

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

예제 출력 1

2