~/algor $ cat problems/ikki-korsatkich-aynan-k-xil
Segments with exactly k distinct numbers
Hard
2000 ms
128 MB
67%
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.)
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