All problems

Problem 841

Word Subsets

Medium · 20 pts · String, Hash Table, Counting

Problem

A word B is a subset of a word A if every letter of B appears in A at least as many times as in B (so ll is a subset of hello). A word from the first list is universal if every word of the second list is a subset of it. Print the universal words in their original order, or NONE. Combine the second list into one requirement: for each letter, the largest count it has in any single word of the second list.

Input

The first line contains N and M. The second line contains the N words of the first list. The third line contains the M words of the second list. All words use lowercase letters.

Output

Print the universal words in input order separated by spaces, or NONE.

Constraints

1 <= N, M <= 10000; 1 <= |word| <= 10; the words of the first list are distinct

Example input

5 2
amazon apple facebook google leetcode
e o

Example output

facebook google leetcode

Explanation

With A = amazon apple facebook google leetcode and B = e o, the words containing both an e and an o are facebook, google and leetcode.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Check if Word Equals Summation of Two Words Next: Vowels of All Substrings