import java.util.*;
import java.util.stream.Collectors;
/**
* @author hll[yellowdradra@foxmail.com]
* @since 2023-03-25 13:36
**/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 候选人人数
int candidatesCount = Integer.parseInt(in.nextLine());
// 候选人姓名列表
List<String> candidateList = Arrays.stream(in.nextLine().split(" ")).collect(Collectors.toList());
// 选民人数
int votersCount = Integer.parseInt(in.nextLine());
// 选票
String[] votes = in.nextLine().split(" ");
// 候选人Map(key: 候选人姓名, value: 候选人得票数,初始化为0)
Map<String, Integer> candidateMap = new LinkedHashMap<>(candidatesCount);
for (String candidate : candidateList) {
candidateMap.put(candidate, 0);
}
// 遍历选票 如果所选的候选人存在 则该候选人的选票数加一 否则为将该候选人加入候选人Map 并将其票数置为负数
for (String vote : votes) {
candidateMap.compute(vote, (k, v) -> candidateMap.containsKey(vote) ? v + 1 : Integer.MIN_VALUE);
}
// 有效选票数量
int validCount = 0;
// 遍历候选人Map
for (Map.Entry<String, Integer> entry : candidateMap.entrySet()) {
// 合法的候选人
if (entry.getValue() >= 0) {
System.out.println(entry.getKey() + " : " + entry.getValue());
// 统计合法票数
validCount += entry.getValue();
} else {
// LinkedHashMap保证插入有序 所以遇到第一个不合法的候选人 就可以结束了
break;
}
}
System.out.println("Invalid : " + (votersCount - validCount));
}
}