cswork / OAOpen practice workspace

UberOA #29

Count the Number of Good Subarrays

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersHashing

A pair means two distinct indices i<j within the subarray whose elements are equal. Count the non-empty contiguous subarrays that contain at least k pairs.

This site's standard input/output is stated explicitly.

Input

The first line contains n k, and the second line contains n elements; 1≤n≤100000, 1≤a[i],k≤10⁹.

Output

Output one integer answer.

Example 1

Input:

5 10
1 1 1 1 1

Output:

1

Example 2

Input:

7 2
3 1 4 3 2 2 4

Output:

4

Example 3

Input:

3 1
1 2 3

Output:

0

Example notes

Example 1: the whole array has exactly 10 pairs, and every shorter range has too few, so the answer is 1. Example 2: the valid ranges are indices [0,5], [0,6], [1,6], and [2,6], so the answer is 4. Example 3: the elements are distinct and there are no equal pairs, so the answer is 0.

Editorial

Loading solution…