408458: GYM103134 C Harada and the lucky numbers

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Harada and the lucky numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

People who participate in the world of competitive programming share the same passion, numbers. However, some individuals have preferences, such as natural numbers, integer numbers, transcendental numbers, among others.

Harada is no different, having a certain preference for some numbers, which he considers lucky numbers. In particular, Harada has a list of $$$ Q $$$ lucky numbers.

On his birthday, Harada got a nice little graph and a deck of $$$ N $$$ cards, where each of these cards contains a integer number between $$$ 0 $$$ and $$$ 9 $$$. Now that the birthday party is over, Harada was eager to discover the largest subset of his lucky number list he could form using the cards in his new deck.

For example, suppose the list of lucky numbers is $$$ [23, 111, 112] $$$ and that the deck has $$$ 6 $$$ cards, four cards with the number $$$ 1 $$$, a card with the number $$$ 2 $$$ and a card with the number number $$$ 3 $$$. Then, it would be able to form the following subsets: $$$ \{23 \} $$$, $$$ \{111 \} $$$, $$$ \{112 \} $$$, $$$ \{23, 111 \} $$$, with $$$ \{23, 111 \}$$$ being the biggest one.

However, wanting to avoid bad luck ─ after all, he doesn't play with his own lucky numbers! ─ Harada asked for your help in carrying out this task.

Input

The first line contains two integers $$$Q$$$ and $$$N$$$ $$$(1 \leq Q \leq 7)$$$, $$$(1 \leq N \leq 100)$$$ ─ the number of lucky numbers in the Harada list and the number of cards in the deck he got on birthday, respectively.

The second line contains $$$ Q $$$ distinct integers ─ where $$$ q_i $$$ $$$ (0 \leq q_i \leq 10^9) $$$ is the $$$i$$$-th lucky number on Harada's list. It is guaranteed that no number in the list have leading zeros.

The third and last line contains $$$ N $$$ integers ─ where $$$ n_i $$$ $$$ (0 \leq n_i \leq 9) $$$ is the number of the $$$ i $$$-th card in the deck that Harada got on birthday.

Output

On the first line, print an integer $$$R$$$ ─ the size of the largest subset of the lucky numbers that Harada can form.

On the second line, print $$$ R $$$ distinct numbers ─ where $$$ r_i $$$ is the $$$ i $$$-th luck number of the largest subset.

The order in which the numbers are printed on the second line does not matter, and if there is more than one subset, print any.

ExamplesInput
3 6
23 111 112
1 2 3 1 1 1
Output
2
23 111
Input
6 10
400 289 22 0 20 24
9 5 0 0 1 2 4 2 0 8
Output
3
400 289 0 

加入题单

上一题 下一题 算法标签: