P26133 [AtCoder] [ARC022B] Long Sweet
普及+
题目描述

Problem Description

Takahashi has a long sweet. This sweet is $N\$ long and is divided into blocks every $1\$. Each block has one of $ 10^5 $ flavors, and the $ i $-th block from the left has the $ A_i $-th flavor.

Takahashi wants to cut out the longest "continuous part" that does not contain more than one block of the same flavor. How many $ cm $ can he cut out at most? Note that the cut can only be made at the boundaries between blocks.

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_1 $ $ A_2 $ ... $ A_N $

  • The first line contains an integer $N\ (1\ ≦\ N\ ≦\ 10^5)$, representing the length of the sweet in $ cm $.
  • The second line contains $ N $ integers separated by spaces, representing the flavor information of each block. The $ i $-th integer $A_i\ (1\ ≦\ A_i\ ≦\ 10^5)$ indicates that the $ i $-th block from the left has the $ A_i $-th flavor.

Output Format

Output a single integer on one line, representing the maximum length in $ cm $ of the "continuous part" that Takahashi can cut out from the sweet, which does not contain more than one block of the same flavor. End the output with a newline.

Sample Input and Output

Sample Input #1

7
1 2 1 3 1 4 4

Sample Output #1

3

Sample Input #2

1
100

Sample Output #2

1

Notes/Hints

Partial Points

This problem has partial points.

  • If you correctly solve all test cases where $N\ ≦\ 100$ and $A_i\ ≦\ 100$, you will be awarded $ 50 $ points.
  • If you correctly solve all test cases where $N\ ≦\ 1,000$ and $A_i\ ≦\ 1,000$, you will be awarded $ 99 $ points.

Sample Explanation 1

The longest part is either from the $ 2 $-nd to the $ 4 $-th block, or from the $ 4 $-th to the $ 6 $-th block.

Sample Explanation 2

There is no need to cut if the sweet is already the longest possible part.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
7 1 2 1 3 1 4 4
样例输出
3