/*
██████████████████████████████████████████████████████████████████████████████
██              ██████    ██████      ██      ██  ██    ██████              ██
██  ██████████  ██  ██      ██      ██████████████  ██████  ██  ██████████  ██
██  ██      ██  ██    ██  ████      ██    ██████████    ██  ██  ██      ██  ██
██  ██      ██  ██    ██  ██      ██  ████        ██  ████  ██  ██      ██  ██
██  ██      ██  ██  ██████  ████  ████████████  ██    ████████  ██      ██  ██
██  ██████████  ██  ████  ██    ████    ████  ██████  ████  ██  ██████████  ██
██              ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██              ██
████████████████████  ██  ██    ██████  ██    ████  ████    ██████████████████
██████  ████          ████        ██    ██    ████  ████████  ██          ████
████  ██      ██  ██      ██  ██████  ████  ████    ██    ████    ████████  ██
██      ██      ██    ██    ████      ████        ██████  ██      ██  ██    ██
██  ██    ████████████  ████  ██  ████            ████  ████████████  ████  ██
██  ██      ██  ██  ████    ████████                ████████      ██  ██    ██
██  ██  ██  ██████████  ████    ██  ████  ██    ████  ████        ████  ██  ██
██    ██  ████  ██████  ██    ******************    ████  ██            ██  ██
██    ██████  ██  ██████      * Scan this QR   *██████    ██  ██  ██  ████████
████  ████  ██  ██████      ██* code to join   *██  ████    ██  ████████  ████
██████      ████████  ██      * in the Three   *██  ████          ████  ██  ██
████              ████  ████  * Body ETO.      *  ████        ██  ████  ██  ██
██████  ██    ████████        *  --ETO manager *██  ██                ██    ██
████    ██  ██  ██    ██████  *    Ye Wenjie   *████  ████  ██  ████  ██  ████
██  ████  ██████    ████  ██  *ETO(C),1988~2018*      ██  ██  ██  ██    ██████
██  ██████  ██  ████    ██  ██******************          ██████    ██████  ██
██  ██  ██    ████    ██        ██  ██        ████████      ████  ██  ██    ██
████████████    ██    ██████  ██████████  ██  ████  ██████████    ██  ██  ████
██████████    ██  ████  ██        ██    ██████████  ██    ██      ██  ██    ██
██    ██  ████    ██  ████  ████      ██████    ██    ██      ██  ██  ████  ██
██████  ██  ██████  ██            ██████████  ██    ██    ████  ████  ██    ██
██      ██████  ████  ████  ████      ████    ████  ████            ██████████
██████████████████      ██  ██  ████  ██    ██  ██    ████  ██████    ██    ██
██              ██        ████████████  ████  ██  ██  ██    ██  ██      ██  ██
██  ██████████  ██    ████  ██████  ██  ██████████████      ██████    ██  ████
██  ██      ██  ████████    ██  ██      ████  ████  ██              ████  ████
██  ██      ██  ████  ████  ████  ██████  ██████████████  ██████████    ██  ██
██  ██      ██  ██    ██████  ██  ██  ██████████  ██  ██      ████    ██    ██
██  ██████████  ██████  ████            ██    ████████  ██  ████    ██████████
██              ██████    ████  ████████  ██  ████    ██    ██  ████  ████  ██
██████████████████████████████████████████████████████████████████████████████
    扫    描    二    维    码    加    入    三    体    E    T    O
*/
/*****************
 *   I<3   C++   *
 *  IWANT ANYAC  *
 * ILOVEPROGRAM! *
 *IT'SINTERESTING*
 * ILOVEPROGRAM! *
 *  INCONTESTS   *
 *   GETSCORE    *
 *    ACCODE     *
 *     LETS      *
 *      GO       *
 *Written by:    *
 *    charlieyan *
 *****************/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <numeric>
