import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!size_t; auto ai = readln.split.map!(to!int).array; auto bi = new int[](n); bi[0] = ai[0]; ai = ai[1..$]; foreach (i; 0..n-1) { auto b = bi[i]; auto minJ = 0, minA = 0, minLcm = int.max; foreach (int j, a; ai) { auto lcm = b / gcd(b, a) * a; if (lcm < minLcm || lcm == minLcm && a < minA) { minJ = j; minA = a; minLcm = lcm; } } bi[i + 1] = minA; ai = ai.remove(minJ); } writeln(bi.map!(to!string).join(" ")); }