VU atrankinis turas 2005 m. ACM ICPC varžyboms

Prev | Next

Problem J - Judge

Input file: judge.in
Output file: judge.out

Peter decided to organize a contest on solving of mathematical puzzles between his classmates. N people (2 ≤ N ≤ 10) decided to take part in this activity. At the registration each participant specifies his unique nick consisting of lowercase Latin letters. Peter offers to the participants M tasks (2 ≤ M ≤ 10), each of which has a unique name consisting of uppercase Latin letters. Each contestant sends to Peter a solution for each of the offered puzzles no more than once, and a contestant may solve only some of the puzzles.

Peter checks the submitted solutions and write the results into a text file on his computer. For each checked solution Peter writes one line looking like A-B-C, where A - the contestant's nick, B - the task name, C - number of points the contestant obtains (from 0 to 99 999). (The separator is the character with ASCII-code 45.) A contestant's result is the sum of points brought to him by each solved puzzle.

After checking all the received solutions, Peter found out that the text file with his notes has been damaged due to a computer virus attack: some letters (upper- or lowercase) were replaced with question marks (characters with ASCII-code 63). All the received solutions were also destroyed… Peter wants to take advantage of the situation. Some of the participants are his good friends, and therefore Peter wants to “restore” the results of the contest in such a manner that his friends obtain in total a maximum quantity of points. However, the “restored” results should not contradict with the non-damaged data and with contest rules…

Even though Peter's behaviour is not an example of fair play, help him to “restore” the results in the desired manner!

Input

The first line of the input file contains the integers N and M - the number of the participants and tasks. The following N lines contain the nicks of the contestant (one per line, and the contestants are numbered from 1 to N in the order they appear in the list). The following M lines contain the problem names (one per line). The length of each nick and each task name is greater than 0 and doesn't exceed 100.

The following line contains the integer K - the number of lines in the damaged result file. In the following K lines, this damaged result file is written down.

The following line contains an integer P - the number of Peter's friends among the contestants. Finally, the last line of the file contains P different integers from 1 to N, separated by single spaces - numbers of such contestants.

Output

The first and only line of the output file should contain one integer - the maximal total number of points that Peter's friends may obtain.


Sample Input

3 2
petr
lexa
sergey
PROBA
PROBB
4
lexa-PROBA-100
???g??-?????-0
?e??-PROBA-70
?e??-PROB?-60
2
3 2

Sample Output

160