#C2464. Longest Consecutive Sequence

    ID: 45783 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

You are given an unsorted list of integers. Your task is to find the length of the longest sequence of consecutive integers that can be formed using the numbers from the list.

Note: The consecutive numbers can be in any order in the input array.

Example:

Input: 6
       100 4 200 1 3 2
Output: 4

Explanation: The longest consecutive sequence is [1, 2, 3, 4].

</p>

Please read the input from standard input and write the output to standard output.

inputFormat

The input consists of two lines. The first line contains an integer n (0 ≤ n ≤ 10^5), representing the number of elements in the list. The second line contains n space-separated integers.

If n is 0, the second line will be empty.

outputFormat

Output a single integer that indicates the length of the longest consecutive sequence that can be formed from the given integers.

## sample
6
100 4 200 1 3 2
4