Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ikki-korsatkich-k-xil-son

Segment with at most k distinct numbers

Medium 1000 ms 128 MB 58%
Share

An array $a$ of $n$ positive integers and a positive integer $k$ are given. Find the length of the longest segment of consecutive elements of the array in which at most $k$ distinct numbers occur.

Array cells: the longest contiguous segment with at most k distinct numbers is marked with a bracket

Input

The first line contains two positive integers: $n$ and $k$. The second line contains $n$ positive integers $a_{i}$ separated by spaces.

Output

One integer — the length of the longest segment.

Note

$1 \le k \le n \le 2 * 10^{5}$
$1 \le a_{i} \le 10^{9}$

Examples

Input #1
8 2
1 2 1 3 3 4 3 3
Output #1
5
Input #2
3 3
5 6 7
Output #2
3

Sign in to submit a solution

Signing up is free and takes a minute.