This page is still under construction.

Parts of this page are still being built. What you see may change.

GCD Table

Time limit2sMemory limit512 MB

Summary
Given all N^2 pairwise gcd values of a hidden sequence in random order, recover the sequence.
Level

Medium7 of 10

Topics
Math, Number theory, Greedy, Hash map
Solved
No attempts yet

Problem

For a sequence A=(a1,a2,…,aN)A = (a_1, a_2, \dots, a_N) of length NN, the GCD table GG is defined by

gij=gcd⁡(ai,aj)g_{ij} = \gcd(a_i, a_j)

where gcd⁡(x,y)\gcd(x, y) is the greatest common divisor of xx and yy. For example, the GCD table of A=(4,3,6,2)A = (4, 3, 6, 2) is

4362
44122
31331
62362
22122

All N2N^2 values of the GCD table GG are given in arbitrary order. Restore the original sequence AA.

Input

The first line contains the length NN of the sequence AA (1≤N≤5001 \le N \le 500).

The second line contains the N2N^2 values of the GCD table in arbitrary order, separated by spaces. Every value is a positive integer no larger than 1,000,000,0001{,}000{,}000{,}000. The input always admits an answer.

Output

Print the NN elements of the restored sequence on one line, separated by single spaces.

Any ordering of the elements gives the same GCD table, so print them in non-decreasing order. That is the lexicographically smallest answer. The multiset of elements is uniquely determined.

Examples3

  1. Example 1

    Input
    4
    2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
    
    Expected output
    2 3 4 6
    
  2. Example 2

    Input
    1
    42
    
    Expected output
    42
    
  3. Example 3

    Input
    2
    1 1 1 1
    
    Expected output
    1 1