LogiQuest

412. Fruit Into Baskets

MediumSliding WindowHash Map

Each tree has a fruit type. Starting anywhere and moving right, you can only carry two types. Print the most fruits you can collect (the longest subarray with at most two distinct values).

Input format

Line 1: n Line 2: n fruit types

Output format

The maximum count.

Example 1

Input

3
1 2 1

Output

3

Example 2

Input

4
0 1 2 2

Output

3

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…