Problem
In the mythical land of Wisdomia, a legendary array of numbers holds secrets that only the skilled can decipher. Your task is to take this array of integers, sort it in non-decreasing order, and then uncover the longest subsequence consisting of unique elements. Here's how you can achieve this: First, select and implement an efficient sorting algorithm to arrange the array in ascending order. Then, traverse the sorted array to identify the longest subsequence where each number appears only once. For instance, given the array [4, 3, 1, 2, 4, 3], after sorting, you get [1, 2, 3, 3, 4, 4], and the longest subsequence of unique elements is [1, 2, 3, 4]. Consider edge cases like arrays where all elements are the same or arrays that are already sorted.
Input format
The first line contains an integer n (1 <= n <= 1000), the number of elements in the array. The second line contains n integers, each an element of the array.
Output format
Two lines of output: the first line contains the sorted array of integers, and the second line contains the longest subsequence of unique integers.
Constraints
1 <= n <= 1000; -10^9 <= each element <= 10^9
Sample input
6 4 6 2 6 3 1
Sample output
1 2 3 4 6 6 4 6 2 3 1