402661: GYM100834 J Polycarp and Dividend
Memory Limit:512 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
J. Polycarp and Dividendtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output
Polycarp have free time, collection of N decimal digits c1, ... , cN and positive integer A. He wants to find positive integer B, such that A divides B and B contains only digits from collection c1, ... , cN. Each digit from collection can be used any times. It is not required to use all the digits.
InputThe first line contains N — the number of digits in collection, 1 ≤ N ≤ 10. The second line contains N integer numbers ci (0 ≤ ci ≤ 9). Each digit can be there at most one time. The third line contains integer A, 1 ≤ A ≤ 105.
OutputOutput B. If you cannot find it, then output -1.
ExamplesInput3Output
3 5 7
123
5535Input
1Output
1
1230
-1