#C11538. Longest Consecutive Subsequence

    ID: 40865 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

Given a list of positive integers, find the longest subsequence of consecutive integers in increasing order. A consecutive subsequence is defined such that for every two adjacent elements \(a_i\) and \(a_{i+1}\) in the subsequence, \(a_{i+1} = a_i + 1\). If there are multiple subsequences with the same maximum length, you may output any one of them.

Note: The input list might be unsorted and can contain duplicate values. You should first remove duplicates and sort the remaining numbers before determining the longest consecutive subsequence.

inputFormat

The input is read from standard input (stdin). The first line contains an integer \(n\) denoting the number of elements. The second line contains \(n\) space-separated positive integers.

If \(n = 0\), the list is empty.

outputFormat

Print the longest consecutive subsequence as a sequence of space-separated integers to standard output (stdout). If the input list is empty, output an empty line.

## sample
5
3 10 2 1 20
1 2 3