#P10593. Coloring to Form Valid Contiguous Runs

    ID: 12616 Type: Default 1000ms 256MiB

Coloring to Form Valid Contiguous Runs

Coloring to Form Valid Contiguous Runs

You are given a string S of length n consisting of the characters B, W and X. For every occurrence of X you can independently change it to either B or W. You are also given an integer k.

Your task is to count the number of ways to recolor all the X characters such that there exist four integers a, b, c, d satisfying

1ab<cdn,1\le a\le b < c\le d \le n,

with

b=a+k1,d=c+k1,b=a+k-1,\quad d=c+k-1,

and such that

Sa=Sa+1==Sb=B,S_a=S_{a+1}=\cdots=S_b=B, Sc=Sc+1==Sd=W.S_c=S_{c+1}=\cdots=S_d=W.

Output the answer modulo \(10^9+7\).

Note: The two contiguous segments must be non‐overlapping, and the segment of B's must entirely come before the segment of W's.

inputFormat

The first line contains two integers n and k (the length of the string and the length of each desired segment, respectively).

The second line contains the string S of length n, consisting of the characters B, W and X.

outputFormat

Output a single integer: the number of valid colorings that satisfy the condition, modulo \(10^9+7\).

sample

5 2
BXXWW
2