#K53222. Longest Increasing Consecutive Subsequence

    ID: 29484 Type: Default 1000ms 256MiB

Longest Increasing Consecutive Subsequence

Longest Increasing Consecutive Subsequence

You are given a sequence of n integers. Your task is to determine the length of the longest subsequence in which each pair of adjacent elements differs by exactly one. In other words, for a subsequence a_1, a_2, \dots, a_k to be valid, it must satisfy \(a_i = a_{i-1} + 1\) for every \(2 \le i \le k\). This problem requires you to find the maximum length among all such contiguous subsequences.

Note: A single element is considered a valid subsequence with a length of 1.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  • The first line contains a single integer n ( \(0 \le n \le 10^5\)), which is the number of elements in the sequence.
  • The second line contains n space-separated integers representing the sequence.

outputFormat

Output a single integer representing the length of the longest increasing consecutive subsequence. The result should be printed to standard output (stdout).

## sample
8
1 2 3 4 5 3 4 2
5