atcoder#AGC010E. [AGC010E] Rearranging

[AGC010E] Rearranging

Score : 16001600 points

Problem Statement

There are NN integers written on a blackboard. The ii-th integer is AiA_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

  • 1N20001 \leq N \leq 2000
  • 1Ai1081 \leq A_i \leq 10^8

Input

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

NN

A1A_1 A2A_2ANA_N

Output

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

5
1 2 3 4 5
5 3 2 4 1

If Takahashi arranges the given integers in the order (1,2,3,4,5)(1,2,3,4,5), they will become (5,3,2,4,1)(5,3,2,4,1) after Aoki optimally manipulates them.

4
2 3 4 6
2 4 6 3