P1420 Longest Consecutive Sequence

Description

Given a sequence of positive integers of length $n$, output the length of the longest consecutive sequence in the sequence. “Consecutive” means consecutive natural numbers in increasing order that appear in the sequence.

Input Format

The first line contains an integer $n$. The second line contains $n$ integers $a_i$, separated by spaces.

Output Format

Output one integer: the number of elements in the longest consecutive sequence.

Explanation/Hint

Constraints For $100\%$ of the testdata, it is guaranteed that $1 \leq n \leq 10^4$, $1 \leq a_i \leq 10^9$. Translated by ChatGPT 5