#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
int gcd(int a, int b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
set<int>se;
void bun(int a)
{
	for (int i = 2;; i++)
	{
		if (i*i>a)break;
		for (;;)
		{
			if (a%i == 0)a /= i, se.insert(i);
			else break;
		}
	}
	if (a != 1)se.insert(a);
}
vector<int>ps;
vector<int>pat[100000];
vector<int>v;
vector<int>merge(vector<int>a, vector<int>b)
{
	vector<int>r;
	a.push_back(-1);
	b.push_back(-1);
	int pa = 0, pb = 0;
	for (int i = 0; i < a.size() + b.size() - 2; i++)
	{
		if (a[pa] > b[pb])r.push_back(a[pa]), pa++;
		else r.push_back(b[pb]), pb++;
	}
	return r;
}
#define SIZE 12000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
int num;
bool isok[2000];
vector<int>calc(vector<int>idx, int las)
{
	if (idx.empty())return idx;
	int rrr = rand();
	//printf("%d-------\n", rrr);
	//for (int i = 0; i < idx.size(); i++)printf("%d ", v[idx[i]]); printf("\n");
	uf.init();
	for (int i = 0; i < idx.size(); i++)for (int j = 0; j < pat[idx[i]].size(); j++)uf.unite(idx[i], pat[idx[i]][j]);
	map<int, vector<int> >ma;
	for (int i = 0; i < idx.size(); i++)ma[uf.find(idx[i])].push_back(idx[i]);
	int maxi = 0;
	int rr = -1;
	map<int, vector<int> >::iterator it = ma.begin();
	for (int p = 0;; p++)
	{
		if (it == ma.end())break;
		vector<int>z = (*it).second;
		it++;
		int mini = 1000000000;
		for (int i = 0; i < z.size(); i++)
		{
			if (isok[z[i]])mini = min(mini, v[z[i]]);
		}
		if (mini > maxi)maxi = mini, rr = p;
	}
	//printf(" %d\n", maxi);
	it = ma.begin();
	vector<int>ans;
	for (int p = 0;; p++)
	{
		if (it == ma.end())break;
		vector<int>z = (*it).second;
		it++;
		if (p == rr)
		{
			int t;
			for (int i = 0; i < z.size(); i++)if (v[z[i]] == maxi)t = i;
			vector<int>zz;
			for (int i = 0; i < z.size(); i++)if (t != i)zz.push_back(z[i]);
			z = zz;
		}
		for (int i = 0; i < z.size(); i++)
		{
			if (isok[z[i]])
			{
				if (maxi < v[z[i]] && gcd(maxi, v[z[i]]) == 1)isok[z[i]] = false;
				else isok[z[i]] = true;
			}
			else
			{
				if (gcd(maxi, v[z[i]]) != 1)isok[z[i]] = true;
				else isok[z[i]] = false;
			}
		}
		//for (int i = 0; i < z.size(); i++)printf("   %d", v[z[i]]); printf("\n");
		vector<int>t = calc(z, maxi);
		//for (int i = 0; i < t.size(); i++)printf("%d ", t[i]); printf("\n");
		ans = merge(ans, t);
	}
	reverse(ans.begin(), ans.end());
	ans.push_back(maxi);
	reverse(ans.begin(), ans.end());
	//printf("-----%d\n", rrr);
	return ans;
}
int main()
{
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		v.push_back(z);
		bun(z);
	}
	set<int>::iterator it = se.begin();
	for (;;)
	{
		if (it == se.end())break;
		ps.push_back(*it);
		it++;
	}
	for (int i = 0; i < num; i++)for (int j = 0; j < ps.size(); j++)if (v[i] % ps[j] == 0)pat[i].push_back(j + num);
	vector<int>z;
	for (int i = 0; i < num; i++)z.push_back(i);
	fill(isok, isok + num, true);
	vector<int>r = calc(z, 1000000000);
	for (int i = 0; i < num; i++)printf("%d ", r[i]);
	printf("\n");
}

Measured memory_bytes: 30080