cswork / OAOpen practice workspace

RobloxOA #2

Subarrays with at Least K Duplicate Pairs

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersHashing

Given an integer array numbers and a positive integer k, count the contiguous subarrays that contain at least k pairs of equal-valued elements. Each pair uses two indices, and indices of different pairs must be pairwise distinct; an element cannot belong to two pairs at once.

Input

The first line contains n k; the second line contains n integers. Ranges added by this site: 1≤n≤200000, 1≤k≤10^9, |numbers[i]|≤10^9. When k exceeds the number of pairs the array can provide, the answer is 0.

Output

Output the number of contiguous subarrays that satisfy the condition.

Example 1

Input:

5 2
0 1 0 1 0

Output:

3

Example 2

Input:

6 3
2 2 2 2 2 2

Output:

1

Example 3

Input:

4 1
1 3 3 1

Output:

4

Editorial

Loading solution…