Skip to main content
LIVE CONTEST: ALGOR Contest: Round #4 (Special Challenge) is live now!

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

Segments with exactly k distinct numbers

Hard 2000 ms 128 MB 67%
Share

An array $a$ of $n$ positive integers and a positive integer $k$ are given. How many segments of consecutive elements contain exactly $k$ distinct numbers? (For example, the segment 1 2 1 contains $2$ distinct numbers.)

Array cells: one of the segments with exactly k distinct numbers is highlighted, extending it increases the count of distinct ones

Input

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

Output

One integer — the number of segments.

Note

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

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.