using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Magatro { static int N; static int[] a; static List ans = new List(); static bool[] c; static void Main() { Scan(); c = new bool[N]; c[0] = true; ans.Add(a[0]); for(int i = 1; i < N; i++) { int ind = -1; int minlcm = int.MaxValue; int min = int.MaxValue; for(int j = 0; j < N; j++) { if (c[j]) continue; int lcm = LCM(a[j], ans[ans.Count - 1]); if (minlcm > lcm) { minlcm = lcm; ind = j; min = a[j]; } if (minlcm == lcm) { if (min > a[j]) { ind = j; min = a[j]; } } } ans.Add(a[ind]); c[ind] = true; } Console.WriteLine(string.Join(" ", ans)); } static int LCM(int a,int b) { if (a < b) { Swap(ref a, ref b); } int x = a * b; int r = a % b; while (r > 0) { a = b; b = r; r = a % b; } return x / b; } static void Swap(ref int a,ref int b) { int temp = a; a = b; b = temp; } static void Scan() { Scanner sc = new Scanner(); N = sc.NextInt(); a = new int[N]; for(int i = 0; i < N; i++) { a[i] = sc.NextInt(); } } } public class Scanner { public string[] S; private int Index; private char Separator; public Scanner(char separator=' ') { Index = 0; Separator = separator; } public string Next() { string result; if (S == null || Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } private string[] Line() { return Console.ReadLine().Split(Separator); } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } }