#C11305. Longest Consecutive Subsequence

    ID: 40607 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

Given a list of integers, find the length of the longest consecutive subsequence. A consecutive subsequence is defined as a set of integers that can be arranged in increasing order so that each adjacent pair of elements differs by 1. Formally, a sequence of the form (x, x+1, \ldots, x+k-1) has a length of (k).

Your task is to compute the value of (k) for the longest such subsequence from the provided list.

inputFormat

The input is given from standard input (stdin).

The first line contains an integer (n) representing the number of elements in the list. The second line contains (n) space-separated integers.

outputFormat

Output to standard output (stdout) a single integer representing the length of the longest consecutive subsequence in the list.## sample

10
1 9 3 10 2 20 4 11 21 30
4