QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#10932. Colored Marbles

الإحصائيات

A toy store has just opened and is giving away free colored marbles. Xiao Ming decides to take advantage of this.

The store owner has arranged $n$ marbles in a row, where the $i$-th marble has a color $c_i$. Xiao Ming can choose a single contiguous subsegment of these marbles and take all marbles within that subsegment that appear exactly once in that subsegment.

Xiao Ming wants to know the maximum number of marbles he can take.

Input

The first line contains a positive integer $n$, representing the number of marbles. The second line contains $n$ space-separated integers, where the $i$-th number represents the color $c_i$ of the marble.

Output

A single integer representing the maximum number of marbles Xiao Ming can take.

Examples

Input 1

10
1 2 3 6 6 3 7 9 8 8

Output 1

5

Note 1

By choosing the subsegment $[1, 9]$, he takes the marbles with colors 1, 2, 7, 8, and 9, totaling 5 marbles. Since the marbles with colors 3 and 6 both appear twice, they cannot be chosen.

Subtasks

For $30\%$ of the data, $n \le 10^3$.

For $100\%$ of the data, $n \le 3 \times 10^5$ and $1 \le c_i \le n$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.