#include <list>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define FILLBIG(a) FILL(a,0x3f)
#define ALL(a) (a).begin(),(a).end()
#define Inf ((int)0x3f3f3f3f)
#define INF ((long long)0x3f3f3f3f3f3f3f3f)
#define Mod 1000000007
#define foreach(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(...) return printf(__VA_ARGS__),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define MASK(a) (1<<(a))
#define MASKX(x,a) ((x)<<(a))
#define BIT(a,b) (((a)>>(b))&1)
#define cddx(a) priority_queue<a >
#define cxdd(a) priority_queue<a,vector<a >,greater<a > >
#define deval(a) {cerr<<#a<<" = "<<a<<endl;}
#define dearr(be,en) {cerr<<#be;cerr<<" = {";for(auto i=be;i!=en;i++)cerr<<' '<<*i;cerr<<" }\n";}
#define reg register
#define prtime eprintf("\n\nTime used: %dms\n",clock());
#define PI 3.1415926535897932384626
#define TODEG(a) (a*180/PI)
#define y0 ykangjimutigeidiqiuyipianjingtu
#define y1 yxiaomiexuduhuanrenleiwannianankang
#define endl '\n'
//抗击母体，给地球一片净土
//消灭徐毒，还人类万年安康
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int uint;
typedef long long INT;
typedef long double ldouble;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;
struct fastIO
{
	inline fastIO operator>>(int& num)
	{
		num=0;
		char c=getchar();
		while(c!='-'&&(c<'0'||c>'9'))c=getchar();
		bool foo=0;
		if(c=='-')
		{
			foo=1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			num=(num<<3)+(num<<1)+c-'0';
			c=getchar();
		}
		if(foo)num=-num;
		return *this;
	}
	inline fastIO operator>>(INT& num)
	{
		num=0;
		char c=getchar();
		while(c!='-'&&(c<'0'||c>'9'))c=getchar();
		bool foo=0;
		if(c=='-')
		{
			foo=1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			num=(num<<3)+(num<<1)+c-'0';
			c=getchar();
		}
		if(foo)num=-num;
		return *this;
	}
	inline fastIO operator>>(float& num)
	{
		scanf("%f",&num);
		return *this;
	}
	inline fastIO operator>>(double& num)
	{
		scanf("%lf",&num);
		return *this;
	}
	inline fastIO operator>>(long double& num)
	{
		scanf("%Lf",&num);
		return *this;
	}
	inline fastIO operator>>(char& num)
	{
		num=getchar();
		while(num==' '||num=='\n')num=getchar();
		return *this;
	}
	inline fastIO operator>>(char* num)
	{
		int cnt=0;
		char c=getchar();
		while(c==' '||c=='\n')c=getchar();
		while(c!=' '&&c!='\n')
		{
			num[cnt++]=c;
			c=getchar();
		}
		num[cnt]=0;
		return *this;
	}
	inline fastIO operator>>(string& num)
	{
		cin>>num;
		return *this;
	}
	inline void printInt(const int& num)
	{
		if(num<10)
		{
			putchar(num+'0');
			return;
		}
		printInt(num/10);
		putchar((num%10)+'0');
	}
	inline void printINT(const INT& num)
	{
		if(num<10)
		{
			putchar(num+'0');
			return;
		}
		printINT(num/10);
		putchar((num%10)+'0');
	}
	inline fastIO operator<<(const int& num)
	{
		if(num<0)putchar('-'),printInt(-num);
		else printInt(num);
		return *this;
	}
	inline fastIO operator<<(const INT& num)
	{
		if(num<0)putchar('-'),printINT(-num);
		else printINT(num);
		return *this;
	}
	inline fastIO operator<<(const float& num)
	{
		printf("%.10f",num);
		return *this;
	}
	inline fastIO operator<<(const double& num)
	{
		printf("%.16lf",num);
		return *this;
	}
	inline fastIO operator<<(const long double& num)
	{
		printf("%.20Lf",num);
		return *this;
	}
	inline fastIO operator<<(const char& num)
	{
		putchar(num);
		return *this;
	}
	inline fastIO operator<<(const char* num)
	{
		for(int i=0;num[i];i++)
			putchar(num[i]);
		return *this;
	}
	inline fastIO operator<<(const string& num)
	{
		cout<<num;
		return *this;
	}
}fio;
//Coded by Charlieyan
//版权所有，翻印必究

vector<int> nei[2005],nei2[2005];
int num[2005];
bool SortComp13(int a,int b){
	return num[a]<num[b];
}

bool lgl[2005];
vector<int> ltks[2005];
int ans[2005];

void dfs(int now,int ltk){
	if(lgl[now]){
		return;
	}
	lgl[now]=1;
	ltks[ltk].pb(now);
	for(int i=0;i<SZ(nei[now]);i++){
		if(!lgl[nei[now][i]]){
			dfs(nei[now][i],ltk);
			nei2[now].pb(nei[now][i]);
		}	
	}
}

int n;

int gcd(int a,int b){
	return !b?a:gcd(b,a%b);
}

int main(){
	fio>>n;
	for(int i=0;i<n;i++){
		fio>>num[i];
	}
	sort(num,num+n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(gcd(num[i],num[j])!=1){
				nei[i].pb(j);
			}
		}
	}
	int cntltk=0;
	for(int i=0;i<n;i++){
		if(!lgl[i]){
			dfs(i,cntltk++);
		}
	}
	priority_queue<pii> pq;
	for(int i=0;i<cntltk;i++){
		pq.push(mp(num[ltks[i][0]],ltks[i][0]));
	}
	int N=0;
	while(SZ(pq)){
		pii fff=pq.top();
		pq.pop();
		int Num=fff.first,x=fff.second;
		ans[N++]=Num;
		for(int i=0;i<SZ(nei2[x]);i++){
			pq.push(mp(num[nei2[x][i]],nei2[x][i]));
		}
	}
	for(int i=0;i<N;i++){
		printf("%d%c",ans[i],i==N-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 16000