Intermediate1200

Split

Codeforces
View on Codeforces
Time: 2 secondsMemory: 256 megabytes

Farmer John has an array a containing n positive integers and an integer k.

Let a[l, r] be a subarray^∗ of a. He performs the following procedure to independently determine if subarray a[l, r] is awesome:

Output the number of awesome subarrays.

Input

The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.The first line of each test case contains two integers n and k (2 ≤ k ≤ n ≤ 2 · 10^5).The following line contains n space-separated integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n).It is guaranteed that the sum of n over all test cases does not exceed 2 · 10^5.

Output

For each testcase, output one integer on a new line: the number of awesome subarrays.

Examples

Input
4 3 2 1 1 1 4 2 1 2 1 2 8 2 3 3 3 3 2 2 2 2 6 3 1 1 1 1 1 1
Output
0 7 18 11

Note

Test case 1: n=3, a=[1,1,1].For k=2, you cannot finish with the same number of 1's in both multisets, so no subarray works. Test case 2: n=4, a=[1,2,1,2]. For k=2, the final state must give each multiset exactly one 1 and one 2. Thus a valid subarray can contain at most one 1 and at most one 2.

binary searchdata structurestwo pointers

Discussion

(0)
Sign in to join the discussion.
Loading editor...
0 online