#GYM104736C. Candy Rush

Candy Rush

本题没有可用的提交语言。

Description

It's rush hour! You've called it a day at work, and you need to buy candies for all your family members before the mall closes.

Exclusivity and uniformity are characteristics highly valued by your family, and in order to impress them, you've come up with a plan. All the candies given to each family member should be from a single brand, and no other family member should receive candies from that same brand. Additionally, you don't want to admit you love some more than others, so you want everyone to receive the same number of candies.

The mall has a store that sells candies from $K$ different brands. Coincidentally, your family consists of exactly $K$ members. This may seem too easy, but of course there's a catch.

The store displays its candies aligned on a single shelf. You don't have time to select candies individually; instead, you want to buy a group of contiguous candies to complete your task efficiently. This means that when you purchase any pair of candies, you must also buy all the candies located between them on the shelf.

What is the maximum number of candies that you can buy?

The first line contains two integers $N$ and $K$ ($1 \leq N, K \leq 4 \times 10^5$), indicating respectively the number of candies on the shelf and the number of family members. Candy brands are identified by distinct integers from $1$ to $K$.

The second line contains $N$ integers ${C_1}, {C_2}, \ldots, {C_N}$ ($1 \leq C_i \leq K$ for ${i}={1}, {2}, \ldots, {N}$), denoting the brand of each candy on the shelf, in left-to-right order.

Output a single line with an integer indicating the maximum number of candies that you can buy to your family. Recall that no family member can receive two different candy brands, and no candy brand can be purchased for two different family members. Additionally, each family member must receive the same number of candies, and the candies must be purchased as a contiguous block from the shelf.

Input

The first line contains two integers $N$ and $K$ ($1 \leq N, K \leq 4 \times 10^5$), indicating respectively the number of candies on the shelf and the number of family members. Candy brands are identified by distinct integers from $1$ to $K$.

The second line contains $N$ integers ${C_1}, {C_2}, \ldots, {C_N}$ ($1 \leq C_i \leq K$ for ${i}={1}, {2}, \ldots, {N}$), denoting the brand of each candy on the shelf, in left-to-right order.

Output

Output a single line with an integer indicating the maximum number of candies that you can buy to your family. Recall that no family member can receive two different candy brands, and no candy brand can be purchased for two different family members. Additionally, each family member must receive the same number of candies, and the candies must be purchased as a contiguous block from the shelf.

6 2
2 2 1 1 2 2
7 3
2 1 2 1 2 2 3
3 4
3 4 2
4
0
0

Note

Explanation of sample 1: Either buying from the first to the fourth candies, from the second to the fifth or from the third to the sixth allows you to purchase two candies of each brand.

Explanation of sample 2: No contiguous block of candies has the same number of candies for brands 1, 2, and 3.

Explanation of sample 3: While the store is known for selling candies from $K$ different brands, some brands might be out of stock.