#C13817. Longest Consecutive Sequence

    ID: 43397 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given a list of integers, find the length of the longest consecutive sequence. A consecutive sequence is a set of numbers such that each number in the sequence (except the first) is equal to the previous number plus one. For example, the sequence $a, a+1, a+2, \dots, a+k$ has a length of $k+1$.

Note that the numbers in the list may be unsorted and may contain duplicates. You need to determine the length of the longest possible sequence that can be formed by using the numbers in the list.

inputFormat

The input is given via stdin and follows the format below:

n
num1 num2 num3 ... numN

Here, 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 a single integer to stdout which is the length of the longest consecutive sequence that can be formed from the list.

## sample
6
100 4 200 1 3 2
4