A. TriNum Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the vibrant town of Numerica, where numbers ruled the marketplace, a clever mathematician named Alaric presented a challenge. Traders were tasked with finding the longest stretch of numbers in an array, but here's the catch – they could only use up to three different numbers in that stretch. It was like a numerical puzzle, a quest to uncover the magic of the longest subarray with just three types of numbers.

As traders delved into Numerica, each subarray they discovered was a chapter in their adventure, revealing the delicate dance of numbers within Alaric's constraints. The goal was simple yet intriguing: for an array $$$A$$$ find the longest subarray with at most three different numbers, and earn the admiration of the entire marketplace.

Input
  1. The first line contains an integer, $$$N$$$, representing the length of the array. $$$(1\le N \le 10^5)$$$
  2. The second line contains $$$N$$$ space-separated integers, representing $$$A$$$ ($$$1 \le A_i \le 2 \cdot 10^5$$$).
Output

Output a single integer representing the length of the longest subarray where traders, armed with arrays, successfully unravel the numerical puzzle presented by Alaric.

Example
Input
7
1 4 2 1 9 1 10
Output
4