498. Largest Special Subset

0

Medium

Given a set of positive integers nums, find the largest subset, answer, that satisfies a special property. The special property states that for every pair of elements (result[i], result[j]) in the subset, either result[i] is divisible by result[j] or result[j] is divisible by result[i]. If there are multiple solutions, return the lexicographically smallest subset.

Input Format

The first line of the input should contain an integer n, which represents the size of the nums array. The following n lines should each contain an integer element of the nums array.

Output Format

Print the lexicographically smallest subset as the answer array.

Example

Input

3 1 2 3

Output

1 2

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 2 * 10^9
  • All the integers in nums are unique.
  • Loading...

    View Submissions

    Console