#K47932. Longest Contiguous Subsequence Length

    ID: 28308 Type: Default 1000ms 256MiB

Longest Contiguous Subsequence Length

Longest Contiguous Subsequence Length

You are given an array of integers. Your task is to determine the length of the longest contiguous subsequence (subarray) where the absolute difference between any two adjacent elements is less than or equal to \(1\).

Example:

Input: 6
       2 2 3 4 5 5
Output: 6

In the above example, every pair of adjacent elements in the sequence satisfies \(|a_i - a_{i-1}| \le 1\). If the condition is broken, you should start a new subsequence.

inputFormat

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

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

It is guaranteed that \(n \ge 1\).

outputFormat

Output a single integer to standard output (stdout), representing the length of the longest contiguous subsequence in which the absolute difference between any two adjacent elements is at most \(1\).

## sample
6
2 2 3 4 5 5
6