There are N integers written on a blackboard. The i-th integer is A_i.

Takahashi and Aoki will arrange these integers in a row, as follows:

* First, Takahashi will arrange the integers as he wishes.
* Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes.



We will assume that Takahashi acts optimally so that the eventual sequence will be lexicographically as small as possible, and we will also assume that Aoki acts optimally so that the eventual sequence will be lexicographically as large as possible. Find the eventual sequence that will be produced.

Constraints

* 1 ≦ N ≦ 2000
* 1 ≦ A_i ≦ 10^8

Input

The input is given from Standard Input in the following format:


N
A_1 A_2 … A_N


Output

Print the eventual sequence that will be produced, in a line.

Examples

Input

5
1 2 3 4 5


Output

5 3 2 4 1


Input

4
2 3 4 6


Output

2 4 6 3
#include <bits/stdc++.h>

const int MAXN = 2010;
std::priority_queue<int> q;
std::vector<int> to[MAXN], gr[MAXN];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int n, A[MAXN], ind[MAXN], tim[MAXN], idx;
bool vis[MAXN];
void dfs(int u) {
	vis[u] = true; tim[u] = ++idx;
	for (int i : gr[u]) if (!vis[i])
		dfs(i);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	std::sort(A + 1, A + 1 + n);
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			if (gcd(A[i], A[j]) > 1) {
				gr[i].push_back(j);
				gr[j].push_back(i);
			}
	for (int i = 1; i <= n; ++i) if (!vis[i]) dfs(i);
	for (int i = 1; i <= n; ++i)
		for (auto t : gr[i])
			if (tim[i] < tim[t])
				++ind[t], to[i].push_back(t);
	for (int i = 1; i <= n; ++i) if (!ind[i]) q.push(i);
	for (int i = 1, t; i <= n; ++i) {
		std::cout << (A[t = q.top()]) << (" \n" [i == n]); q.pop();
		for (int j : to[t]) if (!--ind[j]) q.push(j);
	}
	return 0;
}
