QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#9584. Self-Pity

统计

As a lonely explorer, you are full of curiosity about the mysterious power of arrays. On your journey through the past, you heard a legend about arrays: every array hides a mysterious power. If the frequency of the maximum value in an array is at least a certain threshold $k$, this array has a "power value" of $1$; otherwise, it has no power value. The "power level" of an array is the sum of the power values of all its subarrays.

Given an array of length $n$, you are eager to know the power level of this array.

Recall: A subarray is a contiguous segment of elements in an array. For example, for the array $a = [3, 2, 1, 3, 2]$, $[2, 1], [1, 3], [3, 2, 1]$ are subarrays, but $[3, 3], [1, 4]$ are not.

Input

The first line contains the number of test cases $T$ ($1 \le T \le 10^6$).

For each test case: The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 10^6$), representing the length of the array and the threshold. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), representing the given array.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output

For each test case, output a single integer on a new line, representing the power level of the array.

Examples

Input 1

2
5 2
1 3 3 2 2
4 3
1 4 2 1

Output 1

7
0

Note

In the first example, the subarrays $[1, 3, 3], [1, 3, 3, 2], [1, 3, 3, 2, 2], [3, 3], [3, 3, 2], [3, 3, 2, 2], [2, 2]$ have a maximum value that appears at least $2$ times. There are $7$ such subarrays with a power value of $1$, so the power level of the array is $7$.

In the second example, there is no subarray where the maximum value appears at least $3$ times, so the power level of the array is $0$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.