using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m, a, b) = (c[0], c[1], c[2], c[3]); c = NList; var plist = PList(n); var INF = long.MaxValue / 2; var len = Enumerable.Repeat(INF, plist.Count).ToArray(); len[0] = 0; WriteLine(string.Join(" ", plist)); for (var i = 0; i < plist.Count; ++i) { var minci = int.MaxValue; foreach (var ci in c) if (ci % plist[i] == 0) { minci = ci; break; } for (var j = i + 1; j < plist.Count; ++j) { if (minci <= plist[j]) break; if (plist[j] % plist[i] == 0) { if (j + 1 == plist.Count) len[j] = Math.Min(len[j], len[i] + (long)(plist[j] / plist[i] - 1) * a); else len[j] = Math.Min(len[j], len[i] + (long)(plist[j] / plist[i] - 1) * a + b); } } } WriteLine(len.Last() == INF ? -1 : len.Last()); } static List PList(int n) { var ans = new List(); var rev = new List(); for (var i = 1; i * i <= n; ++i) { if (n % i == 0) { ans.Add(i); if (i * i < n) rev.Add(n / i); } } rev.Reverse(); return ans.Concat(rev).ToList(); } }