CRAN04 - Audition


Penny is a terrible waitress and even worse actress, however recently she applied for a role in an upcoming TV series. Even though she thought she had no chance, she was called for an audition. She was very happy about it until she found out that her character in this new series will be a studious, high IQ girl named Megan. Producer told her that to get the role of Megan she had to prove that her mind can handle a bit of mathematics and reasoning. If she passed the test then she will be given the role of Megan. The test was as follow.

The people (Boys and Girls) who came for audition are standing in a line in a random order. Producer has to select exactly K boys for the show. So he asks Penny to tell how many ways can he select two numbers i and j such that the number of boys standing between these (including I and j) indexes is exactly K.

Penny desperately needs this role. Everybody knows that Penny is not a very smart and requests you to help her.

Input

First line contains T – The number of test cases.

Next line contains space separated N and K.

N – The total number of boys and girls who came to audition.

K – The number of the boys who must be there between each (i, j) pair.

Next line contains a non-empty string consisting of '1' and '0'.

1 represents Boy.

0 represents Girl.

Output

The number of (i, j) pairs such that the number of boys between index i and j, both inclusive is equal to K.

Constraints

1<=T<=10

1<=N<=10^6

0<=K<=10^6

Example

Input:
3
4 1
0101
5 2
01010
5 4
01010

Output:
6
4
0

hide comments
:.Mohib.:: 2015-06-14 09:10:18

Awsm que + strong test cases.... enjoyed solving it.... :)

Ankit: 2015-06-14 08:05:47

easy one :)

Angel Gonzalez: 2015-03-20 19:30:39

@Sudarshan K: there is in fact an O(n) solution, even with scanf and printf the O(nlogn) was giving me TLE. Maybe it was because of the huge constant factors of STL data structures.

Sudarshan K: 2014-12-26 09:41:10

Kudos for framing the question :). Also is there and O(n) solution for this ?

numerix: 2014-12-25 22:13:20

Really a nice problem, that offers the opportunity to write a rather short (about 10 lines), concise and "pythonic" Python solution. Though there is large input, it is no problem to get a Python solution AC within the TL, if the problem is reduced to its core.

Rahul Lingala: 2014-12-23 19:43:33

Awesome question.

LeppyR64: 2013-02-20 14:21:45

Nice problem!


Added by:CSI
Date:2013-02-16
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64