eolymp
bolt
Try our new interface for solving problems
Problems

Greatest Common Divisor

Greatest Common Divisor

Today at the math class the sixth-grader Peter studied the concept of greatest common divisor. Peter immediately decided to apply this knowledge in practice. Peter wrote on a piece of paper $n$ integers $a_1, a_2, ... , a_n$ --- the house numbers, where his friends live. Now he wants to choose a subset from these numbers so that their greatest common divisor equals to his favorite number $d$. Help Peter to choose from given numbers the desired subset. \InputFile First line contains two integers $n$ and $d~(1 \le n \le 1000, 1 \le d \le 10^9)$. Second line contains $n$ integers $a_1, a_2, ... , a_n~(1 \le a_i \le 10^9)$. \OutputFile If there is a desired subset, print in the first line number the size $k$ of this subset. On the second line print the numbers included in this subset. If solution does not exist, print number $-1$. If there are several answers, print any of them.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4 3
6 8 12 9
Output example #1
3
6 12 9 
Input example #2
3 3
2 4 8
Output example #2
-1
Source 2011 XII All-Russia Team School Programming Olympiad, 20 November, Problem А