K-Distinct Windows

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
PyPy 3 2.0s
Python 3 2.0s
Memory limit: 500M

Problem type

Given an array a of n integers, count how many subarrays of length exactly x contain at least k distinct values.

Remember that a subarray is a contiguous section of the array.

Input

The first line contains three integers n, x, and k.

The second line contains n integers a_1, a_2, \dots, a_n.

Output

Print a single integer: the number of subarrays of length exactly x that contain at least k distinct values.

Constraints

  • 1 \le k \le x \le n \le 2 \cdot 10^5
  • -10^9 \le a_i \le 10^9

Example 1

Input
8 4 3
1 1 2 3 2 2 1 4
Output
4
Explanation

The five subarrays of length 4 are:

  • [1, 1, 2, 3], which has 3 distinct values;
  • [1, 2, 3, 2], which has 3 distinct values;
  • [2, 3, 2, 2], which has 2 distinct values;
  • [3, 2, 2, 1], which has 3 distinct values;
  • [2, 2, 1, 4], which has 3 distinct values.

So the answer is 4.


Comments

There are no comments at the moment.