Irritating accountants
면접 대비시간 제한3초메모리 제한1024 MB
구매한 n개 항목을 분류별로 묶은 뒤, 회계사가 정한 분류 순서대로 각 분류의 항목을 출력한다. 분류 안의 순서는 임의로 정해도 된다.
문제
You are shopping on behalf of a company for a big upcoming event and the pesky accountants ask you to sort the items you buy according to their own rigid standards. Why you ask? Nobody knows except for the accountants.
입력
The first line of input contains two space-separated integers and , indicating how many items you have bought and how many categories the accountants operate with respectively. On the second line follows space-separated strings , the names of the items you have bought. Some items may have been bought multiple times. On the third line follows space-separated distinct strings , the names of the categories in the order that the accountants require your items to be sorted.
Next follows lines, one describing each category. The such line begins with a string , the name of the category it describes. It is followed by a positive integer and then space-separated distinct strings , the items that belong to category .
All strings in the input consists of between and characters from the English alphabet ([A-Za-z]). It is guaranteed that each item you bought belongs to exactly one category, and that is a permutation of . It also holds that .
출력
On a single line, output strings representing the items you bought in sorted order according to the accountants. If there are multiple ways of sorting the items according to the requirements, output any of them.