#C8110. Longest Consecutive Subsequence

    ID: 52057 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

Given a sequence of integers, your task is to find the longest contiguous subsequence where the numbers are consecutive. In mathematical terms, for any two adjacent numbers \(a\) and \(b\) in the subsequence, the relationship \(b = a+1\) must hold. If there are multiple subsequences with the maximum length, output the one that appears first in the list.

Example: For the sequence 4 3 5 1 2 6 7 8 3 1, the longest consecutive subsequence is 6 7 8.

inputFormat

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

outputFormat

Output to standard output (stdout) the longest consecutive subsequence as space-separated integers in a single line.## sample

10
4 3 5 1 2 6 7 8 3 1
6 7 8