#CRT0001. Gaster の 01序列
Gaster の 01序列
Problem Background
went to the Monster Academy to steal some questions again, and then handed them over to . hopes you can help him.
Problem Description
Given a sequence of length , please find the longest contiguous subsequence where the difference between the maximum and minimum numbers in this subsequence is not greater than 1. This subsequence is called a "01 difference" subsequence.
Ensure that the data meets the condition , meaning the difference between any two adjacent numbers is less than or equal to 1.
Input Format
The first line contains an integer — the size of the sequence.
The second line contains integers .
Output Format
The length of the longest "01" subsequence.
Examples
Input Example 1
5
1 2 3 3 2
Output Example 1
4
The longest "01" subsequence is [2, 3, 3, 2]. It has a length of 4.
Input Example 2
8
1 2 1 2 1 2 3 2
Output Example 2
6
The longest "01" subsequence is [1, 2, 1, 2, 1, 2]. It has a length of 6.